Merge pull request #135 from vint2k/macos_dock_icon_visibility

macOS Dock icon visibility feature
This commit is contained in:
Loren Eteval
2025-05-31 23:03:35 +08:00
committed by GitHub
3 changed files with 33 additions and 0 deletions
+3
View File
@@ -56,6 +56,9 @@ if PLATFORM == 'Windows':
elif PLATFORM == 'Darwin':
NUITKA_BUILD = (
f'python -m nuitka '
f'--include-module=objc '
f'--include-module=AppKit '
f'--include-module=Cocoa '
f'--standalone --plugin-enable=pyside6 '
f'--disable-console '
f'--assume-yes-for-downloads '
+28
View File
@@ -278,6 +278,28 @@ class Application(ApplicationFactory, SingletonApplication):
logger.info('final cleanup done')
def _setDockIconVisible(self, visible: bool):
if PLATFORM != 'Darwin':
return
from AppKit import NSApplication
policy = 0 if visible else 1
NSApplication.sharedApplication().setActivationPolicy_(policy)
def eventFilter(self, obj, event):
# Show Dock icon on macOS when window is shown
# and hide only when window is closed (not minimized)
if PLATFORM == 'Darwin' and obj is getattr(self, 'mainWindow', None):
if event.type() == QtCore.QEvent.Type.Show:
self._setDockIconVisible(True)
elif event.type() == QtCore.QEvent.Type.Hide:
# Hide Dock icon when window is closed (not minimized)
if not self.mainWindow.isMinimized():
self._setDockIconVisible(False)
return super().eventFilter(obj, event)
def exit(self, exitcode=0):
self.setExitingFlag(True)
@@ -381,6 +403,12 @@ class Application(ApplicationFactory, SingletonApplication):
self.mainWindow = AppMainWindow()
self.systemTray = SystemTrayIcon()
if PLATFORM == 'Darwin':
# Install event filter for main window to track show/hide
self.mainWindow.installEventFilter(self)
# Hide Dock icon initially, keeping only the tray icon visible
self._setDockIconVisible(False)
if AppSettings.isStateON_('DarkMode'):
self.switchToDarkMode()
+2
View File
@@ -8,3 +8,5 @@ icmplib
sysproxy; sys_platform == "win32"
darkdetect; sys_platform != "darwin"
darkdetect[macos-listener]; sys_platform == "darwin"
pyobjc-core; sys_platform == "darwin"
pyobjc-framework-Cocoa; sys_platform == "darwin"