2222
2323import atexit
2424import logging
25- import typing
2625from importlib import metadata
2726
2827import gi
29- from safeeyes import utility
28+ from safeeyes import context , utility
3029from safeeyes .ui .about_dialog import AboutDialog
3130from safeeyes .ui .break_screen import BreakScreen
3231from safeeyes .ui .required_plugin_dialog import RequiredPluginDialog
@@ -47,19 +46,20 @@ class SafeEyes(Gtk.Application):
4746
4847 required_plugin_dialog_active = False
4948 retry_errored_plugins_count = 0
49+ context : context .Context
50+ break_screen : BreakScreen
51+ safe_eyes_core : SafeEyesCore
52+ plugins_manager : PluginManager
53+ system_locale : str
5054
51- def __init__ (self , system_locale , config ) -> None :
55+ def __init__ (self , system_locale : str , config ) -> None :
5256 super ().__init__ (
5357 application_id = "io.github.slgobinath.SafeEyes" ,
5458 flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE ,
5559 )
5660
5761 self .active = False
58- self .break_screen = None
59- self .safe_eyes_core = None
6062 self .config = config
61- self .context : typing .Any = {}
62- self .plugins_manager = None
6363 self .settings_dialog_active = False
6464 self ._status = ""
6565 self .system_locale = system_locale
@@ -219,39 +219,23 @@ def do_command_line(self, command_line):
219219
220220 return 0
221221
222- def do_startup (self ):
222+ def do_startup (self ) -> None :
223223 Gtk .Application .do_startup (self )
224224
225225 logging .info ("Starting up Application" )
226226
227227 # Initialize the Safe Eyes Context
228- self .context ["version" ] = SAFE_EYES_VERSION
229- self .context ["desktop" ] = utility .desktop_environment ()
230- self .context ["is_wayland" ] = utility .is_wayland ()
231- self .context ["locale" ] = self .system_locale
232- self .context ["api" ] = {}
233- self .context ["api" ]["show_settings" ] = lambda : utility .execute_main_thread (
234- self .show_settings
235- )
236- self .context ["api" ]["show_about" ] = lambda : utility .execute_main_thread (
237- self .show_about
238- )
239- self .context ["api" ]["enable_safeeyes" ] = (
240- lambda next_break_time = - 1 : utility .execute_main_thread (
241- self .enable_safeeyes , next_break_time
242- )
243- )
244- self .context ["api" ]["disable_safeeyes" ] = (
245- lambda status = None , is_resting = False : utility .execute_main_thread (
246- self .disable_safeeyes , status , is_resting
247- )
248- )
249- self .context ["api" ]["status" ] = self .status
250- self .context ["api" ]["quit" ] = lambda : utility .execute_main_thread (self .quit )
251228 if self .config .get ("persist_state" ):
252- self . context [ " session" ] = utility .open_session ()
229+ session = utility .open_session ()
253230 else :
254- self .context ["session" ] = {"plugin" : {}}
231+ session = {"plugin" : {}}
232+
233+ self .context = context .Context (
234+ api = context .API (self ),
235+ locale = self .system_locale ,
236+ version = SAFE_EYES_VERSION ,
237+ session = session ,
238+ )
255239
256240 # Initialize the theme
257241 self ._initialize_styles ()
@@ -269,10 +253,6 @@ def do_startup(self):
269253 self .safe_eyes_core .on_stop_break += self .stop_break
270254 self .safe_eyes_core .on_update_next_break += self .update_next_break
271255 self .safe_eyes_core .initialize (self .config )
272- self .context ["api" ]["take_break" ] = self .take_break
273- self .context ["api" ]["has_breaks" ] = self .safe_eyes_core .has_breaks
274- self .context ["api" ]["postpone" ] = self .safe_eyes_core .postpone
275- self .context ["api" ]["get_break_time" ] = self .safe_eyes_core .get_break_time
276256
277257 try :
278258 self .plugins_manager .init (self .context , self .config )
@@ -289,7 +269,7 @@ def do_startup(self):
289269 and self .safe_eyes_core .has_breaks ()
290270 ):
291271 self .active = True
292- self .context [ " state" ] = State .START
272+ self .context . state = State .START
293273 self .plugins_manager .start () # Call the start method of all plugins
294274 self .safe_eyes_core .start ()
295275 self .handle_system_suspend ()
0 commit comments