diff --git a/electrum/daemon.py b/electrum/daemon.py index ad7a81430..40fb1ac9c 100644 --- a/electrum/daemon.py +++ b/electrum/daemon.py @@ -497,6 +497,7 @@ class Daemon(Logger): wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config) wallet.start_network(self.network) self.add_wallet(wallet) + self.update_recently_opened_wallets(path) return wallet @staticmethod @@ -542,6 +543,7 @@ class Daemon(Logger): self.stop_wallet(path) if os.path.exists(path): os.unlink(path) + self.update_recently_opened_wallets(path, remove=True) return True return False @@ -704,3 +706,14 @@ class Daemon(Logger): self._check_password_for_directory( old_password=old_password, new_password=new_password, wallet_dir=wallet_dir) return True + + def update_recently_opened_wallets(self, wallet_path, *, remove: bool = False): + recent = self.config.RECENTLY_OPEN_WALLET_FILES or [] + if wallet_path in recent: + recent.remove(wallet_path) + if not remove: + recent.insert(0, wallet_path) + recent = [path for path in recent if os.path.exists(path)] + recent = recent[:5] + self.config.RECENTLY_OPEN_WALLET_FILES = recent + util.trigger_callback('recently_opened_wallets_update') diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 4e61fae32..71ab1a6c7 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -491,6 +491,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): def on_event_proxy_set(self, *args): self.tor_button.setVisible(False) + @qt_event_listener + def on_event_recently_opened_wallets_update(self, *args): + self.update_recently_opened_menu() + def close_wallet(self): if self.wallet: self.logger.info(f'close_wallet {self.wallet.storage.path}') @@ -498,7 +502,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): @profiler def load_wallet(self, wallet: Abstract_Wallet): - self.update_recently_visited(wallet.storage.path) + self.update_recently_opened_menu() if wallet.has_lightning(): util.trigger_callback('channels_updated', wallet) self.need_update.set() @@ -643,24 +647,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): self.show_message(msg, title=_("Wallet backup created")) return True - def update_recently_visited(self, filename): - recent = self.config.RECENTLY_OPEN_WALLET_FILES or [] - try: - sorted(recent) - except Exception: - recent = [] - if filename in recent: - recent.remove(filename) - recent.insert(0, filename) - recent = [path for path in recent if os.path.exists(path)] - recent = recent[:5] - self.config.RECENTLY_OPEN_WALLET_FILES = recent + def update_recently_opened_menu(self): + recent = self.config.RECENTLY_OPEN_WALLET_FILES self.recently_visited_menu.clear() - for i, k in enumerate(sorted(recent)): + for i, k in enumerate(recent): b = os.path.basename(k) + def loader(k): return lambda: self.gui_object.new_window(k) - self.recently_visited_menu.addAction(b, loader(k)).setShortcut(QKeySequence("Ctrl+%d"%(i+1))) + self.recently_visited_menu.addAction(b, loader(k)).setShortcut(QKeySequence("Ctrl+%d" % (i+1))) self.recently_visited_menu.setEnabled(bool(len(recent))) def get_wallet_folder(self):