|
|
|
@ -65,7 +65,7 @@ class FlwtchState extends State<Flwtch> with WindowListener {
|
|
|
|
|
final MethodChannel notificationClickChannel = MethodChannel('im.cwtch.flwtch/notificationClickHandler');
|
|
|
|
|
final MethodChannel shutdownMethodChannel = MethodChannel('im.cwtch.flwtch/shutdownClickHandler');
|
|
|
|
|
final MethodChannel shutdownLinuxMethodChannel = MethodChannel('im.cwtch.linux.shutdown');
|
|
|
|
|
late StreamSubscription connectivityStream;
|
|
|
|
|
late StreamSubscription? connectivityStream;
|
|
|
|
|
ConnectivityState connectivityState = ConnectivityState.assumed_online;
|
|
|
|
|
|
|
|
|
|
final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();
|
|
|
|
@ -95,35 +95,74 @@ class FlwtchState extends State<Flwtch> with WindowListener {
|
|
|
|
|
shutdownLinuxMethodChannel.setMethodCallHandler(shutdownDirect);
|
|
|
|
|
print("initState: creating cwtchnotifier, ffi");
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState, globalServersList, this);
|
|
|
|
|
var cwtchNotifier = new CwtchNotifier(
|
|
|
|
|
profs,
|
|
|
|
|
globalSettings,
|
|
|
|
|
globalErrorHandler,
|
|
|
|
|
globalTorStatus,
|
|
|
|
|
NullNotificationsManager(),
|
|
|
|
|
globalAppState,
|
|
|
|
|
globalServersList,
|
|
|
|
|
this);
|
|
|
|
|
cwtch = CwtchGomobile(cwtchNotifier);
|
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
|
var cwtchNotifier =
|
|
|
|
|
new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(_notificationSelectConvo), globalAppState, globalServersList, this);
|
|
|
|
|
new CwtchNotifier(
|
|
|
|
|
profs,
|
|
|
|
|
globalSettings,
|
|
|
|
|
globalErrorHandler,
|
|
|
|
|
globalTorStatus,
|
|
|
|
|
newDesktopNotificationsManager(_notificationSelectConvo),
|
|
|
|
|
globalAppState,
|
|
|
|
|
globalServersList,
|
|
|
|
|
this);
|
|
|
|
|
cwtch = CwtchFfi(cwtchNotifier);
|
|
|
|
|
} else {
|
|
|
|
|
var cwtchNotifier =
|
|
|
|
|
new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(_notificationSelectConvo), globalAppState, globalServersList, this);
|
|
|
|
|
new CwtchNotifier(
|
|
|
|
|
profs,
|
|
|
|
|
globalSettings,
|
|
|
|
|
globalErrorHandler,
|
|
|
|
|
globalTorStatus,
|
|
|
|
|
newDesktopNotificationsManager(_notificationSelectConvo),
|
|
|
|
|
globalAppState,
|
|
|
|
|
globalServersList,
|
|
|
|
|
this);
|
|
|
|
|
cwtch = CwtchFfi(cwtchNotifier);
|
|
|
|
|
}
|
|
|
|
|
connectivityStream = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
|
|
|
|
|
// Got a new connectivity status!
|
|
|
|
|
if (result == ConnectivityResult.none) {
|
|
|
|
|
connectivityState = ConnectivityState.confirmed_offline;
|
|
|
|
|
} else {
|
|
|
|
|
// were we offline?
|
|
|
|
|
if (connectivityState == ConnectivityState.confirmed_offline) {
|
|
|
|
|
EnvironmentConfig.debugLog("Network appears to have come back online, restarting Tor");
|
|
|
|
|
cwtch.ResetTor();
|
|
|
|
|
}
|
|
|
|
|
connectivityState = ConnectivityState.confirmed_online;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
startConnectivityListener();
|
|
|
|
|
print("initState: invoking cwtch.Start()");
|
|
|
|
|
cwtch.Start();
|
|
|
|
|
print("initState: done!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// connectivity listening is an optional enhancement feature that tries to listen for OS events about the network
|
|
|
|
|
// and if it detects coming back online, restarts the ACN/tor
|
|
|
|
|
// gracefully fails and NOPs, as it's not a required functionality
|
|
|
|
|
startConnectivityListener() async {
|
|
|
|
|
try {
|
|
|
|
|
connectivityStream = await Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
|
|
|
|
|
// Got a new connectivity status!
|
|
|
|
|
if (result == ConnectivityResult.none) {
|
|
|
|
|
connectivityState = ConnectivityState.confirmed_offline;
|
|
|
|
|
} else {
|
|
|
|
|
// were we offline?
|
|
|
|
|
if (connectivityState == ConnectivityState.confirmed_offline) {
|
|
|
|
|
EnvironmentConfig.debugLog("Network appears to have come back online, restarting Tor");
|
|
|
|
|
cwtch.ResetTor();
|
|
|
|
|
}
|
|
|
|
|
connectivityState = ConnectivityState.confirmed_online;
|
|
|
|
|
}
|
|
|
|
|
}, onError: (Object error) {
|
|
|
|
|
print("Error listening to connectivity for network state: {$error}");
|
|
|
|
|
return null;
|
|
|
|
|
}, cancelOnError: true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print("Warning: Unable to open connectivity for listening to network state: {$e}");
|
|
|
|
|
connectivityStream = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeNotifierProvider<TorStatus> getTorStatusProvider() => ChangeNotifierProvider.value(value: globalTorStatus);
|
|
|
|
|
ChangeNotifierProvider<ErrorHandler> getErrorHandlerProvider() => ChangeNotifierProvider.value(value: globalErrorHandler);
|
|
|
|
|
ChangeNotifierProvider<Settings> getSettingsProvider() => ChangeNotifierProvider.value(value: globalSettings);
|
|
|
|
@ -295,7 +334,7 @@ class FlwtchState extends State<Flwtch> with WindowListener {
|
|
|
|
|
cwtch.Shutdown();
|
|
|
|
|
windowManager.removeListener(this);
|
|
|
|
|
cwtch.dispose();
|
|
|
|
|
connectivityStream.cancel();
|
|
|
|
|
connectivityStream?.cancel();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|