From f50f815ea059f5061943d4182e51b611ce861fe8 Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Tue, 11 Feb 2025 18:24:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=AC=E6=B3=89cursor=E5=8A=A9?= =?UTF-8?q?=E6=89=8Bv2.0.5=E7=89=88=E6=9C=AC=20-=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=B5=81=E7=A8=8B=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E5=BC=B9=E7=AA=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interactive/account_switcher.py | 13 ++++++++++--- interactive/main.py | 24 ++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/interactive/account_switcher.py b/interactive/account_switcher.py index bd1d8d5..d81453a 100644 --- a/interactive/account_switcher.py +++ b/interactive/account_switcher.py @@ -16,16 +16,23 @@ from cursor_auth_manager import CursorAuthManager def get_hardware_id() -> str: """获取硬件唯一标识""" try: + # 创建startupinfo对象来隐藏命令行窗口 + startupinfo = None + if sys.platform == "win32": + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + startupinfo.wShowWindow = subprocess.SW_HIDE + # 获取CPU信息 - cpu_info = subprocess.check_output('wmic cpu get ProcessorId').decode() + cpu_info = subprocess.check_output('wmic cpu get ProcessorId', startupinfo=startupinfo).decode() cpu_id = cpu_info.split('\n')[1].strip() # 获取主板序列号 - board_info = subprocess.check_output('wmic baseboard get SerialNumber').decode() + board_info = subprocess.check_output('wmic baseboard get SerialNumber', startupinfo=startupinfo).decode() board_id = board_info.split('\n')[1].strip() # 获取BIOS序列号 - bios_info = subprocess.check_output('wmic bios get SerialNumber').decode() + bios_info = subprocess.check_output('wmic bios get SerialNumber', startupinfo=startupinfo).decode() bios_id = bios_info.split('\n')[1].strip() # 组合信息并生成哈希 diff --git a/interactive/main.py b/interactive/main.py index ca8a279..5c6befb 100644 --- a/interactive/main.py +++ b/interactive/main.py @@ -12,24 +12,21 @@ def setup_logging(): log_file = log_dir / "switcher.log" - # 同时输出到文件和控制台 - handlers = [logging.FileHandler(log_file, encoding="utf-8")] - if sys.stdout is not None: - handlers.append(logging.StreamHandler(sys.stdout)) - + # 只输出到文件,不输出到控制台 logging.basicConfig( - level=logging.INFO, # 使用INFO级别以显示更多信息 + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s", - handlers=handlers + handlers=[ + logging.FileHandler(log_file, encoding="utf-8"), + ] ) - logging.info("日志系统初始化成功") except Exception as e: - print(f"设置日志系统失败: {str(e)}") + # 不打印错误信息,只记录到日志 + pass def main(): """主函数""" try: - print("正在启动程序...") setup_logging() # 检查Python版本 @@ -52,10 +49,9 @@ def main(): except Exception as e: error_msg = f"程序运行出错: {str(e)}\n{traceback.format_exc()}" logging.error(error_msg) - print(error_msg) # 直接打印错误信息 - - # 保持窗口不关闭 - input("按回车键退出...") + # 使用tkinter的消息框显示错误 + from tkinter import messagebox + messagebox.showerror("错误", error_msg) if __name__ == "__main__": main() \ No newline at end of file