2016-06-20 10:42:06 +02:00
|
|
|
import AppKit
|
|
|
|
import webbrowser
|
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
import platform
|
|
|
|
from twisted.internet import reactor
|
2016-07-05 01:53:01 +02:00
|
|
|
|
2016-10-29 00:55:34 +02:00
|
|
|
from lbrynet.lbrynet_daemon import DaemonControl
|
2016-11-10 21:49:51 +01:00
|
|
|
from lbrynet import analytics
|
2016-10-27 21:57:02 +02:00
|
|
|
from lbrynet.conf import settings
|
2016-10-18 03:00:24 +02:00
|
|
|
from lbrynet.core import utils
|
|
|
|
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
if platform.mac_ver()[0] >= "10.10":
|
|
|
|
from LBRYNotify import LBRYNotify
|
|
|
|
|
2016-11-03 20:22:16 +01:00
|
|
|
|
2016-06-20 10:42:06 +02:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def test_internet_connection():
|
2016-10-18 03:00:24 +02:00
|
|
|
return utils.check_connection()
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LBRYDaemonApp(AppKit.NSApplication):
|
|
|
|
def finishLaunching(self):
|
|
|
|
self.connection = False
|
|
|
|
statusbar = AppKit.NSStatusBar.systemStatusBar()
|
|
|
|
self.statusitem = statusbar.statusItemWithLength_(AppKit.NSVariableStatusItemLength)
|
2016-10-19 06:12:44 +02:00
|
|
|
self.icon = AppKit.NSImage.alloc().initByReferencingFile_(settings.ICON_PATH)
|
2016-06-20 10:42:06 +02:00
|
|
|
self.icon.setScalesWhenResized_(True)
|
|
|
|
self.icon.setSize_((20, 20))
|
|
|
|
self.statusitem.setImage_(self.icon)
|
|
|
|
self.menubarMenu = AppKit.NSMenu.alloc().init()
|
2016-11-03 22:57:42 +01:00
|
|
|
self.open = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
|
|
|
|
"Open", "openui:", "")
|
2016-06-20 10:42:06 +02:00
|
|
|
self.menubarMenu.addItem_(self.open)
|
2016-11-03 22:57:42 +01:00
|
|
|
self.quit = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
|
|
|
|
"Quit", "applicationShouldTerminate:", "")
|
2016-06-20 10:42:06 +02:00
|
|
|
self.menubarMenu.addItem_(self.quit)
|
|
|
|
self.statusitem.setMenu_(self.menubarMenu)
|
2016-10-19 06:12:44 +02:00
|
|
|
self.statusitem.setToolTip_(settings.APP_NAME)
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
if test_internet_connection():
|
2016-10-31 22:19:19 +01:00
|
|
|
notify("Starting LBRY")
|
2016-06-20 10:42:06 +02:00
|
|
|
else:
|
2016-10-31 22:19:19 +01:00
|
|
|
notify("LBRY needs an internet connection to start, try again when one is available")
|
2016-06-20 10:42:06 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
2016-11-10 21:49:51 +01:00
|
|
|
DaemonControl.start_server_and_listen(
|
|
|
|
launchui=True, use_auth=False,
|
|
|
|
analytics_manager=analytics.Manager.new_instance()
|
|
|
|
)
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
def openui_(self, sender):
|
2016-10-19 06:12:44 +02:00
|
|
|
webbrowser.open(settings.UI_ADDRESS)
|
2016-06-20 10:42:06 +02:00
|
|
|
|
2016-12-01 00:05:01 +01:00
|
|
|
# this code is from the example
|
|
|
|
# https://pythonhosted.org/pyobjc/examples/Cocoa/Twisted/WebServicesTool/index.html
|
2016-11-03 22:57:29 +01:00
|
|
|
def applicationShouldTerminate_(self, sender):
|
|
|
|
if reactor.running:
|
|
|
|
log.info('Stopping twisted event loop')
|
|
|
|
notify("Goodbye!")
|
|
|
|
reactor.stop()
|
|
|
|
return False
|
|
|
|
return True
|
2016-10-31 22:19:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def notify(msg):
|
|
|
|
if platform.mac_ver()[0] >= "10.10":
|
|
|
|
LBRYNotify(msg)
|