2023-12-20 01:20:21 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2024-01-04 18:43:11 +00:00
|
|
|
import 'package:cake_wallet/view_model/settings/tor_connection.dart';
|
2023-12-20 01:20:21 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2024-01-04 18:43:11 +00:00
|
|
|
import 'package:tor/tor.dart';
|
2023-12-20 01:20:21 +00:00
|
|
|
|
|
|
|
part 'tor_view_model.g.dart';
|
|
|
|
|
|
|
|
class TorViewModel = TorViewModelBase with _$TorViewModel;
|
|
|
|
|
2024-01-04 18:43:11 +00:00
|
|
|
enum TorConnectionStatus { connecting, connected, disconnected }
|
2023-12-20 01:20:21 +00:00
|
|
|
|
2024-01-04 18:43:11 +00:00
|
|
|
abstract class TorViewModelBase with Store {
|
2023-12-20 01:20:21 +00:00
|
|
|
TorViewModelBase(this._settingsStore);
|
|
|
|
|
|
|
|
final SettingsStore _settingsStore;
|
|
|
|
|
|
|
|
@action
|
|
|
|
Future<void> updateStartOnLaunch(bool value) async {
|
|
|
|
_settingsStore.shouldStartTorOnLaunch = value;
|
|
|
|
}
|
2024-01-04 18:43:11 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
TorConnectionMode get torConnectionMode => _settingsStore.torConnectionMode;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void setTorConnectionMode(TorConnectionMode mode) => _settingsStore.torConnectionMode = mode;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
TorConnectionStatus get torConnectionStatus {
|
|
|
|
|
|
|
|
if (_settingsStore.torConnectionMode == TorConnectionMode.disabled) {
|
|
|
|
return TorConnectionStatus.disconnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tor.instance.port == -1 && Tor.instance.started) {
|
|
|
|
return TorConnectionStatus.connecting;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tor.instance.port != -1) {
|
|
|
|
return TorConnectionStatus.connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TorConnectionStatus.disconnected;
|
|
|
|
}
|
|
|
|
|
2023-12-20 01:20:21 +00:00
|
|
|
}
|