Skip to content

Commit 9b25fac

Browse files
committed
Better missing GUI requirements message on macOS
Fixes #286
1 parent 3b6f180 commit 9b25fac

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

emailproxy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2024-09-12' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2024-09-24' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -2601,7 +2601,8 @@ def __init__(self, args=None):
26012601

26022602
if self.args.gui and len(MISSING_GUI_REQUIREMENTS) > 0:
26032603
Log.error('Unable to load all GUI requirements:', MISSING_GUI_REQUIREMENTS, '- did you mean to run in',
2604-
'`--no-gui` mode? If not, please run `python -m pip install -r requirements-gui.txt`')
2604+
'`--no-gui` mode? If not, please run `python -m pip install -r requirements-gui.txt` or install',
2605+
'from PyPI with GUI requirements included: `python -m pip install emailproxy[gui]`')
26052606
self.exit(None)
26062607
return
26072608

@@ -2622,6 +2623,9 @@ def __init__(self, args=None):
26222623
# noinspection PyUnresolvedReferences,PyAttributeOutsideInit
26232624
def init_platforms(self):
26242625
if sys.platform == 'darwin' and self.args.gui:
2626+
if len(MISSING_GUI_REQUIREMENTS) > 0:
2627+
return # skip - we will exit anyway due to missing requirements (with a more helpful error message)
2628+
26252629
# hide dock icon (but not LSBackgroundOnly as we need input via webview)
26262630
info = AppKit.NSBundle.mainBundle().infoDictionary()
26272631
info['LSUIElement'] = '1'
@@ -3417,7 +3421,8 @@ def exit(self, icon, restart_callback=None):
34173421

34183422
AppConfig.save()
34193423

3420-
if sys.platform == 'darwin' and self.args.gui:
3424+
# attribute existence check is needed here and below because we may exit before init_platforms() has run
3425+
if sys.platform == 'darwin' and self.args.gui and hasattr(self, 'macos_reachability_target'):
34213426
# noinspection PyUnresolvedReferences
34223427
SystemConfiguration.SCNetworkReachabilityUnscheduleFromRunLoop(self.macos_reachability_target,
34233428
SystemConfiguration.CFRunLoopGetCurrent(),
@@ -3451,7 +3456,8 @@ def exit(self, icon, restart_callback=None):
34513456
restart_callback()
34523457

34533458
# macOS Launch Agents need reloading when changed; unloading exits immediately so this must be our final action
3454-
if sys.platform == 'darwin' and self.args.gui and self.macos_unload_plist_on_exit:
3459+
if sys.platform == 'darwin' and self.args.gui and (
3460+
hasattr(self, 'macos_unload_plist_on_exit') and self.macos_unload_plist_on_exit):
34553461
self.macos_launchctl('unload')
34563462

34573463

0 commit comments

Comments
 (0)