perf(panel): defer heavy component imports to first use
This commit is contained in:
1 file changed
+28
-11
+28
-11
@@ -12,11 +12,7 @@ from services.config import get_config_all, on_config_change
|
|||||||
from services.modus import notification_service
|
from services.modus import notification_service
|
||||||
from utils.gtk_utils import setup_cursor_hover, svg_file
|
from utils.gtk_utils import setup_cursor_hover, svg_file
|
||||||
from utils.roam import modus_service
|
from utils.roam import modus_service
|
||||||
from window.controlcenter.main import ModusControlCenter
|
|
||||||
from window.notification.notification_center import NotificationCenter
|
|
||||||
from window.panel.components.custom_mods import CustomMods
|
from window.panel.components.custom_mods import CustomMods
|
||||||
from window.panel.components.enhanced_system_tray import apply_enhanced_system_tray
|
|
||||||
from window.panel.components.globalmenu import GlobalMenu
|
|
||||||
from window.panel.components.indicators import (
|
from window.panel.components.indicators import (
|
||||||
BatteryIndicator,
|
BatteryIndicator,
|
||||||
BluetoothIndicator,
|
BluetoothIndicator,
|
||||||
@@ -25,8 +21,6 @@ from window.panel.components.indicators import (
|
|||||||
from window.panel.components.workspace import WorkspaceIndicator
|
from window.panel.components.workspace import WorkspaceIndicator
|
||||||
from window.panel.notch import Notch
|
from window.panel.notch import Notch
|
||||||
|
|
||||||
apply_enhanced_system_tray()
|
|
||||||
|
|
||||||
|
|
||||||
class Panel(Window):
|
class Panel(Window):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@@ -39,13 +33,21 @@ class Panel(Window):
|
|||||||
visible=False,
|
visible=False,
|
||||||
all_visible=False,
|
all_visible=False,
|
||||||
)
|
)
|
||||||
self.globalmenu = GlobalMenu(parent_window=self)
|
|
||||||
|
# Deferred from module import: patches SystemTrayItem before any tray
|
||||||
|
# item is created.
|
||||||
|
from window.panel.components.enhanced_system_tray import (
|
||||||
|
apply_enhanced_system_tray,
|
||||||
|
)
|
||||||
|
|
||||||
|
apply_enhanced_system_tray()
|
||||||
|
|
||||||
|
self._globalmenu_instance = None
|
||||||
|
|
||||||
self.imac = Gtk.MenuButton(name="panel-button")
|
self.imac = Gtk.MenuButton(name="panel-button")
|
||||||
self.imac.get_style_context().add_class("flat")
|
self.imac.get_style_context().add_class("flat")
|
||||||
self.imac.add(svg_file("misc/logo.svg", size=18))
|
self.imac.add(svg_file("misc/logo.svg", size=18))
|
||||||
setup_cursor_hover(self.imac, "pointer")
|
setup_cursor_hover(self.imac, "pointer")
|
||||||
self.globalmenu.set_imac_button(self.imac)
|
|
||||||
|
|
||||||
self.tray = SystemTray(name="panel-button", spacing=4, icon_size=20)
|
self.tray = SystemTray(name="panel-button", spacing=4, icon_size=20)
|
||||||
|
|
||||||
@@ -217,9 +219,20 @@ class Panel(Window):
|
|||||||
)
|
)
|
||||||
return self._todo_instance
|
return self._todo_instance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def globalmenu(self):
|
||||||
|
if self._globalmenu_instance is None:
|
||||||
|
from window.panel.components.globalmenu import GlobalMenu
|
||||||
|
|
||||||
|
self._globalmenu_instance = GlobalMenu(parent_window=self)
|
||||||
|
self._globalmenu_instance.set_imac_button(self.imac)
|
||||||
|
return self._globalmenu_instance
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def control_center(self):
|
def control_center(self):
|
||||||
if self._control_center_instance is None:
|
if self._control_center_instance is None:
|
||||||
|
from window.controlcenter.main import ModusControlCenter
|
||||||
|
|
||||||
self._control_center_instance = ModusControlCenter(
|
self._control_center_instance = ModusControlCenter(
|
||||||
parent=self, pointing_to=self.control_center_btn
|
parent=self, pointing_to=self.control_center_btn
|
||||||
)
|
)
|
||||||
@@ -228,6 +241,8 @@ class Panel(Window):
|
|||||||
@property
|
@property
|
||||||
def notification_center(self):
|
def notification_center(self):
|
||||||
if self._notification_center_instance is None:
|
if self._notification_center_instance is None:
|
||||||
|
from window.notification.notification_center import NotificationCenter
|
||||||
|
|
||||||
self._notification_center_instance = NotificationCenter(
|
self._notification_center_instance = NotificationCenter(
|
||||||
parent=self, pointing_to=self.notification_center_btn
|
parent=self, pointing_to=self.notification_center_btn
|
||||||
)
|
)
|
||||||
@@ -393,12 +408,14 @@ class Panel(Window):
|
|||||||
|
|
||||||
# Destroy components
|
# Destroy components
|
||||||
for component in [
|
for component in [
|
||||||
self.globalmenu,
|
self._globalmenu_instance,
|
||||||
self.notch,
|
self.notch,
|
||||||
self.custom_mods,
|
self.custom_mods,
|
||||||
self.workspace_indicator,
|
self.workspace_indicator,
|
||||||
self.indicators,
|
self.indicators,
|
||||||
]:
|
]:
|
||||||
|
if component is None:
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
component.destroy()
|
component.destroy()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -406,8 +423,8 @@ class Panel(Window):
|
|||||||
|
|
||||||
# Destroy MouseCapture windows
|
# Destroy MouseCapture windows
|
||||||
for mc in [
|
for mc in [
|
||||||
self.control_center,
|
self._control_center_instance,
|
||||||
self.notification_center,
|
self._notification_center_instance,
|
||||||
self._pomodoro_instance,
|
self._pomodoro_instance,
|
||||||
self._todo_instance,
|
self._todo_instance,
|
||||||
]:
|
]:
|
||||||
|
|||||||
Reference in new issue
Block a user