feat: add root directory files and interactive module - Add account manager, test files, and interactive GUI module; Update requirements.txt

This commit is contained in:
huangzhenpc
2025-02-11 16:10:18 +08:00
parent d82928785d
commit e18297c3c0
12 changed files with 276 additions and 3 deletions

BIN
interactive/icon/th (1).jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
interactive/icon/th (2).jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
interactive/icon/th.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
interactive/icon/two.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

37
interactive/main.py Normal file
View File

@@ -0,0 +1,37 @@
import logging
from pathlib import Path
from gui.main_window import MainWindow
def setup_logging():
"""设置日志"""
log_dir = Path.home() / ".cursor_switcher" / "logs"
log_dir.mkdir(parents=True, exist_ok=True)
log_file = log_dir / "switcher.log"
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[
logging.FileHandler(log_file, encoding="utf-8"),
logging.StreamHandler()
]
)
logging.info("日志系统初始化完成")
def main():
"""主函数"""
try:
setup_logging()
logging.info("启动GUI界面...")
window = MainWindow()
window.run()
except KeyboardInterrupt:
logging.info("程序被用户中断")
except Exception as e:
logging.error(f"程序运行出错: {str(e)}")
finally:
logging.info("程序退出")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,2 @@
requests==2.31.0
pyinstaller==6.3.0

View File

@@ -0,0 +1,67 @@
import os
import json
import logging
from pathlib import Path
class Config:
def __init__(self):
self.api_base_url = "https://cursorapi.nosqli.com/admin"
self.config_dir = Path(os.path.expanduser("~")) / ".cursor_switcher"
self.config_file = self.config_dir / "config.json"
self.member_file = self.config_dir / "member.json"
self.load_config()
def load_config(self):
"""加载配置"""
try:
self.config_dir.mkdir(parents=True, exist_ok=True)
if not self.config_file.exists():
self.save_default_config()
with open(self.config_file, "r", encoding="utf-8") as f:
config = json.load(f)
self.api_token = config.get("api_token", "")
except Exception as e:
logging.error(f"加载配置失败: {str(e)}")
self.api_token = ""
def save_member_info(self, info: dict):
"""保存会员信息"""
try:
with open(self.member_file, "w", encoding="utf-8") as f:
json.dump(info, f, indent=2, ensure_ascii=False)
except Exception as e:
logging.error(f"保存会员信息失败: {str(e)}")
def load_member_info(self) -> dict:
"""读取会员信息"""
try:
if self.member_file.exists():
with open(self.member_file, "r", encoding="utf-8") as f:
return json.load(f)
except Exception as e:
logging.error(f"读取会员信息失败: {str(e)}")
return {
"expire_time": "",
"days": 0,
"new_days": 0
}
def save_default_config(self):
"""保存默认配置"""
config = {
"api_token": ""
}
with open(self.config_file, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
def save_config(self, api_token: str):
"""保存新的配置"""
config = {
"api_token": api_token
}
with open(self.config_file, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
self.api_token = api_token