This commit is contained in:
super
2026-04-10 19:35:08 +08:00
13 changed files with 2125 additions and 245 deletions

View File

@@ -73,20 +73,26 @@ class WindowAPI:
window.events.restored += lambda _: setattr(self, '_is_maximized', False)
def close(self):
"""关闭窗口,异步执行清理逻辑"""
def cleanup_and_exit():
"""后台清理线程"""
try:
kill_process('v6')
except Exception as e:
print(f"【退出前】关闭紫鸟浏览器进程异常: {str(e)}")
finally:
time.sleep(0.5)
os._exit(0)
# 先销毁窗口,让用户看到立即响应
try:
self._window.destroy()
except:
pass
return
try:
kill_process('v6')
except Exception as e:
print(f"【退出前】关闭紫鸟浏览器进程异常: {str(e)}")
try:
self._window.destroy()
except:
pass
os._exit(0) # 强制退出整个进程,包括所有线程
# 在后台线程执行清理,不阻塞
cleanup_thread = threading.Thread(target=cleanup_and_exit, daemon=True)
cleanup_thread.start()
def minimize(self):
self._window.minimize()
@@ -390,21 +396,24 @@ def start_task_monitor():
def on_window_closing():
return
"""窗口关闭事件处理器,执行与 close() 方法相同的清理逻辑"""
# 先关闭窗口,避免看起来卡着
try:
if webview.windows:
webview.windows[0].destroy()
except:
pass
"""窗口关闭事件处理器异步执行清理逻辑避免阻塞UI"""
def cleanup_and_exit():
"""后台清理线程"""
try:
kill_process('v6')
except Exception as e:
print(f"【退出前】关闭紫鸟浏览器进程异常: {str(e)}")
finally:
# 给一点时间让清理完成,然后强制退出
time.sleep(0.5)
os._exit(0)
# 然后执行清理逻辑
try:
kill_process('v6')
except Exception as e:
print(f"【退出前】关闭紫鸟浏览器进程异常: {str(e)}")
os._exit(0) # 强制退出整个进程,包括所有线程
# 立即在后台线程执行清理,不阻塞窗口关闭
cleanup_thread = threading.Thread(target=cleanup_and_exit, daemon=True)
cleanup_thread.start()
# 立即返回,让窗口快速关闭,用户不会感觉卡顿
return True
def main():