1
1
import logging
2
2
import webbrowser
3
- import os
3
+ import os
4
4
import shutil
5
5
import sys
6
6
from pathlib import Path
7
7
import subprocess
8
8
import winshell
9
9
from PyQt6 .QtWidgets import QSystemTrayIcon , QMenu
10
10
from PyQt6 .QtGui import QIcon
11
- from PyQt6 .QtCore import QCoreApplication , QSize
11
+ from PyQt6 .QtCore import QCoreApplication , QSize , Qt
12
12
from core .bar_manager import BarManager
13
13
from settings import GITHUB_URL , SCRIPT_PATH , APP_NAME , DEFAULT_CONFIG_DIRECTORY
14
+ from core .config import get_config
14
15
15
16
OS_STARTUP_FOLDER = os .path .join (os .environ ['APPDATA' ], r'Microsoft\Windows\Start Menu\Programs\Startup' )
16
17
VBS_PATH = os .path .join (SCRIPT_PATH , 'yasb.vbs' )
17
-
18
+
18
19
# Check if exe file exists
19
20
INSTALLATION_PATH = os .path .abspath (os .path .join (__file__ , "../../.." ))
20
21
EXE_PATH = os .path .join (INSTALLATION_PATH , 'yasb.exe' )
21
22
SHORTCUT_FILENAME = "yasb.lnk"
22
23
AUTOSTART_FILE = EXE_PATH if os .path .exists (EXE_PATH ) else VBS_PATH
23
24
WORKING_DIRECTORY = INSTALLATION_PATH if os .path .exists (EXE_PATH ) else SCRIPT_PATH
24
-
25
- class TrayIcon (QSystemTrayIcon ):
26
25
26
+ class TrayIcon (QSystemTrayIcon ):
27
27
def __init__ (self , bar_manager : BarManager ):
28
28
super ().__init__ ()
29
29
self ._bar_manager = bar_manager
@@ -32,7 +32,16 @@ def __init__(self, bar_manager: BarManager):
32
32
self ._load_favicon ()
33
33
self ._load_context_menu ()
34
34
self .setToolTip (f"{ APP_NAME } " )
35
-
35
+ try :
36
+ config = get_config (show_error_dialog = True )
37
+ except Exception as e :
38
+ logging .error (f"Error loading config: { e } " )
39
+ return
40
+ if config ['komorebi' ]:
41
+ self .komorebi_start = config ['komorebi' ]["start_command" ]
42
+ self .komorebi_stop = config ['komorebi' ]["stop_command" ]
43
+ self .komorebi_reload = config ['komorebi' ]["reload_command" ]
44
+
36
45
def _load_favicon (self ):
37
46
# Get the current directory of the script
38
47
parent_directory = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
@@ -41,7 +50,7 @@ def _load_favicon(self):
41
50
42
51
def _load_context_menu (self ):
43
52
menu = QMenu ()
44
-
53
+ menu . setWindowModality ( Qt . WindowModality . WindowModal )
45
54
style_sheet = """
46
55
QMenu {
47
56
background-color: #26292b;
@@ -51,41 +60,52 @@ def _load_context_menu(self):
51
60
margin:0;
52
61
border-radius:6px
53
62
}
54
-
55
63
QMenu::item {
56
64
margin:0 4px;
57
- padding: 6px 16px;
58
- border-radius:4px
65
+ padding: 8px 16px;
66
+ border-radius:4px;
67
+ font-size: 11px;
59
68
}
60
-
61
69
QMenu::item:selected {
62
70
background-color: #373b3e;
63
71
}
64
-
65
72
QMenu::separator {
66
73
height: 1px;
67
74
background: #373b3e;
68
75
margin:5px 0;
69
76
}
77
+ QMenu::right-arrow {
78
+ width: 8px;
79
+ height: 8px;
80
+ padding-right: 18px;
81
+ }
70
82
"""
71
-
72
83
menu .setStyleSheet (style_sheet )
73
-
84
+
74
85
github_action = menu .addAction ("Visit GitHub" )
75
86
github_action .triggered .connect (self ._open_docs_in_browser )
87
+
76
88
open_config_action = menu .addAction ("Open Config" )
77
89
open_config_action .triggered .connect (self ._open_config )
78
- reload_action = menu .addAction ("Reload App" )
90
+
91
+ reload_action = menu .addAction ("Reload YASB" )
79
92
reload_action .triggered .connect (self ._reload_application )
80
- menu .addSeparator ()
81
93
94
+ menu .addSeparator ()
95
+
82
96
if self .is_komorebi_installed ():
83
- start_komorebi = menu .addAction ("Start Komorebi" )
97
+ komorebi_menu = menu .addMenu ("Komorebi" )
98
+ start_komorebi = komorebi_menu .addAction ("Start Komorebi" )
84
99
start_komorebi .triggered .connect (self ._start_komorebi )
85
- stop_komorebi = menu .addAction ("Stop Komorebi" )
100
+
101
+ stop_komorebi = komorebi_menu .addAction ("Stop Komorebi" )
86
102
stop_komorebi .triggered .connect (self ._stop_komorebi )
103
+
104
+ reload_komorebi = komorebi_menu .addAction ("Reload Komorebi" )
105
+ reload_komorebi .triggered .connect (self ._reload_komorebi )
106
+
87
107
menu .addSeparator ()
88
-
108
+
89
109
if self .is_autostart_enabled ():
90
110
disable_startup_action = menu .addAction ("Disable Autostart" )
91
111
disable_startup_action .triggered .connect (self ._disable_startup )
@@ -94,9 +114,10 @@ def _load_context_menu(self):
94
114
enable_startup_action .triggered .connect (self ._enable_startup )
95
115
96
116
menu .addSeparator ()
117
+
97
118
exit_action = menu .addAction ("Exit" )
98
119
exit_action .triggered .connect (self ._exit_application )
99
-
120
+
100
121
self .setContextMenu (menu )
101
122
102
123
def is_autostart_enabled (self ):
@@ -141,16 +162,22 @@ def _open_config(self):
141
162
142
163
def _start_komorebi (self ):
143
164
try :
144
- subprocess .run ("komorebic start --whkd" , stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , shell = True )
165
+ subprocess .run (self . komorebi_start , stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , shell = True )
145
166
except Exception as e :
146
167
logging .error (f"Failed to start komorebi: { e } " )
147
168
148
169
def _stop_komorebi (self ):
149
170
try :
150
- subprocess .run ("komorebic stop --whkd" , stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , shell = True )
171
+ subprocess .run (self . komorebi_stop , stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , shell = True )
151
172
except Exception as e :
152
173
logging .error (f"Failed to stop komorebi: { e } " )
153
174
175
+ def _reload_komorebi (self ):
176
+ try :
177
+ subprocess .run (self .komorebi_reload , stdout = subprocess .PIPE , stderr = subprocess .DEVNULL , shell = True )
178
+ except Exception as e :
179
+ logging .error (f"Failed to reload komorebi: { e } " )
180
+
154
181
def _reload_application (self ):
155
182
logging .info ("Reloading Application..." )
156
183
os .execl (sys .executable , sys .executable , * sys .argv )
@@ -161,4 +188,4 @@ def _exit_application(self):
161
188
QCoreApplication .exit (0 )
162
189
163
190
def _open_docs_in_browser (self ):
164
- webbrowser .open (self ._docs_url )
191
+ webbrowser .open (self ._docs_url )
0 commit comments