forked from CHNZYX/Auto_Simulated_Universe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notif.py
128 lines (113 loc) · 3.41 KB
/
notif.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import ctypes
import time
from PIL import Image
from pystray import Icon, MenuItem as item
import threading
import pygame
import sys
import os
from winotify import Notification
import psutil
def notif(title,msg):
Notification(app_id="椰羊自动化",title=title,msg=msg,icon=os.getcwd() + "\\imgs\\icon.png").show()
def exit_program(icon, item):
icon.stop()
os._exit(0)
def maopao(icon=None, item=None):
file_name = 'logs/notif.txt'
cnt='0'
tm=None
if os.path.exists(file_name):
with open(file_name, 'r', encoding="utf-8",errors='ignore') as file:
s=file.readlines()
cnt=s[0].strip('\n')
try:
tm=s[3].strip('\n')
except:
pass
if tm is None:
tm = str(time.time())
os.makedirs('logs',exist_ok=1)
with open(file_name, 'w', encoding="utf-8") as file:
file.write(f"{cnt}\n喵\n计数:{cnt}\n{tm}")
def clear(icon=None, item=None):
file_name = 'logs/notif.txt'
tm = time.time()
if os.path.exists(file_name):
with open(file_name, 'w', encoding="utf-8",errors='ignore') as file:
file.write('0\n清零\n计数:0\n{tm}')
def notify():
file_name = 'logs/notif.txt'
if not os.path.exists(file_name):
with open(file_name, 'w', encoding="utf-8") as file:
file.write("0")
last = os.path.getmtime(file_name)
while 1:
time.sleep(0.5)
if last != os.path.getmtime(file_name):
with open(file_name,'r', encoding="utf-8",errors='ignore') as fh:
s=fh.readlines()
if len(s)>=3:
notif(s[1].strip('\n'),s[2].strip('\n'))
last = os.path.getmtime(file_name)
running = 0
def genshin():
global running
running = 1
pygame.init()
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.abspath(".")
audio_file = os.path.join(base_path, "start.mp3")
pygame.mixer.music.load(audio_file)
initial_volume = 0.3
pygame.mixer.music.set_volume(initial_volume)
st = 0
while running:
f = 0
for process in psutil.process_iter(['name']):
if process.info['name'] == 'YuanShen.exe':
f = 1
if st == 0 and f == 1:
pygame.mixer.music.play()
st = f
time.sleep(0.1)
def start():
global running
if not running:
t_start = threading.Thread(target=genshin)
t_start.start()
else:
running = 0
def main():
# 检测程序是否已经在运行
mutex = ctypes.windll.kernel32.CreateMutexW(None, False, "YEYANG_MyProgramMutex")
if ctypes.windll.kernel32.GetLastError() == 183:
ctypes.windll.user32.MessageBoxW(0, "程序已在运行!", "提示", 0x40)
return
# 创建系统托盘图标
image = Image.open("imgs/icon.png")
icon = Icon("椰羊自动化", image, "椰羊自动化")
menu = (
item('冒泡', maopao),
item('清零', clear),
item('原神,启动', start),
item('退出', exit_program),
)
icon.menu = menu
maopao()
'''
try:
mynd = list_handles(f=lambda n:"notif" in n[-9:])[0]
win32gui.ShowWindow(mynd, 0)
except:
pass
'''
t_notify = threading.Thread(target=notify)
t_notify.start()
# 显示系统托盘图标
icon.run()
if __name__ == '__main__':
main()