mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-12 22:04:54 +00:00
code cleanup and minor fixes
This commit is contained in:
parent
567c08b957
commit
cf01fc21ff
2 changed files with 7 additions and 39 deletions
|
@ -2,28 +2,18 @@ import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
||||||
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
|
||||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/device_info.dart';
|
import 'package:cake_wallet/utils/device_info.dart';
|
||||||
import 'package:cake_wallet/utils/feature_flag.dart';
|
import 'package:cake_wallet/utils/feature_flag.dart';
|
||||||
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
||||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
|
|
||||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
|
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
|
||||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
|
||||||
import 'package:cw_core/wallet_base.dart';
|
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_background_service/flutter_background_service.dart';
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
import 'package:cake_wallet/main.dart';
|
import 'package:cake_wallet/main.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
||||||
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
||||||
|
@ -32,11 +22,9 @@ const initialNotificationTitle = 'Cake Background Sync';
|
||||||
const initialNotificationContent = 'On standby - app is in the foreground';
|
const initialNotificationContent = 'On standby - app is in the foreground';
|
||||||
const notificationId = 888;
|
const notificationId = 888;
|
||||||
const notificationChannelId = 'cake_service';
|
const notificationChannelId = 'cake_service';
|
||||||
const notificationChannelName = 'CAKE BG SERVICE';
|
const notificationChannelName = 'CAKE BACKGROUND SERVICE';
|
||||||
const notificationChannelDescription = 'Cake Wallet Background Service';
|
const notificationChannelDescription = 'Cake Wallet Background Service';
|
||||||
|
const DELAY_SECONDS_BEFORE_SYNC_START = 15;
|
||||||
@pragma('vm:entry-point')
|
|
||||||
void callbackDispatcher() {}
|
|
||||||
|
|
||||||
void setNotificationStandby(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
|
void setNotificationStandby(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
|
||||||
flutterLocalNotificationsPlugin.show(
|
flutterLocalNotificationsPlugin.show(
|
||||||
|
@ -67,7 +55,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
FlutterLocalNotificationsPlugin();
|
FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
service.on('stopService').listen((event) async {
|
service.on('stopService').listen((event) async {
|
||||||
print("STOPPING SERVICE!");
|
print("STOPPING BACKGROUND SERVICE!");
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
await service.stopSelf();
|
await service.stopSelf();
|
||||||
});
|
});
|
||||||
|
@ -79,14 +67,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
service.on('setForeground').listen((event) async {
|
service.on('setForeground').listen((event) async {
|
||||||
bgSyncStarted = false;
|
bgSyncStarted = false;
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
// try {
|
setNotificationStandby(flutterLocalNotificationsPlugin);
|
||||||
// final wallet = getIt.get<AppStore>().wallet;
|
|
||||||
// wallet?.close();
|
|
||||||
// } catch (_) {
|
|
||||||
// // this throws a few errors
|
|
||||||
// }
|
|
||||||
|
|
||||||
// setNotificationStandby(flutterLocalNotificationsPlugin);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// we have entered the background, start the sync:
|
// we have entered the background, start the sync:
|
||||||
|
@ -96,13 +77,13 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
}
|
}
|
||||||
bgSyncStarted = true;
|
bgSyncStarted = true;
|
||||||
|
|
||||||
await Future.delayed(const Duration(seconds: 30));
|
await Future.delayed(const Duration(seconds: DELAY_SECONDS_BEFORE_SYNC_START));
|
||||||
print("STARTING SYNC FROM BG!!");
|
print("STARTING SYNC FROM BG!!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await initializeAppConfigs();
|
await initializeAppConfigs();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// this throws a few errors
|
// these errors still show up in logs which doesn't really make sense to me
|
||||||
}
|
}
|
||||||
|
|
||||||
print("initialized app configs");
|
print("initialized app configs");
|
||||||
|
@ -126,13 +107,6 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// print("stopping in ten seconds!");
|
|
||||||
// Timer(const Duration(seconds: 10), () {
|
|
||||||
// // stop the service after 10 seconds
|
|
||||||
// print("stopping now!");
|
|
||||||
// service.stopSelf();
|
|
||||||
// });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +183,6 @@ class BackgroundTasks {
|
||||||
|
|
||||||
void updateServiceState(bool foreground) {
|
void updateServiceState(bool foreground) {
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
// bgService.invoke("setForeground");
|
|
||||||
bgService.invoke('stopService');
|
bgService.invoke('stopService');
|
||||||
initializeService(bgService);
|
initializeService(bgService);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -129,13 +129,8 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPaused() {
|
|
||||||
wasInBackground = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
print("previous state: $_previousState current state: $state");
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
if (isQrScannerShown) {
|
if (isQrScannerShown) {
|
||||||
|
@ -190,7 +185,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
// if we enter any state other than resumed start a timer for 30 seconds
|
// if we enter any state other than resumed start a timer for 30 seconds
|
||||||
// after which we'll consider the app to be in the background
|
// after which we'll consider the app to be in the background
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
_stateTimer = Timer(const Duration(seconds: 5), () async {
|
_stateTimer = Timer(const Duration(seconds: 10), () async {
|
||||||
wasInBackground = true;
|
wasInBackground = true;
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(false);
|
getIt.get<BackgroundTasks>().updateServiceState(false);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue