feat: 发布 v3.5.0 版本
This commit is contained in:
29
main.py
29
main.py
@@ -7,6 +7,9 @@ import shutil
|
||||
import tempfile
|
||||
import urllib3
|
||||
import ctypes
|
||||
import win32event
|
||||
import win32api
|
||||
import winerror
|
||||
from pathlib import Path
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox, QSystemTrayIcon, QMenu
|
||||
from PyQt5.QtGui import QIcon
|
||||
@@ -18,6 +21,28 @@ from account_switcher import AccountSwitcher
|
||||
urllib3.disable_warnings()
|
||||
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
||||
|
||||
def prevent_multiple_instances():
|
||||
"""防止程序多开
|
||||
|
||||
Returns:
|
||||
bool: 如果是第一个实例返回True,否则返回False
|
||||
"""
|
||||
try:
|
||||
# 创建一个唯一的互斥锁名称
|
||||
mutex_name = "Global\\CursorHelper_SingleInstance_Lock"
|
||||
|
||||
# 尝试创建互斥锁
|
||||
handle = win32event.CreateMutex(None, 1, mutex_name)
|
||||
if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
|
||||
# 互斥锁已存在,说明程序已经在运行
|
||||
logging.warning("程序已经在运行")
|
||||
QMessageBox.warning(None, "警告", "程序已经在运行!\n请不要重复打开程序。")
|
||||
return False
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error(f"检查程序实例失败: {str(e)}")
|
||||
return True # 如果检查失败,允许程序运行
|
||||
|
||||
def cleanup_temp():
|
||||
"""清理临时文件"""
|
||||
try:
|
||||
@@ -93,6 +118,10 @@ def print_banner():
|
||||
def main():
|
||||
"""主函数"""
|
||||
try:
|
||||
# 0. 检查是否已有实例在运行
|
||||
if not prevent_multiple_instances():
|
||||
return 1
|
||||
|
||||
# 1. 首先检查管理员权限
|
||||
if not is_admin():
|
||||
if run_as_admin():
|
||||
|
||||
Reference in New Issue
Block a user