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