From 17599de611fcafbda1160ceb6524aa8e9e0c1ac5 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 27 Mar 2024 16:44:31 +0100 Subject: [PATCH] save notes whenever modified, using 10s rate limiter. fixes #8951 --- electrum/gui/qt/main_window.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 0c60312a9..57c8ec0e6 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -74,6 +74,7 @@ from electrum.lnutil import extract_nodeid, ConnStringFormatError from electrum.lnaddr import lndecode from electrum.submarine_swaps import SwapServerError +from .rate_limiter import rate_limited from .exception_window import Exception_Hook from .amountedit import BTCAmountEdit from .qrcodewidget import QRDialog @@ -1573,8 +1574,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): notes_tab.setFont(QtGui.QFont(MONOSPACE_FONT, 10, QtGui.QFont.Normal)) notes_tab.setPlainText(self.wallet.db.get('notes_text', '')) notes_tab.is_shown_cv = self.config.cv.GUI_QT_SHOW_TAB_NOTES + notes_tab.textChanged.connect(self.maybe_save_notes_text) return notes_tab + @rate_limited(10, ts_after=True) + def maybe_save_notes_text(self): + self.save_notes_text() + + def save_notes_text(self): + self.logger.info('saving notes') + self.wallet.db.put('notes_text', self.notes_tab.toPlainText()) + def update_console(self): console = self.console console.history = self.wallet.db.get_stored_item("qt-console-history", []) @@ -2521,7 +2531,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): fut.cancel() self.unregister_callbacks() self.config.GUI_QT_WINDOW_IS_MAXIMIZED = self.isMaximized() - self.wallet.db.put('notes_text', self.notes_tab.toPlainText()) + self.save_notes_text() if not self.isMaximized(): g = self.geometry() self.wallet.db.put("winpos-qt", [g.left(),g.top(),