This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
57 lines (44 loc) · 1.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pystray
import os
from PIL import Image
from sys import platform
from app import app_main
from threading import Thread
def normal_main():
def sudo_execute(cmd):
if platform == "darwin":
pass
# script_text = 'do shell script "{}" with administrator privileges'.format(cmd)
# os.spawnlp(os.P_NOWAIT, 'osascript', 'osascript', '-e', script_text)
else:
os.spawnlp(os.P_NOWAIT, 'pkexec', 'pkexec', cmd)
def setup(ico):
ico.visible = True
def shutdown(ico):
ico.stop()
def show(_ico):
if platform == "darwin":
os.spawnlp(os.P_NOWAIT, 'open', 'open', 'http://localhost:5000/')
else:
os.spawnlp(os.P_NOWAIT, 'xdg-open', 'xdg-open', 'http://localhost:5000/')
def nfd_start(_ico):
sudo_execute('nfd-start')
def nfd_stop(_ico):
sudo_execute('nfd-stop')
menu = pystray.Menu(
pystray.MenuItem('Show', show),
pystray.Menu.SEPARATOR,
pystray.MenuItem('NFD Start', nfd_start),
pystray.MenuItem('NFD Stop', nfd_stop),
pystray.Menu.SEPARATOR,
pystray.MenuItem('Exit', shutdown),
)
icon = pystray.Icon('ndncc', menu=menu)
img = Image.open('ndn_app.png')
icon.icon = img
app_thread = Thread(target=app_main)
app_thread.daemon = True
app_thread.start()
icon.run(setup)
if __name__ == '__main__':
normal_main()