-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (52 loc) · 1.53 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
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
from pystray import Icon, Menu, MenuItem
from PIL import Image
from threading import Thread
from notify.wx_notify import WxNotify
from notify.log import logger
class StayBackend:
def __init__(self):
self.icon = None
self.menu = None
self.image = Image.open("assets/notify.png")
def set_menu(self, menu):
self.menu = menu
self.icon = Icon("name", self.image, "WxNotify", self.menu)
def run(self):
self.icon.run()
def stop(self):
self.icon.stop()
def close_stay():
try:
notify.close()
stay_backend.stop()
sys.exit(0)
except Exception as e:
logger.error(e)
sys.exit(1)
def check_mask(icon, item):
if not item.checked:
WxNotify.set_private()
logger.info("已进入隐私模式")
else:
WxNotify.set_public()
logger.info("已退出隐私模式")
def enable_gh(icon, item):
if item.checked:
WxNotify.enable_gh = False
else:
WxNotify.enable_gh = True
if __name__ == '__main__':
stay_backend = StayBackend()
menu = (
Menu.SEPARATOR,
MenuItem('公众号消息', enable_gh, checked=lambda item: WxNotify.enable_gh),
MenuItem('隐私模式', check_mask, checked=lambda item: WxNotify.mask),
MenuItem('退出', close_stay)
)
stay_backend.set_menu(menu)
notify = WxNotify()
backend_stay_thread = Thread(target=stay_backend.run)
backend_stay_thread.start()
notify.start()
logger.debug("启动成功")