|
22 | 22 | import encodings |
23 | 23 |
|
24 | 24 | from gettext import gettext as _ |
| 25 | +from typing import Optional |
25 | 26 |
|
26 | 27 | from diffuse import constants, utils |
27 | 28 | from diffuse.resources import theResources |
|
35 | 36 | class DiffuseApplication(Gtk.Application): |
36 | 37 | """The main application class.""" |
37 | 38 |
|
38 | | - def __init__(self, sysconfigdir): |
| 39 | + def __init__(self, sysconfigdir: str): |
39 | 40 | super().__init__( |
40 | 41 | application_id=constants.APP_ID, |
41 | 42 | flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE | Gio.ApplicationFlags.NON_UNIQUE) |
42 | 43 |
|
43 | | - self.window = None |
44 | 44 | self.sysconfigdir = sysconfigdir |
| 45 | + self.window: Optional[DiffuseWindow] = None |
| 46 | + self.statepath: str = "" |
45 | 47 |
|
46 | 48 | self.connect('shutdown', self.on_shutdown) |
47 | 49 |
|
@@ -196,7 +198,8 @@ def __init__(self, sysconfigdir): |
196 | 198 |
|
197 | 199 | def do_activate(self) -> None: |
198 | 200 | """Called when the application is activated.""" |
199 | | - self.window.present() |
| 201 | + if self.window is not None: |
| 202 | + self.window.present() |
200 | 203 |
|
201 | 204 | def do_command_line(self, command_line): |
202 | 205 | """Called to treat the command line options.""" |
@@ -369,7 +372,8 @@ def do_command_line(self, command_line): |
369 | 372 | return 0 |
370 | 373 |
|
371 | 374 | def on_shutdown(self, application: Gio.Application) -> None: |
372 | | - self.window.save_state(self.statepath) |
| 375 | + if self.window is not None and self.statepath != '': |
| 376 | + self.window.save_state(self.statepath) |
373 | 377 |
|
374 | 378 |
|
375 | 379 | def main(version: str, sysconfigdir: str) -> int: |
|
0 commit comments