Skip to content

Commit

Permalink
Work around macOS App Translocation when packaged using pyinstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrob committed Jan 20, 2024
1 parent 80e51e4 commit eb32990
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion emailproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import logging.handlers
import os
import pathlib
import platform
import plistlib
import queue
import re
Expand Down Expand Up @@ -150,7 +151,10 @@ class NSObject:

script_path = sys.executable if getattr(sys, 'frozen', False) else os.path.realpath(__file__) # for pyinstaller etc
if sys.platform == 'darwin' and '.app/Contents/MacOS/' in script_path: # pyinstaller .app binary is within the bundle
script_path = '/'.join(script_path.split('Contents/MacOS/')[0].split('/')[:-1])
if float('.'.join(platform.mac_ver()[0].split('.')[:2])) >= 10.12: # need a known path (due to App Translocation)
script_path = pathlib.Path('~/.%s/%s' % (APP_SHORT_NAME, APP_SHORT_NAME)).expanduser()
else:
script_path = '.'.join(script_path.split('Contents/MacOS/')[0].split('/')[:-1])
script_path = os.getcwd() if __package__ is not None else os.path.dirname(script_path) # for packaged version (PyPI)
CONFIG_FILE_PATH = CACHE_STORE = os.path.join(script_path, '%s.config' % APP_SHORT_NAME)
CONFIG_SERVER_MATCHER = re.compile(r'^(?P<type>(IMAP|POP|SMTP))-(?P<port>\d+)$')
Expand Down

0 comments on commit eb32990

Please sign in to comment.