Merge pull request #2 from yshtcn/Dev

Dev to main 2023.9.7.2
This commit is contained in:
yshtcn
2023-09-07 20:01:08 +08:00
committed by GitHub
4 changed files with 50 additions and 8 deletions

View File

@@ -18,5 +18,5 @@ proxy_url = socks5://username:password@localhost:1080
# 任务栏托盘标题 # 任务栏托盘标题
title = 系统心跳 title = 系统心跳
# 托盘悬停提示 # 托盘悬停提示
tips = 系统状态报送(首次运行时记得先更新配置) tips = 程序将持续的向设定的目标(首次运行时记得先更新配置)

View File

@@ -13,6 +13,26 @@ import shutil
import subprocess import subprocess
import platform import platform
import winreg import winreg
from plyer import notification
def display_notification(title, message, app_name='YourAppName', timeout=10):
"""
Display a Windows notification.
Parameters:
- title (str): The title of the notification.
- message (str): The message content of the notification.
- app_name (str): The name of the application. Default is 'YourAppName'.
- timeout (int): The time (in seconds) before the notification disappears. Default is 10 seconds.
"""
notification.notify(
title=title,
message=message,
app_name=app_name,
timeout=timeout
)
@@ -146,6 +166,9 @@ title = config.get('Settings', 'title')
tips = config.get('Settings', 'tips') tips = config.get('Settings', 'tips')
# 添加程序到Windows启动 # 添加程序到Windows启动
def add_to_startup(program_name, executable_path): def add_to_startup(program_name, executable_path):
try: try:
@@ -153,8 +176,10 @@ def add_to_startup(program_name, executable_path):
winreg.SetValueEx(key, program_name, 0, winreg.REG_SZ, executable_path) winreg.SetValueEx(key, program_name, 0, winreg.REG_SZ, executable_path)
winreg.CloseKey(key) winreg.CloseKey(key)
logger.info(f"Program added to startup: Program name = {program_name}, Executable path = {executable_path}") logger.info(f"Program added to startup: Program name = {program_name}, Executable path = {executable_path}")
display_notification(f"{program_name}已添加到自启动项", f"启动路径: {executable_path}")
except Exception as e: except Exception as e:
logger.error(f"An error occurred while adding the program to startup: {e}") logger.error(f"An error occurred while adding the program to startup: {e}")
display_notification(f"{program_name}未能添加到自启动项目", f"错误原因: {e}")
# 从Windows启动中移除程序 # 从Windows启动中移除程序
def remove_from_startup(program_name): def remove_from_startup(program_name):
@@ -163,8 +188,10 @@ def remove_from_startup(program_name):
winreg.DeleteValue(key, program_name) winreg.DeleteValue(key, program_name)
winreg.CloseKey(key) winreg.CloseKey(key)
logger.info(f"Program removed from startup: Program name = {program_name}") logger.info(f"Program removed from startup: Program name = {program_name}")
display_notification(f"{program_name}已从自启动项移除", f"{program_name}将不再自动启动")
except Exception as e: except Exception as e:
logger.error(f"An error occurred while removing the program from startup: {e}") logger.error(f"An error occurred while removing the program from startup: {e}")
display_notification(f"{program_name}未能从自启动项移除", f"错误原因: {e}")
# 检查程序是否已在Windows启动中 # 检查程序是否已在Windows启动中
def is_in_startup(program_name): def is_in_startup(program_name):
@@ -183,18 +210,24 @@ def is_packaged():
# 切换Windows启动状态 # 切换Windows启动状态
def toggle_startup(icon, item): def toggle_startup(icon, item):
program_name = "heartbeat" program_name = title
if is_in_startup(program_name): if is_in_startup(program_name):
remove_from_startup(program_name) remove_from_startup(program_name)
else: else:
add_to_startup(program_name, sys.executable) add_to_startup(program_name, sys.executable)
def open_current_dir(text):
os.startfile(current_dir)
# 创建状态栏图标和菜单 # 创建状态栏图标和菜单
menu_items = [item('关闭程序', quit_action)] menu_items = [
item('打开程序目录', open_current_dir),
item('关闭程序', quit_action)
]
# 判断是否以.exe方式运行添加相应菜单项 # 判断是否以.exe方式运行添加相应菜单项
if is_packaged(): if is_packaged():
menu_items.insert(0, item('添加/取消自启动', toggle_startup, checked=lambda text: is_in_startup("heartbeat"))) menu_items.insert(0, item('添加/取消自启动', toggle_startup, checked=lambda text: is_in_startup(title)))
else: else:
menu_items.insert(0, item('Py运行不支持自启动', lambda text: None, enabled=False)) menu_items.insert(0, item('Py运行不支持自启动', lambda text: None, enabled=False))
@@ -213,6 +246,7 @@ if config.get('Settings', 'proxy_enabled', fallback='0') == '1':
'https': config.get('Settings', 'proxy_url')} 'https': config.get('Settings', 'proxy_url')}
# Start the heartbeat function in a new thread # Start the heartbeat function in a new thread
display_notification(f'{title}已启动', f'{tips}')
t = threading.Thread(target=heartbeat, args=(interval, heartbeat_url, session, heartbeat_ping)) t = threading.Thread(target=heartbeat, args=(interval, heartbeat_url, session, heartbeat_ping))
t.start() t.start()

View File

@@ -1,9 +1,13 @@
@echo off @echo off
title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>pyinstaller" title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>pyinstaller"
:: <20><>װ/<2F><><EFBFBD><EFBFBD>pyinstaller(ע<><EFBFBD><E2A3BA>ϣ<EFBFBD><CFA3><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>װ/<2F><><EFBFBD><EFBFBD>pyinstaller<65>ǵ<EFBFBD>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD> :: <20><>װ/<2F><><EFBFBD><EFBFBD>pyinstaller(ע<><EFBFBD><E2A3BA>ϣ<EFBFBD><CFA3><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>װ/<2F><><EFBFBD><EFBFBD>pyinstaller<65>ǵ<EFBFBD>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD>
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
cls
title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>Ŀ<EFBFBD>"
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
cls
:: <20><><EFBFBD>±<EFBFBD><C2B1><EFBFBD> :: <20><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>
title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>" title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>"
@@ -101,7 +105,7 @@ rd /S /Q %~dp0\build\build
:: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
cd /d %~dp0\build cd /d %~dp0\build
pyinstaller --onefile --noconsole --version-file %~dp0\version_info.txt --add-data "%~dp0\config.Exsample.ini;." %~dp0\heartbeat.py pyinstaller --hidden-import=plyer.platforms.win.notification --onefile --noconsole --version-file %~dp0\version_info.txt --add-data "%~dp0\config.Exsample.ini;." %~dp0\heartbeat.py
::<3A><><EFBFBD>±<EFBFBD><C2B1><EFBFBD> ::<3A><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>
title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" title "AutoPyInstaller<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
pystray
Pillow
requests
plyer