Skip to content

Commit 3f407ba

Browse files
committed
修复和优化
- 优化 **安全验证逻辑**,统一使用项目验证系统 - 优化 **软件退出**,解决退出缓慢问题 - 优化 **URL 注册**,无需管理员权限即可完成 - 优化 **TEMP 清理**,仅清理 TEMP 文件夹 - 优化 **日志记录**,描述错误问题 - 修复 **URL命令解析**,修复命令匹配错误 - 修复 **重启功能**,解决无法重启异常 - 修复 **URL 注册**,修复注册失败问题 - 移除 **URL 中的通用命令**,简化命令处理
1 parent 44e5acf commit 3f407ba

10 files changed

Lines changed: 207 additions & 214 deletions

File tree

CHANGELOG/v2.2.0/CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ v2.0 - Koharu(小鸟游星野) release 3
77

88
## 💡 功能优化
99

10-
-
10+
- 优化 **安全验证逻辑**,统一使用项目验证系统
11+
- 优化 **软件退出**,解决退出缓慢问题
12+
- 优化 **URL 注册**,无需管理员权限即可完成
13+
- 优化 **TEMP 清理**,仅清理 TEMP 文件夹
14+
- 优化 **日志记录**,描述错误问题
1115

1216
## 🐛 修复问题
1317

14-
-
18+
- 修复 **URL命令解析**,修复命令匹配错误
19+
- 修复 **重启功能**,解决无法重启异常
20+
- 修复 **URL 注册**,修复注册失败问题
1521

1622
## 🔧 其它变更
1723

18-
-
24+
- 移除 **URL 中的通用命令**,简化命令处理
1925

2026
---
2127

