2016-02-19 06:07:19 +01:00
|
|
|
import rumps
|
|
|
|
import xmlrpclib
|
|
|
|
import os
|
2016-02-25 23:17:07 +01:00
|
|
|
import webbrowser
|
2016-02-29 05:49:37 +01:00
|
|
|
import subprocess
|
2016-02-29 19:25:47 +01:00
|
|
|
import argparse
|
2016-02-19 06:07:19 +01:00
|
|
|
|
2016-02-27 23:49:49 +01:00
|
|
|
|
2016-02-19 06:07:19 +01:00
|
|
|
class DaemonStatusBarApp(rumps.App):
|
|
|
|
def __init__(self):
|
2016-03-02 08:00:45 +01:00
|
|
|
icon_path = 'app.icns'
|
2016-02-27 23:49:49 +01:00
|
|
|
if os.path.isfile(icon_path):
|
|
|
|
rumps.App.__init__(self, name="LBRY", icon=icon_path, quit_button=None,
|
|
|
|
menu=["Open", "Preferences", "View balance", "Quit"])
|
|
|
|
else:
|
|
|
|
rumps.App.__init__(self, name="LBRY", title="LBRY", quit_button=None,
|
|
|
|
menu=["Open", "Preferences", "View balance", "Quit"])
|
2016-02-25 23:17:07 +01:00
|
|
|
|
2016-03-03 00:32:48 +01:00
|
|
|
@rumps.timer(1)
|
|
|
|
def alert_daemon_start(self):
|
|
|
|
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
|
|
|
try:
|
|
|
|
start_msg = daemon.is_running()
|
|
|
|
if isinstance(start_msg, str):
|
|
|
|
rumps.notification(title='LBRY', subtitle='', message=str(start_msg), sound=True)
|
|
|
|
update_info = daemon.check_for_new_version()
|
|
|
|
update_msg = ""
|
|
|
|
for p in update_info:
|
|
|
|
if not p[0]:
|
|
|
|
update_msg += p[1] + "\n"
|
|
|
|
if update_msg:
|
|
|
|
update_msg += "\n Try running the installer again to fix this"
|
|
|
|
rumps.notification(title='LBRY', subtitle='', message=update_msg, sound=True)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2016-02-27 23:49:49 +01:00
|
|
|
@rumps.clicked('Open')
|
2016-02-25 23:17:07 +01:00
|
|
|
def get_ui(self):
|
2016-03-03 00:32:48 +01:00
|
|
|
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
2016-02-27 23:49:49 +01:00
|
|
|
try:
|
|
|
|
daemon.is_running()
|
2016-03-08 18:15:49 +01:00
|
|
|
webbrowser.get('safari').open("lbry://lbry")
|
2016-02-27 23:49:49 +01:00
|
|
|
except:
|
|
|
|
try:
|
2016-03-03 00:32:48 +01:00
|
|
|
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
2016-02-27 23:49:49 +01:00
|
|
|
except:
|
|
|
|
rumps.alert(title='LBRY', message="Couldn't connect to lbrynet daemon")
|
|
|
|
|
|
|
|
@rumps.clicked("Preferences")
|
2016-03-03 00:32:48 +01:00
|
|
|
def prefs(self):
|
|
|
|
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
2016-02-27 23:49:49 +01:00
|
|
|
try:
|
|
|
|
daemon.is_running()
|
2016-03-08 18:15:49 +01:00
|
|
|
webbrowser.get('safari').open("lbry://settings")
|
2016-02-27 23:49:49 +01:00
|
|
|
except:
|
2016-03-03 00:32:48 +01:00
|
|
|
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
2016-02-27 23:49:49 +01:00
|
|
|
|
|
|
|
@rumps.clicked("View balance")
|
|
|
|
def disp_balance(self):
|
2016-03-03 00:32:48 +01:00
|
|
|
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
2016-02-27 23:49:49 +01:00
|
|
|
try:
|
|
|
|
balance = daemon.get_balance()
|
2016-03-03 00:32:48 +01:00
|
|
|
r = round(float(balance), 2)
|
2016-02-27 23:49:49 +01:00
|
|
|
try:
|
2016-03-03 00:32:48 +01:00
|
|
|
rumps.notification(title='LBRY', subtitle='', message=str("Your balance is %.2f LBC" % r), sound=False)
|
2016-02-27 23:49:49 +01:00
|
|
|
except:
|
2016-03-03 00:32:48 +01:00
|
|
|
rumps.alert(title='LBRY', message=str("Your balance is %.2f LBC" % r))
|
2016-02-27 23:49:49 +01:00
|
|
|
|
|
|
|
except:
|
|
|
|
try:
|
2016-03-03 00:32:48 +01:00
|
|
|
rumps.notification(title='LBRY', subtitle='', message="Couldn't connect to lbrynet daemon", sound=True)
|
2016-02-27 23:49:49 +01:00
|
|
|
except:
|
|
|
|
rumps.alert(title='LBRY', message="Couldn't connect to lbrynet daemon")
|
2016-02-19 06:07:19 +01:00
|
|
|
|
|
|
|
@rumps.clicked('Quit')
|
|
|
|
def clean_quit(self):
|
2016-03-03 00:32:48 +01:00
|
|
|
daemon = xmlrpclib.ServerProxy("http://localhost:7080/")
|
2016-02-27 23:49:49 +01:00
|
|
|
try:
|
|
|
|
daemon.stop()
|
|
|
|
except:
|
|
|
|
pass
|
2016-02-19 06:07:19 +01:00
|
|
|
rumps.quit_application()
|
|
|
|
|
2016-02-27 23:49:49 +01:00
|
|
|
|
2016-02-25 23:17:07 +01:00
|
|
|
def main():
|
2016-02-29 19:25:47 +01:00
|
|
|
parser = argparse.ArgumentParser(description="Launch lbrynet status bar application")
|
|
|
|
parser.add_argument("--startdaemon",
|
|
|
|
help="true or false, default true",
|
|
|
|
type=str,
|
|
|
|
default="true")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-02-29 21:04:20 +01:00
|
|
|
if str(args.startdaemon).lower() == "true":
|
2016-03-03 00:32:48 +01:00
|
|
|
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
|
|
|
|
try:
|
|
|
|
daemon.is_running()
|
|
|
|
except:
|
|
|
|
subprocess.Popen("screen -dmS lbrynet bash -c "
|
|
|
|
"'PYTHONPATH=$PYTHONPATH:`cat /Users/${USER}/Library/Application\ Support/lbrynet/.python_path`; "
|
|
|
|
"PATH=$PATH:`cat /Users/${USER}/Library/Application\ Support/lbrynet/.lbry_bin_path`; "
|
|
|
|
"lbrynet-daemon --update=False'", shell=True)
|
2016-02-29 19:25:47 +01:00
|
|
|
|
2016-02-27 23:49:49 +01:00
|
|
|
status_app = DaemonStatusBarApp()
|
|
|
|
status_app.run()
|
|
|
|
|
2016-02-25 23:17:07 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|