Only stop wallet on rename and delete

This commit is contained in:
Konstantin Ullrich 2024-05-28 17:18:38 +02:00
parent dc424b58fc
commit 701c6b2004
No known key found for this signature in database
GPG key ID: E9562A013280F5DB
4 changed files with 39 additions and 21 deletions

View file

@ -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<void> 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));

View file

@ -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<MoneroNewWalletCredentials,
@override
Future<void> 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();

View file

@ -7,18 +7,18 @@
#include "generated_plugin_registrant.h"
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <flutter_local_authentication/flutter_local_authentication_plugin_c_api.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <local_auth_windows/local_auth_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
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(

View file

@ -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
)