forked from LBRYCommunity/lbry-sdk
Make systray thread a daemon to close on api.stop()
This commit is contained in:
parent
0b149ce5f1
commit
6097e14617
1 changed files with 12 additions and 4 deletions
|
@ -5,7 +5,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor, error
|
||||||
from twisted.web import server
|
from twisted.web import server
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
|
@ -235,20 +235,26 @@ class SysTrayIcon(object):
|
||||||
def execute_menu_option(self, id):
|
def execute_menu_option(self, id):
|
||||||
menu_action = self.menu_actions_by_id[id]
|
menu_action = self.menu_actions_by_id[id]
|
||||||
if menu_action == self.QUIT:
|
if menu_action == self.QUIT:
|
||||||
win32gui.DestroyWindow(self.hwnd)
|
self.exit_app()
|
||||||
else:
|
else:
|
||||||
menu_action(self)
|
menu_action(self)
|
||||||
|
|
||||||
|
def exit_app(self):
|
||||||
|
win32gui.DestroyWindow(self.hwnd)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
def LBRYApp():
|
def LBRYApp():
|
||||||
SysTrayIcon(icon, hover_text, menu_options, on_quit=stop)
|
return SysTrayIcon(icon, hover_text, menu_options, on_quit=stop)
|
||||||
|
|
||||||
def openui_(sender):
|
def openui_(sender):
|
||||||
webbrowser.open(UI_ADDRESS)
|
webbrowser.open(UI_ADDRESS)
|
||||||
|
|
||||||
def replyToApplicationShouldTerminate_():
|
def replyToApplicationShouldTerminate_():
|
||||||
|
try:
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
except error.ReactorNotRunning:
|
||||||
|
log.debug('Reactor already stopped')
|
||||||
|
|
||||||
def stop(sysTrayIcon):
|
def stop(sysTrayIcon):
|
||||||
replyToApplicationShouldTerminate_()
|
replyToApplicationShouldTerminate_()
|
||||||
|
@ -257,6 +263,7 @@ def main():
|
||||||
icon = os.path.join(os.path.dirname(sys.executable), ICON_PATH, 'lbry16.ico')
|
icon = os.path.join(os.path.dirname(sys.executable), ICON_PATH, 'lbry16.ico')
|
||||||
else:
|
else:
|
||||||
icon = os.path.join(ICON_PATH, 'lbry16.ico')
|
icon = os.path.join(ICON_PATH, 'lbry16.ico')
|
||||||
|
|
||||||
hover_text = APP_NAME
|
hover_text = APP_NAME
|
||||||
menu_options = (('Open', icon, openui_),)
|
menu_options = (('Open', icon, openui_),)
|
||||||
|
|
||||||
|
@ -265,6 +272,7 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
systray_thread = threading.Thread(target=LBRYApp)
|
systray_thread = threading.Thread(target=LBRYApp)
|
||||||
|
systray_thread.daemon = True
|
||||||
systray_thread.start()
|
systray_thread.start()
|
||||||
|
|
||||||
lbry = LBRYDaemonServer()
|
lbry = LBRYDaemonServer()
|
||||||
|
|
Loading…
Reference in a new issue