Skip to content

Commit b7f788a

Browse files
committed
Fix default log file path on Windows when using PyInstaller
Also avoid repeated recreation of the GUI menu on startup
1 parent 0a1e16b commit b7f788a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ If this argument is not provided, the proxy will look for `emailproxy.config` in
100100
The value of this argument can either be the full path to a local file (which must be writable), or an identifier for an external store such as a secrets manager (see the [documentation below](#advanced-configuration)).
101101
If this argument is not provided, credentials will be cached in the current configuration file.
102102

103-
- `--log-file` allows you to specify the location of a file to send log output to.
103+
- `--log-file` allows you to specify the location of a file to send log output to (full path required).
104104
Log files are rotated at 32MB and 10 older log files are kept.
105105
This option overrides the proxy's default behaviour, which varies by platform (see [below](#troubleshooting) for details).
106106

emailproxy.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2022 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2023-03-27' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2023-03-28' # ISO 8601 (YYYY-MM-DD)
1010

1111
import abc
1212
import argparse
@@ -212,7 +212,8 @@ def initialise(log_file=None):
212212
Log._LOGGER = logging.getLogger(APP_NAME)
213213
if log_file or sys.platform == 'win32':
214214
handler = logging.handlers.RotatingFileHandler(
215-
log_file or '%s/%s.log' % (os.path.dirname(os.path.realpath(__file__)), APP_SHORT_NAME),
215+
log_file or '%s/%s.log' % (os.path.dirname(sys.executable if getattr(sys, 'frozen', False) else
216+
os.path.realpath(__file__)), APP_SHORT_NAME),
216217
maxBytes=LOG_FILE_MAX_SIZE, backupCount=LOG_FILE_MAX_BACKUPS)
217218
handler.setFormatter(logging.Formatter('%(asctime)s: %(message)s'))
218219
elif sys.platform == 'darwin':
@@ -2313,10 +2314,8 @@ def get_icon_size(text, font_size):
23132314
def create_config_menu(self):
23142315
items = []
23152316
if len(self.proxies) <= 0:
2316-
# note that we don't actually allow no servers when loading config, but just in case that behaviour changes
2317-
items.append(pystray.MenuItem('Servers:', None, enabled=False))
2318-
items.append(pystray.MenuItem(' No servers configured', None, enabled=False))
2319-
items.append(pystray.Menu.SEPARATOR)
2317+
# note that we don't actually allow no servers when loading the config, so no need to generate a menu
2318+
return items # (avoids creating and then immediately regenerating the menu when servers are loaded)
23202319
else:
23212320
for server_type in ['IMAP', 'POP', 'SMTP']:
23222321
items.extend(App.get_config_menu_servers(self.proxies, server_type))

0 commit comments

Comments
 (0)