From c22bfd61af8739c07f0b58dc92451c046ad630c2 Mon Sep 17 00:00:00 2001 From: Lucas Tanure Date: Thu, 29 Oct 2026 09:36:34 +0000 Subject: [PATCH] Save notes when the session manager stops the application Text typed into a note reaches the disk only after two chained timers: one second after the last keystroke, then three more seconds before the file is written. At logout or shutdown the session manager stops the application with SIGTERM. The process has no handler for it and dies at once, so pending timers never run and the last seconds of typing are lost. A short note written just before shutting down comes back empty after the next login. Moving or resizing a note inside that one-second window also cleared the pending "text changed" flag, so even a save that did happen could write the old text. Signed-off-by: Lucas Tanure --- usr/lib/sticky/sticky.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/usr/lib/sticky/sticky.py b/usr/lib/sticky/sticky.py index a409e0f..3d2a841 100755 --- a/usr/lib/sticky/sticky.py +++ b/usr/lib/sticky/sticky.py @@ -2,6 +2,7 @@ import json import os +import signal import sys import gi @@ -374,7 +375,7 @@ def restore(self, time=0): self.move(self.x, self.y) def queue_update(self, b=None, invalidate_cache=False): - self.invalid_cache = invalidate_cache + self.invalid_cache = self.invalid_cache or invalidate_cache if self.changed_timer_id: GLib.source_remove(self.changed_timer_id) @@ -801,6 +802,10 @@ def do_activate(self): self.hold() + GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, self.quit_app) + GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, self.quit_app) + GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, self.quit_app) + if self.autostart_mode: self.autostart_mode = False if not self.settings.get_boolean("autostart-notes-visible"): @@ -1259,7 +1264,19 @@ def on_removed(self, note): self.notes.remove(note) self.on_update() + def flush_pending_updates(self): + pending = False + for note in self.notes: + if note.changed_timer_id: + GLib.source_remove(note.changed_timer_id) + note.changed_timer_id = 0 + pending = True + + if pending: + self.on_update() + def quit_app(self, *args): + self.flush_pending_updates() self.file_handler.flush() for note in self.notes: