mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
save
This commit is contained in:
parent
c35908cdfb
commit
9f1b9548c3
4 changed files with 67 additions and 38 deletions
|
@ -98,6 +98,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
await currentWallet?.stopSync();
|
await currentWallet?.stopSync();
|
||||||
|
|
||||||
final walletLoadingService = getIt.get<WalletLoadingService>();
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||||
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType);
|
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType);
|
||||||
|
|
||||||
bool syncAll = true;
|
bool syncAll = true;
|
||||||
|
@ -171,10 +172,10 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final wallet = syncingWallets.first!;
|
// final wallet = syncingWallets.first!;
|
||||||
final syncProgress = ((wallet.syncStatus.progress() ?? 0) * 100).toStringAsPrecision(5);
|
// final syncProgress = ((wallet.syncStatus.progress() ?? 0) * 100).toStringAsPrecision(5);
|
||||||
|
|
||||||
// String title = "${wallet!.name} ${syncProgress}% Synced";
|
// String title = "${wallet!.name} ${syncProgress}% Synced";
|
||||||
|
|
||||||
String title = "";
|
String title = "";
|
||||||
|
|
||||||
for (int i = 0; i < syncingWallets.length; i++) {
|
for (int i = 0; i < syncingWallets.length; i++) {
|
||||||
|
@ -208,36 +209,38 @@ Future<bool> onIosBackground(ServiceInstance service) async {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initializeService(FlutterBackgroundService bgService) async {
|
Future<void> initializeService(FlutterBackgroundService bgService, bool useNotifications) async {
|
||||||
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
if (useNotifications) {
|
||||||
notificationChannelId,
|
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
||||||
notificationChannelName,
|
notificationChannelId,
|
||||||
description: notificationChannelDescription,
|
notificationChannelName,
|
||||||
importance: Importance.low,
|
description: notificationChannelDescription,
|
||||||
);
|
importance: Importance.low,
|
||||||
|
|
||||||
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
||||||
FlutterLocalNotificationsPlugin();
|
|
||||||
|
|
||||||
if (Platform.isIOS || Platform.isAndroid) {
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(
|
|
||||||
const InitializationSettings(
|
|
||||||
iOS: DarwinInitializationSettings(),
|
|
||||||
android: AndroidInitializationSettings('ic_bg_service_small'),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||||
|
FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
|
if (Platform.isIOS || Platform.isAndroid) {
|
||||||
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
|
const InitializationSettings(
|
||||||
|
iOS: DarwinInitializationSettings(),
|
||||||
|
android: AndroidInitializationSettings('ic_bg_service_small'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await flutterLocalNotificationsPlugin
|
||||||
|
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
|
||||||
|
?.createNotificationChannel(channel);
|
||||||
|
|
||||||
|
flutterLocalNotificationsPlugin
|
||||||
|
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
|
||||||
|
?.requestNotificationsPermission();
|
||||||
|
|
||||||
|
setNotificationStandby(flutterLocalNotificationsPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
await flutterLocalNotificationsPlugin
|
|
||||||
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
|
|
||||||
?.createNotificationChannel(channel);
|
|
||||||
|
|
||||||
flutterLocalNotificationsPlugin
|
|
||||||
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
|
|
||||||
?.requestNotificationsPermission();
|
|
||||||
|
|
||||||
setNotificationStandby(flutterLocalNotificationsPlugin);
|
|
||||||
|
|
||||||
// notify the service that we are in the foreground:
|
// notify the service that we are in the foreground:
|
||||||
bgService.invoke("setForeground");
|
bgService.invoke("setForeground");
|
||||||
|
|
||||||
|
@ -271,10 +274,10 @@ Future<void> initializeService(FlutterBackgroundService bgService) async {
|
||||||
class BackgroundTasks {
|
class BackgroundTasks {
|
||||||
FlutterBackgroundService bgService = FlutterBackgroundService();
|
FlutterBackgroundService bgService = FlutterBackgroundService();
|
||||||
|
|
||||||
void updateServiceState(bool foreground) {
|
void updateServiceState(bool foreground, bool useNotifications) async {
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
bgService.invoke('stopService');
|
bgService.invoke('stopService');
|
||||||
initializeService(bgService);
|
initializeService(bgService, useNotifications);
|
||||||
} else {
|
} else {
|
||||||
bgService.invoke("setBackground");
|
bgService.invoke("setBackground");
|
||||||
}
|
}
|
||||||
|
@ -292,12 +295,24 @@ class BackgroundTasks {
|
||||||
.wallets
|
.wallets
|
||||||
.any((element) => element.type == WalletType.litecoin);
|
.any((element) => element.type == WalletType.litecoin);
|
||||||
|
|
||||||
|
bool hasBitcoin = getIt
|
||||||
|
.get<WalletListViewModel>()
|
||||||
|
.wallets
|
||||||
|
.any((element) => element.type == WalletType.bitcoin);
|
||||||
|
|
||||||
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
|
if (!settingsStore.silentPaymentsAlwaysScan) {
|
||||||
|
hasBitcoin = false;
|
||||||
|
}
|
||||||
|
if (!settingsStore.mwebAlwaysScan) {
|
||||||
|
hasLitecoin = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// if its not android nor ios, or the user has no monero wallets; exit
|
/// if its not android nor ios, or the user has no monero wallets; exit
|
||||||
if (!DeviceInfo.instance.isMobile || (!hasMonero && !hasLitecoin)) {
|
if (!DeviceInfo.instance.isMobile || (!hasMonero && !hasLitecoin && !hasBitcoin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final settingsStore = getIt.get<SettingsStore>();
|
|
||||||
|
|
||||||
final SyncMode syncMode = settingsStore.currentSyncMode;
|
final SyncMode syncMode = settingsStore.currentSyncMode;
|
||||||
final bool syncAll = settingsStore.currentSyncAll;
|
final bool syncAll = settingsStore.currentSyncAll;
|
||||||
|
@ -309,7 +324,7 @@ class BackgroundTasks {
|
||||||
|
|
||||||
bgService.invoke('stopService');
|
bgService.invoke('stopService');
|
||||||
|
|
||||||
await initializeService(bgService);
|
await initializeService(bgService, settingsStore.showSyncNotification);
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
print(error);
|
print(error);
|
||||||
print(stackTrace);
|
print(stackTrace);
|
||||||
|
|
|
@ -58,6 +58,7 @@ class PreferencesKey {
|
||||||
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
|
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
|
||||||
static const syncModeKey = 'sync_mode';
|
static const syncModeKey = 'sync_mode';
|
||||||
static const syncAllKey = 'sync_all';
|
static const syncAllKey = 'sync_all';
|
||||||
|
static const showSyncNotificationKey = 'show_sync_notification';
|
||||||
static const lastPopupDate = 'last_popup_date';
|
static const lastPopupDate = 'last_popup_date';
|
||||||
static const lastAppReviewDate = 'last_app_review_date';
|
static const lastAppReviewDate = 'last_app_review_date';
|
||||||
static const sortBalanceBy = 'sort_balance_by';
|
static const sortBalanceBy = 'sort_balance_by';
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:cake_wallet/core/auth_service.dart';
|
||||||
import 'package:cake_wallet/core/totp_request_details.dart';
|
import 'package:cake_wallet/core/totp_request_details.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:cake_wallet/entities/background_tasks.dart';
|
import 'package:cake_wallet/entities/background_tasks.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/view_model/link_view_model.dart';
|
import 'package:cake_wallet/view_model/link_view_model.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
@ -161,10 +162,11 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
// background service handling:
|
// background service handling:
|
||||||
|
bool showNotifications = getIt.get<SettingsStore>().showSyncNotification;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
// restart the background service if it was running before:
|
// restart the background service if it was running before:
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(true);
|
getIt.get<BackgroundTasks>().updateServiceState(true, showNotifications);
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
if (!wasInBackground) {
|
if (!wasInBackground) {
|
||||||
return;
|
return;
|
||||||
|
@ -178,7 +180,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(false);
|
getIt.get<BackgroundTasks>().updateServiceState(false, showNotifications);
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
case AppLifecycleState.detached:
|
case AppLifecycleState.detached:
|
||||||
default:
|
default:
|
||||||
|
@ -187,7 +189,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
_stateTimer = Timer(const Duration(seconds: 10), () async {
|
_stateTimer = Timer(const Duration(seconds: 10), () async {
|
||||||
wasInBackground = true;
|
wasInBackground = true;
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(false);
|
getIt.get<BackgroundTasks>().updateServiceState(false, showNotifications);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
required String initialLanguageCode,
|
required String initialLanguageCode,
|
||||||
required SyncMode initialSyncMode,
|
required SyncMode initialSyncMode,
|
||||||
required bool initialSyncAll,
|
required bool initialSyncAll,
|
||||||
|
required bool initialShowSyncNotification,
|
||||||
// required String initialCurrentLocale,
|
// required String initialCurrentLocale,
|
||||||
required this.appVersion,
|
required this.appVersion,
|
||||||
required this.deviceName,
|
required this.deviceName,
|
||||||
|
@ -169,6 +170,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
|
initialShouldRequireTOTP2FAForAllSecurityAndBackupSettings,
|
||||||
currentSyncMode = initialSyncMode,
|
currentSyncMode = initialSyncMode,
|
||||||
currentSyncAll = initialSyncAll,
|
currentSyncAll = initialSyncAll,
|
||||||
|
showSyncNotification = initialShowSyncNotification,
|
||||||
priority = ObservableMap<WalletType, TransactionPriority>(),
|
priority = ObservableMap<WalletType, TransactionPriority>(),
|
||||||
defaultBuyProviders = ObservableMap<WalletType, ProviderType>(),
|
defaultBuyProviders = ObservableMap<WalletType, ProviderType>(),
|
||||||
defaultSellProviders = ObservableMap<WalletType, ProviderType>() {
|
defaultSellProviders = ObservableMap<WalletType, ProviderType>() {
|
||||||
|
@ -389,7 +391,11 @@ abstract class SettingsStoreBase with Store {
|
||||||
|
|
||||||
reaction((_) => currentSyncAll, (bool syncAll) {
|
reaction((_) => currentSyncAll, (bool syncAll) {
|
||||||
sharedPreferences.setBool(PreferencesKey.syncAllKey, syncAll);
|
sharedPreferences.setBool(PreferencesKey.syncAllKey, syncAll);
|
||||||
|
_backgroundTasks.registerBackgroundService();
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => showSyncNotification, (bool value) {
|
||||||
|
sharedPreferences.setBool(PreferencesKey.showSyncNotificationKey, value);
|
||||||
_backgroundTasks.registerBackgroundService();
|
_backgroundTasks.registerBackgroundService();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -766,6 +772,9 @@ abstract class SettingsStoreBase with Store {
|
||||||
@observable
|
@observable
|
||||||
bool currentSyncAll;
|
bool currentSyncAll;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
bool showSyncNotification;
|
||||||
|
|
||||||
String appVersion;
|
String appVersion;
|
||||||
|
|
||||||
String deviceName;
|
String deviceName;
|
||||||
|
@ -1068,6 +1077,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 0);
|
return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 0);
|
||||||
});
|
});
|
||||||
final savedSyncAll = sharedPreferences.getBool(PreferencesKey.syncAllKey) ?? true;
|
final savedSyncAll = sharedPreferences.getBool(PreferencesKey.syncAllKey) ?? true;
|
||||||
|
final savedShowSyncNotification = sharedPreferences.getBool(PreferencesKey.showSyncNotificationKey) ?? false;
|
||||||
|
|
||||||
// migrated to secure:
|
// migrated to secure:
|
||||||
final timeOutDuration = await SecureKey.getInt(
|
final timeOutDuration = await SecureKey.getInt(
|
||||||
|
@ -1241,6 +1251,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
backgroundTasks: backgroundTasks,
|
backgroundTasks: backgroundTasks,
|
||||||
initialSyncMode: savedSyncMode,
|
initialSyncMode: savedSyncMode,
|
||||||
initialSyncAll: savedSyncAll,
|
initialSyncAll: savedSyncAll,
|
||||||
|
initialShowSyncNotification: savedShowSyncNotification,
|
||||||
shouldShowYatPopup: shouldShowYatPopup,
|
shouldShowYatPopup: shouldShowYatPopup,
|
||||||
shouldShowRepWarning: shouldShowRepWarning,
|
shouldShowRepWarning: shouldShowRepWarning,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue