mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 03:49:43 +00:00
save
This commit is contained in:
parent
cab76cc6a3
commit
df70bb7a56
2 changed files with 38 additions and 17 deletions
|
@ -203,30 +203,34 @@ abstract class MoneroWalletBase
|
|||
|
||||
@override
|
||||
Future<void> startSync({bool isBackgroundSync = false}) async {
|
||||
if (isBackgroundSync) {
|
||||
try {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
monero_wallet.startBackgroundSync();
|
||||
isBackgroundSyncing = true;
|
||||
_setListeners();
|
||||
_listener?.start();
|
||||
return;
|
||||
} catch (e) {
|
||||
isBackgroundSyncing = false;
|
||||
syncStatus = FailedSyncStatus();
|
||||
printV(e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
// if (isBackgroundSync) {
|
||||
// try {
|
||||
// syncStatus = AttemptingSyncStatus();
|
||||
// monero_wallet.startBackgroundSync();
|
||||
// isBackgroundSyncing = true;
|
||||
// _setListeners();
|
||||
// _listener?.start();
|
||||
// return;
|
||||
// } catch (e) {
|
||||
// isBackgroundSyncing = false;
|
||||
// syncStatus = FailedSyncStatus();
|
||||
// printV(e);
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
monero_wallet.startRefresh();
|
||||
// monero_wallet.startRefresh();
|
||||
monero_wallet.setupBackgroundSync(
|
||||
backgroundSyncType: 2,
|
||||
walletPassword: password,
|
||||
backgroundCachePassword: "testing-cache-password",
|
||||
);
|
||||
monero_wallet.startBackgroundSync();
|
||||
if (isBackgroundSync) {
|
||||
isBackgroundSyncing = true;
|
||||
}
|
||||
_setListeners();
|
||||
_listener?.start();
|
||||
} catch (e) {
|
||||
|
|
|
@ -156,6 +156,7 @@ Future<void> onStart(ServiceInstance service) async {
|
|||
printV("error stopping sync: $e");
|
||||
}
|
||||
// stop the service itself:
|
||||
service.invoke("serviceState", {"state": "NOT_RUNNING"});
|
||||
await service.stopSelf();
|
||||
});
|
||||
|
||||
|
@ -163,10 +164,15 @@ Future<void> onStart(ServiceInstance service) async {
|
|||
printV(event);
|
||||
});
|
||||
|
||||
service.on("setForeground").listen((event) async {
|
||||
void setForeground() {
|
||||
bgSyncStarted = false;
|
||||
_syncTimer?.cancel();
|
||||
setNotificationStandby(flutterLocalNotificationsPlugin);
|
||||
}
|
||||
|
||||
service.on("setForeground").listen((event) async {
|
||||
setForeground();
|
||||
service.invoke("serviceState", {"state": "FOREGROUND"});
|
||||
});
|
||||
|
||||
void setReady() {
|
||||
|
@ -175,6 +181,7 @@ Future<void> onStart(ServiceInstance service) async {
|
|||
|
||||
service.on("setReady").listen((event) async {
|
||||
setReady();
|
||||
service.invoke("serviceState", {"state": "READY"});
|
||||
});
|
||||
|
||||
service.on("foregroundPing").listen((event) async {
|
||||
|
@ -488,6 +495,7 @@ Future<void> onStart(ServiceInstance service) async {
|
|||
if (fgCount > 10) {
|
||||
fgCount = 0;
|
||||
setBackground();
|
||||
service.invoke("serviceState", {"state": "BACKGROUND"});
|
||||
_bgTimer?.cancel();
|
||||
}
|
||||
});
|
||||
|
@ -571,6 +579,7 @@ class BackgroundTasks {
|
|||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
Timer? _pingTimer;
|
||||
String serviceState = "NOT_RUNNING";
|
||||
|
||||
void serviceBackground() {
|
||||
bgService.invoke("setBackground");
|
||||
|
@ -582,6 +591,10 @@ class BackgroundTasks {
|
|||
}
|
||||
|
||||
Future<void> serviceForeground() async {
|
||||
if (serviceState == "FOREGROUND") {
|
||||
return;
|
||||
}
|
||||
|
||||
final settingsStore = getIt.get<SettingsStore>();
|
||||
bool showNotifications = settingsStore.showSyncNotification;
|
||||
bgService.invoke("stopService");
|
||||
|
@ -645,6 +658,10 @@ class BackgroundTasks {
|
|||
getIt.get<BackgroundTasks>().foregroundPing();
|
||||
});
|
||||
|
||||
bgService.on("serviceState").listen((event) {
|
||||
serviceState = event?["state"] as String;
|
||||
});
|
||||
|
||||
await initializeService(bgService, useNotifications);
|
||||
} catch (error, stackTrace) {
|
||||
printV(error);
|
||||
|
|
Loading…
Reference in a new issue