2016-06-20 10:42:06 +02:00
|
|
|
import AppKit
|
|
|
|
import webbrowser
|
|
|
|
import sys
|
2016-07-05 01:53:01 +02:00
|
|
|
import os
|
2016-06-20 10:42:06 +02:00
|
|
|
import logging
|
|
|
|
import platform
|
2016-07-05 01:53:01 +02:00
|
|
|
import shutil
|
|
|
|
from appdirs import user_data_dir
|
2016-06-20 10:42:06 +02:00
|
|
|
from twisted.internet import reactor
|
|
|
|
from twisted.web import server
|
2016-07-05 01:53:01 +02:00
|
|
|
import Foundation
|
|
|
|
bundle = Foundation.NSBundle.mainBundle()
|
|
|
|
lbrycrdd_path = bundle.pathForResource_ofType_('lbrycrdd', None)
|
|
|
|
lbrycrdd_path_conf = os.path.join(os.path.expanduser("~"), ".lbrycrddpath.conf")
|
|
|
|
wallet_dir = user_data_dir("lbrycrd")
|
|
|
|
|
|
|
|
if not os.path.isdir(wallet_dir):
|
|
|
|
shutil.os.mkdir(wallet_dir)
|
|
|
|
|
|
|
|
if not os.path.isfile(lbrycrdd_path_conf):
|
2016-07-05 02:47:43 +02:00
|
|
|
f = open(lbrycrdd_path_conf, "w")
|
2016-07-05 01:53:01 +02:00
|
|
|
f.write(lbrycrdd_path)
|
|
|
|
f.close()
|
|
|
|
|
2016-10-19 06:12:44 +02:00
|
|
|
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
|
|
|
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
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
|
|
|
|
|
|
|
|
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()
|
|
|
|
self.open = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Open", "openui:", "")
|
|
|
|
self.menubarMenu.addItem_(self.open)
|
|
|
|
self.quit = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "replyToApplicationShouldTerminate:", "")
|
|
|
|
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():
|
|
|
|
if platform.mac_ver()[0] >= "10.10":
|
|
|
|
LBRYNotify("Starting LBRY")
|
|
|
|
else:
|
|
|
|
if platform.mac_ver()[0] >= "10.10":
|
|
|
|
LBRYNotify("LBRY needs an internet connection to start, try again when one is available")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2016-10-26 01:36:40 +02:00
|
|
|
DaemonControl.start_server_and_listen(launchui=True, use_auth=False)
|
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
|
|
|
|
|
|
|
def replyToApplicationShouldTerminate_(self, shouldTerminate):
|
|
|
|
if platform.mac_ver()[0] >= "10.10":
|
|
|
|
LBRYNotify("Goodbye!")
|
|
|
|
reactor.stop()
|