Skip to content

Commit feb557d

Browse files
committed
fix: add back save_state() when shuting down
1 parent f8f0b06 commit feb557d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Some signals weren't properly renamed from the previous GTK3 migration (@MightyCreak)
2424
- The syntax menu wasn't working anymore (@MightyCreak)
2525
- Properly handles SIGINT (i.e. Ctrl+C) now (@MightyCreak)
26+
- Add back `save_state()` to remember window's width and height (@MightyCreak)
2627

2728
## 0.8.1 - 2023-04-07
2829

src/diffuse/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self, sysconfigdir):
4343
self.window = None
4444
self.sysconfigdir = sysconfigdir
4545

46+
self.connect('shutdown', self.on_shutdown)
47+
4648
self.add_main_option(
4749
'version',
4850
ord('v'),
@@ -249,7 +251,7 @@ def do_command_line(self, command_line):
249251

250252
# load state
251253
self.statepath = os.path.join(data_dir, 'state')
252-
diff_window.loadState(self.statepath)
254+
diff_window.load_state(self.statepath)
253255

254256
# process remaining command line arguments
255257
encoding = None
@@ -366,6 +368,9 @@ def do_command_line(self, command_line):
366368
self.activate()
367369
return 0
368370

371+
def on_shutdown(self, application: Gio.Application) -> None:
372+
self.window.save_state(self.statepath)
373+
369374

370375
def main(version: str, sysconfigdir: str) -> int:
371376
"""The application's entry point."""

src/diffuse/window.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def focus_in_cb(self, widget, event):
985985
page.open_file(f, True)
986986

987987
# record the window's position and size
988-
def configure_cb(self, widget, event):
988+
def configure_cb(self, widget: Gtk.Widget, event: Gdk.EventConfigure) -> None:
989989
# read the state directly instead of using window_maximized as the order
990990
# of configure/window_state events is undefined
991991
if (widget.get_window().get_state() & Gdk.WindowState.MAXIMIZED) == 0:
@@ -1000,7 +1000,7 @@ def window_state_cb(self, window, event):
10001000
)
10011001

10021002
# load state information that should persist across sessions
1003-
def loadState(self, statepath: str) -> None:
1003+
def load_state(self, statepath: str) -> None:
10041004
if os.path.isfile(statepath):
10051005
try:
10061006
f = open(statepath, 'r')
@@ -1030,7 +1030,7 @@ def loadState(self, statepath: str) -> None:
10301030
self.maximize()
10311031

10321032
# save state information that should persist across sessions
1033-
def saveState(self, statepath: str) -> None:
1033+
def save_state(self, statepath: str) -> None:
10341034
try:
10351035
ss = []
10361036
for k, v in self.bool_state.items():

0 commit comments

Comments
 (0)