Skip to content

Commit b5ec7b3

Browse files
committed
Add "Hide Dock Icon" option
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
1 parent 2bbb966 commit b5ec7b3

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

Furious/Externals/GenTranslation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,14 @@
12951295
"ZH": "使用单色托盘图标",
12961296
"isReviewed": "True"
12971297
},
1298+
"Hide Dock Icon": {
1299+
"source": [
1300+
"Furious.TrayActions.Settings"
1301+
],
1302+
"RU": "Скрыть значок Dock",
1303+
"ZH": "隐藏程序坞图标",
1304+
"isReviewed": "True"
1305+
},
12981306
"Customize JSON Configuration...": {
12991307
"source": [
13001308
"Furious.Widget.UserServersQTableWidget"

Furious/TrayActions/Settings.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
registerAppSettings('VPNMode', isBinary=True)
2929
registerAppSettings('DarkMode', isBinary=True)
3030
registerAppSettings('UseMonochromeTrayIcon', isBinary=True)
31+
32+
if PLATFORM == 'Darwin':
33+
registerAppSettings('HideDockIcon', isBinary=True)
34+
3135
registerAppSettings('StartupOnBoot', isBinary=True, default=BinarySettings.ON_)
3236
registerAppSettings('PowerSaveMode', isBinary=True, default=BinarySettings.ON_)
3337
registerAppSettings(
@@ -100,6 +104,15 @@ def triggeredCallback(self, checked):
100104
APP().systemTray.setConnectedIcon()
101105
else:
102106
APP().systemTray.setDisconnectedIcon()
107+
elif self.textCompare('Hide Dock Icon'):
108+
if checked:
109+
APP().installDockIconVisibilityFeature()
110+
111+
AppSettings.turnON_('HideDockIcon')
112+
else:
113+
APP().installDockIconVisibilityFeature(remove=True)
114+
115+
AppSettings.turnOFF('HideDockIcon')
103116
elif self.textCompare('Startup On Boot'):
104117
if checked:
105118
StartupOnBoot.on_()
@@ -135,7 +148,7 @@ def triggeredCallback(self, checked):
135148
class SettingsAction(AppQAction):
136149
def __init__(self, **kwargs):
137150
if PLATFORM == 'Windows' or PLATFORM == 'Darwin':
138-
extraActions = [
151+
tunActions = [
139152
TUNModeAction(
140153
checkable=True,
141154
checked=AppSettings.isStateON_('VPNMode'),
@@ -149,13 +162,24 @@ def __init__(self, **kwargs):
149162
AppQSeperator(),
150163
]
151164
else:
152-
extraActions = [None]
165+
tunActions = [None]
166+
167+
if PLATFORM == 'Darwin':
168+
hideDockIconAction = [
169+
SettingsChildAction(
170+
_('Hide Dock Icon'),
171+
checkable=True,
172+
checked=AppSettings.isStateON_('HideDockIcon'),
173+
)
174+
]
175+
else:
176+
hideDockIconAction = [None]
153177

154178
super().__init__(
155179
_('Settings'),
156180
icon=bootstrapIcon('gear-wide-connected.svg'),
157181
menu=AppQMenu(
158-
*extraActions,
182+
*tunActions,
159183
SettingsChildAction(
160184
_('Dark Mode'),
161185
checkable=True,
@@ -166,6 +190,7 @@ def __init__(self, **kwargs):
166190
checkable=True,
167191
checked=AppSettings.isStateON_('UseMonochromeTrayIcon'),
168192
),
193+
*hideDockIconAction,
169194
AppQSeperator(),
170195
SettingsChildAction(
171196
_('Startup On Boot'),

Furious/Widget/Application.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ def cleanup(self):
278278

279279
logger.info('final cleanup done')
280280

281-
def _setDockIconVisible(self, visible: bool):
281+
@staticmethod
282+
def setDockIconVisible(visible: bool):
282283
if PLATFORM != 'Darwin':
283284
return
284285

@@ -292,14 +293,25 @@ def eventFilter(self, obj, event):
292293
# and hide only when window is closed (not minimized)
293294
if PLATFORM == 'Darwin' and obj is getattr(self, 'mainWindow', None):
294295
if event.type() == QtCore.QEvent.Type.Show:
295-
self._setDockIconVisible(True)
296+
self.setDockIconVisible(True)
296297
elif event.type() == QtCore.QEvent.Type.Hide:
297298
# Hide Dock icon when window is closed (not minimized)
298299
if not self.mainWindow.isMinimized():
299-
self._setDockIconVisible(False)
300+
self.setDockIconVisible(False)
300301

301302
return super().eventFilter(obj, event)
302303

304+
def installDockIconVisibilityFeature(self, remove=False):
305+
if remove:
306+
self.mainWindow.removeEventFilter(self)
307+
self.setDockIconVisible(True)
308+
else:
309+
# Install event filter for main window to track show/hide
310+
self.mainWindow.installEventFilter(self)
311+
312+
if not self.mainWindow.isVisible() and not self.mainWindow.isMinimized():
313+
self.setDockIconVisible(False)
314+
303315
def exit(self, exitcode=0):
304316
self.setExitingFlag(True)
305317

@@ -409,11 +421,9 @@ def listener(*args, **kwargs):
409421
self.mainWindow = AppMainWindow()
410422
self.systemTray = SystemTrayIcon()
411423

412-
if PLATFORM == 'Darwin':
413-
# Install event filter for main window to track show/hide
414-
self.mainWindow.installEventFilter(self)
424+
if PLATFORM == 'Darwin' and AppSettings.isStateON_('HideDockIcon'):
415425
# Hide Dock icon initially, keeping only the tray icon visible
416-
self._setDockIconVisible(False)
426+
self.installDockIconVisibilityFeature()
417427

418428
if AppSettings.isStateON_('DarkMode'):
419429
self.switchToDarkMode()

0 commit comments

Comments
 (0)