improve osx app shutdown

This commit is contained in:
Job Evers-Meltzer 2016-11-03 16:57:29 -05:00
parent 59c4593bf4
commit 3c977f961f
2 changed files with 14 additions and 5 deletions

View file

@ -65,10 +65,14 @@ class LBRYDaemonApp(AppKit.NSApplication):
def openui_(self, sender):
webbrowser.open(settings.UI_ADDRESS)
def replyToApplicationShouldTerminate_(self, shouldTerminate):
log.info('Shutting down')
notify("Goodbye!")
reactor.stop()
# this code is from the example https://pythonhosted.org/pyobjc/examples/Cocoa/Twisted/WebServicesTool/index.html
def applicationShouldTerminate_(self, sender):
if reactor.running:
log.info('Stopping twisted event loop')
notify("Goodbye!")
reactor.stop()
return False
return True
def notify(msg):

View file

@ -18,9 +18,14 @@ def main():
log_file = conf.settings.get_log_filename()
log_support.configure_logging(log_file, console=True)
app = LBRYDaemonApp.sharedApplication()
reactor.addSystemEventTrigger("after", "shutdown", AppHelper.stopEventLoop)
reactor.addSystemEventTrigger("after", "shutdown", shutdown)
reactor.run()
def shutdown():
log.info('Stopping event loop')
AppHelper.stopEventLoop()
if __name__ == "__main__":
main()