lbry-sdk/lbrynet/lbrynet_daemon/LBRYOSXStatusBar.py

90 lines
3.2 KiB
Python
Raw Normal View History

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-02-29 19:25:47 +01:00
#detect if being run as root, if so find the correct icon path
if os.path.expanduser("~") != '/var/root':
icon_path = os.path.join(os.path.expanduser("~"), "Downloads/lbryio/web/img/fav/apple-touch-icon.png")
else:
icon_path = os.path.join("/Users",
subprocess.check_output('echo $SUDO_USER', shell=True)[:-1],
"Downloads/lbryio/web/img/fav/apple-touch-icon.png")
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-02-27 23:49:49 +01:00
@rumps.clicked('Open')
2016-02-25 23:17:07 +01:00
def get_ui(self):
2016-02-27 23:49:49 +01:00
try:
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
daemon.is_running()
webbrowser.open("lbry://lbry")
except:
try:
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
except:
rumps.alert(title='LBRY', message="Couldn't connect to lbrynet daemon")
@rumps.clicked("Preferences")
def prefs(self, _):
try:
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
daemon.is_running()
webbrowser.open("lbry://settings")
except:
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
@rumps.clicked("View balance")
def disp_balance(self):
daemon = xmlrpclib.ServerProxy('http://localhost:7080')
try:
balance = daemon.get_balance()
try:
rumps.notification(title='LBRY', subtitle='status', message="Your balance is " + str(balance), sound=False)
except:
rumps.alert(title='LBRY', message="Your balance is " + str(balance))
except:
try:
rumps.notification(title='LBRY', subtitle='status', message="Couldn't connect to lbrynet daemon", sound=True)
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-02-25 23:17:07 +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()
if str(args.startdaemon).lower() == "true":
2016-02-29 19:25:47 +01:00
subprocess.Popen("screen -dmS lbrynet bash -c 'lbrynet-daemon'", shell=True)
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()