app/Language/modules/basic_settings.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
"url_protocol_notification": {
6969
"enable": "已开启URL协议注册",
7070
"disable": "已关闭URL协议注册",
71-
"register_failure": "URL协议注册失败,需要管理员权限",
72-
"unregister_failure": "URL协议注销失败,可能需要管理员权限",
73-
"permission_error": "权限不足,URL协议注册/注销失败",
71+
"register_failure": "URL协议注册失败",
72+
"unregister_failure": "URL协议注销失败",
73+
"error": "URL协议设置错误: {error}",
7474
},
7575
"export_diagnostic_data": {
7676
"name": "导出诊断数据",
@@ -291,6 +291,14 @@
291291
"url_protocol": {
292292
"name": "URL protocol register",
293293
"description": "Sign up for custom URL protocol (secrandom://), support to launch app via link",
294+
"switchbutton_name": {"enable": "", "disable": ""},
295+
},
296+
"url_protocol_notification": {
297+
"enable": "URL protocol registration enabled",
298+
"disable": "URL protocol registration disabled",
299+
"register_failure": "Failed to register URL protocol",
300+
"unregister_failure": "Failed to unregister URL protocol",
301+
"error": "URL protocol setting error: {error}",
294302
},
295303
"ipc_port": {
296304
"name": "IPC port setting",

app/common/IPC_URL/csharp_ipc_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def get_on_class_left_time(self) -> int:
171171
should_log = True
172172
self._last_on_class_left_log_time = current_time
173173

174-
if should_log:
174+
if should_log and total_seconds != 0:
175175
logger.debug(f"获取到的距离上课剩余时间: {total_seconds} 秒")
176176

177177
return total_seconds

app/common/IPC_URL/protocol_manager.py

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,13 @@ def is_protocol_registered(self) -> bool:
7272
return False
7373

7474
def _register_windows_protocol(self) -> bool:
75-
"""Windows系统注册协议"""
75+
"""Windows系统注册协议(单用户模式,无需管理员权限)"""
7676
try:
7777
# 获取当前可执行文件路径
7878
exe_path = self._get_executable_path()
7979

80-
# 首先尝试注册到HKEY_CLASSES_ROOT
81-
try:
82-
# 注册协议到HKEY_CLASSES_ROOT
83-
with winreg.CreateKey(
84-
winreg.HKEY_CLASSES_ROOT, self.protocol_name
85-
) as key:
86-
winreg.SetValueEx(
87-
key, "", 0, winreg.REG_SZ, f"URL:{self.app_name} Protocol"
88-
)
89-
winreg.SetValueEx(key, "URL Protocol", 0, winreg.REG_SZ, "")
90-
91-
# 注册命令
92-
command_key_path = f"{self.protocol_name}\\shell\\open\\command"
93-
with winreg.CreateKey(
94-
winreg.HKEY_CLASSES_ROOT, command_key_path
95-
) as key:
96-
winreg.SetValueEx(
97-
key, "", 0, winreg.REG_SZ, f'"{exe_path}" --url "%1"'
98-
)
99-
100-
return True
101-
102-
except (OSError, PermissionError) as e:
103-
# 如果HKEY_CLASSES_ROOT失败,尝试注册到HKEY_CURRENT_USER
104-
if e.errno == 5 or "Access is denied" in str(e): # WinError 5
105-
logger.error(f"管理员权限不足,尝试注册到当前用户: {e}")
106-
return self._register_windows_protocol_current_user(exe_path)
107-
else:
108-
raise
80+
# 直接注册到HKEY_CURRENT_USER(单用户模式,无需管理员权限)
81+
return self._register_windows_protocol_current_user(exe_path)
10982

11083
except Exception as e:
11184
logger.error(f"Windows协议注册失败: {e}")
@@ -136,28 +109,10 @@ def _register_windows_protocol_current_user(self, exe_path: str) -> bool:
136109
return False
137110

138111
def _unregister_windows_protocol(self) -> bool:
139-
"""Windows系统注销协议"""
112+
"""Windows系统注销协议(单用户模式,无需管理员权限)"""
140113
try:
141-
# 首先尝试删除系统级注册(HKEY_CLASSES_ROOT)
142-
try:
143-
winreg.DeleteKey(
144-
winreg.HKEY_CLASSES_ROOT,
145-
f"{self.protocol_name}\\shell\\open\\command",
146-
)
147-
winreg.DeleteKey(
148-
winreg.HKEY_CLASSES_ROOT, f"{self.protocol_name}\\shell\\open"
149-
)
150-
winreg.DeleteKey(
151-
winreg.HKEY_CLASSES_ROOT, f"{self.protocol_name}\\shell"
152-
)
153-
winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, self.protocol_name)
154-
return True
155-
except (OSError, PermissionError) as e:
156-
if e.errno == 5 or "Access is denied" in str(e): # WinError 5
157-
# 如果系统级删除失败,尝试删除当前用户注册
158-
return self._unregister_windows_protocol_current_user()
159-
else:
160-
raise
114+
# 直接删除当前用户注册表项(单用户模式,无需管理员权限)
115+
return self._unregister_windows_protocol_current_user()
161116

162117
except Exception as e:
163118
logger.error(f"Windows协议注销失败: {e}")
@@ -187,19 +142,14 @@ def _unregister_windows_protocol_current_user(self) -> bool:
187142
return False
188143

189144
def _is_windows_protocol_registered(self) -> bool:
190-
"""检查Windows协议是否已注册"""
145+
"""检查Windows协议是否已注册(单用户模式)"""
191146
try:
192-
# 首先检查HKEY_CLASSES_ROOT(系统级)
193-
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, self.protocol_name) as key:
147+
# 检查HKEY_CURRENT_USER(用户级)
148+
key_path = f"Software\\Classes\\{self.protocol_name}"
149+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path) as key:
194150
return True
195151
except (OSError, FileNotFoundError):
196-
try:
197-
# 如果没找到,检查HKEY_CURRENT_USER(用户级)
198-
key_path = f"Software\\Classes\\{self.protocol_name}"
199-
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path) as key:
200-
return True
201-
except (OSError, FileNotFoundError):
202-
return False
152+
return False
203153

204154
def _register_linux_protocol(self) -> bool:
205155
"""Linux系统注册协议"""

0 commit comments

Comments
 (0)