mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-20 17:54:41 +00:00
updates to bg sync
This commit is contained in:
parent
b089d928e1
commit
53dd533580
5 changed files with 24 additions and 6 deletions
|
@ -103,5 +103,6 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
|
|||
|
||||
bool isTestnet = false;
|
||||
|
||||
Future<void> closeWallet() async {}
|
||||
// TODO: use proxy layer
|
||||
Future<void> reopenWallet() async {}
|
||||
}
|
||||
|
|
|
@ -233,6 +233,10 @@ void closeCurrentWallet() {
|
|||
monero.Wallet_stop(wptr!);
|
||||
}
|
||||
|
||||
void stopWallet() {
|
||||
monero.Wallet_stop(wptr!);
|
||||
}
|
||||
|
||||
String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!);
|
||||
|
||||
String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!);
|
||||
|
|
|
@ -39,6 +39,7 @@ import 'package:hive/hive.dart';
|
|||
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:monero/monero.dart' as monero;
|
||||
import 'package:cw_monero/api/transaction_history.dart' as transaction_history;
|
||||
|
||||
part 'monero_wallet.g.dart';
|
||||
|
||||
|
@ -175,6 +176,7 @@ abstract class MoneroWalletBase
|
|||
_onAccountChangeReaction?.reaction.dispose();
|
||||
_onTxHistoryChangeReaction?.reaction.dispose();
|
||||
_autoSaveTimer?.cancel();
|
||||
monero_wallet.stopWallet();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -268,6 +270,7 @@ abstract class MoneroWalletBase
|
|||
_listener?.stop();
|
||||
if (isBackgroundSync) {
|
||||
isBackgroundSyncing = false;
|
||||
monero_wallet.stopWallet();
|
||||
monero_wallet.stopBackgroundSync(password);
|
||||
return;
|
||||
}
|
||||
|
@ -277,7 +280,7 @@ abstract class MoneroWalletBase
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> closeWallet() async {
|
||||
Future<void> reopenWallet() async {
|
||||
printV("closing wallet");
|
||||
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
||||
final wmaddr = wmPtr.address;
|
||||
|
@ -286,7 +289,10 @@ abstract class MoneroWalletBase
|
|||
monero.WalletManager_closeWallet(
|
||||
Pointer.fromAddress(wmaddr), Pointer.fromAddress(waddr), true);
|
||||
});
|
||||
await init();
|
||||
wptr = monero.WalletManager_openWallet(wmPtr, path: currentWalletDirPath, password: password);
|
||||
openedWalletsByPath["$currentWalletDirPath/$name"] = wptr!;
|
||||
transaction_history.txhistory = null;
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -164,17 +164,16 @@ Future<void> onStart(ServiceInstance service) async {
|
|||
for (int i = 0; i < syncingWallets.length; i++) {
|
||||
final wallet = syncingWallets[i];
|
||||
await wallet.stopSync(isBackgroundSync: true);
|
||||
await wallet.close();
|
||||
}
|
||||
// stop all standby wallets (just in case):
|
||||
for (int i = 0; i < standbyWallets.length; i++) {
|
||||
final wallet = standbyWallets[i];
|
||||
await wallet.stopSync(isBackgroundSync: true);
|
||||
await wallet.close();
|
||||
}
|
||||
} catch (e) {
|
||||
printV("error stopping sync: $e");
|
||||
}
|
||||
printV("done stopping sync");
|
||||
}
|
||||
|
||||
service.on("stopService").listen((event) async {
|
||||
|
|
|
@ -180,10 +180,18 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
return;
|
||||
}
|
||||
|
||||
await wallet?.stopSync(isBackgroundSync: true);
|
||||
// await wallet?.closeWallet();
|
||||
// restart the background service if it was running before:
|
||||
await getIt.get<BackgroundTasks>().serviceForeground();
|
||||
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
|
||||
await wallet?.stopSync(isBackgroundSync: true);
|
||||
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
|
||||
await wallet?.reopenWallet();
|
||||
|
||||
break;
|
||||
case AppLifecycleState.hidden:
|
||||
case AppLifecycleState.inactive:
|
||||
|
|
Loading…
Reference in a new issue