Skip to content

Commit ea2fda1

Browse files
committed
Backwards-compatible handling of pywebview's new events namespace
1 parent 6bf3b7e commit ea2fda1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

emailproxy.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__author__ = 'Simon Robinson'
55
__copyright__ = 'Copyright (c) 2021 Simon Robinson'
66
__license__ = 'Apache 2.0'
7-
__version__ = '2022-02-07' # ISO 8601
7+
__version__ = '2022-03-21' # ISO 8601
88

99
import argparse
1010
import asyncore
@@ -31,6 +31,7 @@
3131
import urllib.parse
3232
import urllib.error
3333

34+
import pkg_resources
3435
import pystray
3536
import timeago
3637
import webview
@@ -1084,7 +1085,13 @@ def __init__(self):
10841085
self.load_and_start_servers(self.icon)
10851086
else:
10861087
self.icon = self.create_icon()
1087-
self.icon.run(self.post_create)
1088+
try:
1089+
self.icon.run(self.post_create)
1090+
except NotImplementedError:
1091+
Log.info('Error initialising icon - did you mean to run in --no-gui mode?')
1092+
self.exit(None)
1093+
# noinspection PyProtectedMember
1094+
self.icon._Icon__queue.put(False) # pystray sets up the icon thread even in dummy mode; need to exit
10881095

10891096
# noinspection PyUnresolvedReferences
10901097
def init_platforms(self):
@@ -1273,7 +1280,13 @@ def create_authorisation_window(self, request):
12731280
else:
12741281
authorisation_window = webview.create_window(window_title, request['permission_url'], on_top=True)
12751282
setattr(authorisation_window, 'get_title', AuthorisationWindow.get_title) # add missing get_title method
1276-
authorisation_window.loaded += self.authorisation_window_loaded
1283+
1284+
# pywebview 3.6+ moved window events to a separate namespace in a non-backwards-compatible way
1285+
if pkg_resources.parse_version(
1286+
pkg_resources.get_distribution('pywebview').version) < pkg_resources.parse_version('3.6'):
1287+
authorisation_window.loaded += self.authorisation_window_loaded
1288+
else:
1289+
authorisation_window.events.loaded += self.authorisation_window_loaded
12771290

12781291
def handle_authorisation_windows(self):
12791292
if not sys.platform == 'darwin':
@@ -1544,6 +1557,9 @@ def load_and_start_servers(self, icon=None):
15441557
return True
15451558

15461559
def post_create(self, icon):
1560+
if EXITING:
1561+
return # to handle launch in pystray 'dummy' mode without --no-gui option (partial initialisation failure)
1562+
15471563
icon.visible = True
15481564

15491565
if not self.load_and_start_servers(icon):

0 commit comments

Comments
 (0)