From 701c6b20040adea196c77289cb6b18334d3fe655 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Tue, 28 May 2024 17:18:38 +0200 Subject: [PATCH] Only stop wallet on rename and delete --- cw_monero/lib/monero_wallet.dart | 32 +++++++++---------- cw_monero/lib/monero_wallet_service.dart | 20 ++++++++++++ .../flutter/generated_plugin_registrant.cc | 6 ++-- windows/flutter/generated_plugins.cmake | 2 +- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index a823ed9f6..a30c22745 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -151,23 +151,6 @@ abstract class MoneroWalletBase _listener?.stop(); _onAccountChangeReaction?.reaction.dispose(); _autoSaveTimer?.cancel(); - - final currentWalletDirPath = await pathForWalletDir(name: name, type: type); - if (openedWalletsByPath["$currentWalletDirPath/$name"] != null) { - // NOTE: this is realistically only required on windows. - print("closing wallet"); - final wmaddr = wmPtr.address; - final waddr = openedWalletsByPath["$currentWalletDirPath/$name"]!.address; - await Isolate.run(() { - monero.WalletManager_closeWallet( - Pointer.fromAddress(wmaddr), - Pointer.fromAddress(waddr), - true - ); - }); - openedWalletsByPath.remove("$currentWalletDirPath/$name"); - print("wallet closed"); - } } @override @@ -357,6 +340,21 @@ abstract class MoneroWalletBase @override Future renameWalletFiles(String newWalletName) async { final currentWalletDirPath = await pathForWalletDir(name: name, type: type); + if (openedWalletsByPath["$currentWalletDirPath/$name"] != null) { + // NOTE: this is realistically only required on windows. + print("closing wallet"); + final wmaddr = wmPtr.address; + final waddr = openedWalletsByPath["$currentWalletDirPath/$name"]!.address; + await Isolate.run(() { + monero.WalletManager_closeWallet( + Pointer.fromAddress(wmaddr), + Pointer.fromAddress(waddr), + true + ); + }); + openedWalletsByPath.remove("$currentWalletDirPath/$name"); + print("wallet closed"); + } try { // -- rename the waller folder -- final currentWalletDir = Directory(await pathForWalletDir(name: name, type: type)); diff --git a/cw_monero/lib/monero_wallet_service.dart b/cw_monero/lib/monero_wallet_service.dart index bc59499f9..f8d5d6584 100644 --- a/cw_monero/lib/monero_wallet_service.dart +++ b/cw_monero/lib/monero_wallet_service.dart @@ -1,4 +1,6 @@ +import 'dart:ffi'; import 'dart:io'; +import 'dart:isolate'; import 'package:cw_core/monero_wallet_utils.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/unspent_coins_info.dart'; @@ -10,10 +12,12 @@ import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/get_height_by_date.dart'; import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart'; import 'package:cw_monero/api/wallet_manager.dart' as monero_wallet_manager; +import 'package:cw_monero/api/wallet_manager.dart'; import 'package:cw_monero/monero_wallet.dart'; import 'package:flutter/widgets.dart'; import 'package:hive/hive.dart'; import 'package:polyseed/polyseed.dart'; +import 'package:monero/monero.dart' as monero; class MoneroNewWalletCredentials extends WalletCredentials { MoneroNewWalletCredentials( @@ -174,6 +178,22 @@ class MoneroWalletService extends WalletService remove(String wallet) async { final path = await pathForWalletDir(name: wallet, type: getType()); + if (openedWalletsByPath["$path/$wallet"] != null) { + // NOTE: this is realistically only required on windows. + print("closing wallet"); + final wmaddr = wmPtr.address; + final waddr = openedWalletsByPath["$path/$wallet"]!.address; + // await Isolate.run(() { + monero.WalletManager_closeWallet( + Pointer.fromAddress(wmaddr), + Pointer.fromAddress(waddr), + false + ); + // }); + openedWalletsByPath.remove("$path/$wallet"); + print("wallet closed"); + } + final file = Directory(path); final isExist = file.existsSync(); diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 28094fc5a..323f53c9f 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,18 +7,18 @@ #include "generated_plugin_registrant.h" #include +#include #include -#include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { ConnectivityPlusWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); + FlutterLocalAuthenticationPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterLocalAuthenticationPluginCApi")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); - LocalAuthPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("LocalAuthPlugin")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 57d44c08e..d522bed84 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,8 +4,8 @@ list(APPEND FLUTTER_PLUGIN_LIST connectivity_plus + flutter_local_authentication flutter_secure_storage_windows - local_auth_windows permission_handler_windows url_launcher_windows )