Skip to content

Commit

Permalink
Better missing GUI requirements message on macOS
Browse files Browse the repository at this point in the history
Fixes #286
  • Loading branch information
simonrob committed Sep 24, 2024
1 parent 3b6f180 commit 9b25fac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions emailproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = 'Simon Robinson'
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
__license__ = 'Apache 2.0'
__version__ = '2024-09-12' # ISO 8601 (YYYY-MM-DD)
__version__ = '2024-09-24' # ISO 8601 (YYYY-MM-DD)
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only

import abc
Expand Down Expand Up @@ -2601,7 +2601,8 @@ def __init__(self, args=None):

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

Expand All @@ -2622,6 +2623,9 @@ def __init__(self, args=None):
# noinspection PyUnresolvedReferences,PyAttributeOutsideInit
def init_platforms(self):
if sys.platform == 'darwin' and self.args.gui:
if len(MISSING_GUI_REQUIREMENTS) > 0:
return # skip - we will exit anyway due to missing requirements (with a more helpful error message)

# hide dock icon (but not LSBackgroundOnly as we need input via webview)
info = AppKit.NSBundle.mainBundle().infoDictionary()
info['LSUIElement'] = '1'
Expand Down Expand Up @@ -3417,7 +3421,8 @@ def exit(self, icon, restart_callback=None):

AppConfig.save()

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

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


Expand Down

0 comments on commit 9b25fac

Please sign in to comment.