Ver Fonte

Refactor cursor_pro_keep_alive.py and remove obsolete files

- Updated environment variable assignments to use double quotes for consistency.
- Enhanced logging configuration format for clarity.
- Improved configuration loading logic to correctly determine the executable's directory.
- Cleaned up temporary file handling in cleanup_temp_files function.
- Removed obsolete config.ini and related files from the dist directory.
- Deleted unnecessary macOS application files from the dist folder.
cheng zhen há 1 ano atrás
pai
commit
b3c9efc901

+ 0 - 1
CursorKeepAlive.mac.spec

@@ -5,7 +5,6 @@ a = Analysis(
     pathex=[],
     binaries=[],
     datas=[
-        ('config.ini', '.'),
         ('turnstilePatch', 'turnstilePatch'),
         ('cursor_auth_manager.py', '.'),
     ],

+ 27 - 21
cursor_pro_keep_alive.py

@@ -1,6 +1,7 @@
 import os
-os.environ['PYTHONVERBOSE'] = '0'
-os.environ['PYINSTALLER_VERBOSE'] = '0'
+
+os.environ["PYTHONVERBOSE"] = "0"
+os.environ["PYINSTALLER_VERBOSE"] = "0"
 
 from DrissionPage import ChromiumOptions, Chromium
 from DrissionPage.common import Keys
@@ -16,11 +17,11 @@ import logging
 # 在文件开头设置日志
 logging.basicConfig(
     level=logging.WARNING,
-    format='%(asctime)s - %(levelname)s - %(message)s',
+    format="%(asctime)s - %(levelname)s - %(message)s",
     handlers=[
         logging.StreamHandler(),
-        logging.FileHandler('cursor_keep_alive.log', encoding='utf-8')
-    ]
+        logging.FileHandler("cursor_keep_alive.log", encoding="utf-8"),
+    ],
 )
 
 
@@ -28,19 +29,20 @@ def load_config():
     """加载配置文件"""
     config = ConfigParser()
 
-    # 修改获取配置文件路径的方式
-    if getattr(sys, 'frozen', False):
-        # 如果是打包后的执行文件
-        root_dir = sys._MEIPASS
+    # 获取程序运行的实际目录
+    if getattr(sys, "frozen", False):
+        # 打包后的情况:使用可执行文件所在目录
+        root_dir = os.path.dirname(sys.executable)
     else:
-        # 如果是直接运行 Python 脚本
+        # 开发环境:使用当前工作目录
         root_dir = os.getcwd()
-        
+
     config_path = os.path.join(root_dir, "config.ini")
 
     if os.path.exists(config_path):
         config.read(config_path, encoding="utf-8")
         print(f"已加载配置文件: {config_path}")
+        print(config["Account"]["email"])
         return {
             "account": config["Account"]["email"],
             "password": config["Account"]["password"],
@@ -401,18 +403,20 @@ def get_browser_options():
         co.add_extension(extension_path)
     except FileNotFoundError as e:
         print(f"警告: {e}")
-        
+
     co.headless()
-    co.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.92 Safari/537.36")
+    co.set_user_agent(
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.92 Safari/537.36"
+    )
     co.set_pref("credentials_enable_service", False)
     co.set_argument("--hide-crash-restore-bubble")
     co.auto_port()
-    
+
     # Mac 系统特殊处理
-    if sys.platform == 'darwin':
-        co.set_argument('--no-sandbox')
-        co.set_argument('--disable-gpu')
-    
+    if sys.platform == "darwin":
+        co.set_argument("--no-sandbox")
+        co.set_argument("--disable-gpu")
+
     return co
 
 
@@ -420,13 +424,14 @@ def cleanup_temp_files():
     """清理临时文件和缓存"""
     try:
         temp_dirs = [
-            os.path.join(os.getcwd(), '__pycache__'),
-            os.path.join(os.getcwd(), 'build'),
+            os.path.join(os.getcwd(), "__pycache__"),
+            os.path.join(os.getcwd(), "build"),
         ]
-        
+
         for dir_path in temp_dirs:
             if os.path.exists(dir_path):
                 import shutil
+
                 shutil.rmtree(dir_path)
     except Exception as e:
         logging.warning(f"清理临时文件失败: {str(e)}")
@@ -485,6 +490,7 @@ if __name__ == "__main__":
     except Exception as e:
         print(f"程序执行出错: {str(e)}")
         import traceback
+
         print(traceback.format_exc())
     finally:
         # 确保浏览器实例被正确关闭

BIN
dist/CursorPro


+ 0 - 28
dist/CursorPro.app/Contents/Info.plist

@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDisplayName</key>
-	<string>CursorPro</string>
-	<key>CFBundleExecutable</key>
-	<string>CursorPro</string>
-	<key>CFBundleIconFile</key>
-	<string>icon-windowed.icns</string>
-	<key>CFBundleIdentifier</key>
-	<string>com.yourcompany.cursorpro</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleName</key>
-	<string>CursorPro</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleShortVersionString</key>
-	<string>1.0.0</string>
-	<key>CFBundleVersion</key>
-	<string>1.0.0</string>
-	<key>LSBackgroundOnly</key>
-	<false/>
-	<key>NSHighResolutionCapable</key>
-	<true/>
-</dict>
-</plist>

BIN
dist/CursorPro.app/Contents/MacOS/CursorPro


BIN
dist/CursorPro.app/Contents/Resources/icon-windowed.icns


+ 0 - 128
dist/CursorPro.app/Contents/_CodeSignature/CodeResources

@@ -1,128 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>files</key>
-	<dict>
-		<key>Resources/icon-windowed.icns</key>
-		<data>
-		eEHOuYpZLB0vKGVIWGZOh5rH8+o=
-		</data>
-	</dict>
-	<key>files2</key>
-	<dict>
-		<key>Resources/icon-windowed.icns</key>
-		<dict>
-			<key>hash2</key>
-			<data>
-			uQo7VuWRab4Phv4EEGmfQsyqFqDIXZgO8OtgaAMvCzY=
-			</data>
-		</dict>
-	</dict>
-	<key>rules</key>
-	<dict>
-		<key>^Resources/</key>
-		<true/>
-		<key>^Resources/.*\.lproj/</key>
-		<dict>
-			<key>optional</key>
-			<true/>
-			<key>weight</key>
-			<real>1000</real>
-		</dict>
-		<key>^Resources/.*\.lproj/locversion.plist$</key>
-		<dict>
-			<key>omit</key>
-			<true/>
-			<key>weight</key>
-			<real>1100</real>
-		</dict>
-		<key>^Resources/Base\.lproj/</key>
-		<dict>
-			<key>weight</key>
-			<real>1010</real>
-		</dict>
-		<key>^version.plist$</key>
-		<true/>
-	</dict>
-	<key>rules2</key>
-	<dict>
-		<key>.*\.dSYM($|/)</key>
-		<dict>
-			<key>weight</key>
-			<real>11</real>
-		</dict>
-		<key>^(.*/)?\.DS_Store$</key>
-		<dict>
-			<key>omit</key>
-			<true/>
-			<key>weight</key>
-			<real>2000</real>
-		</dict>
-		<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
-		<dict>
-			<key>nested</key>
-			<true/>
-			<key>weight</key>
-			<real>10</real>
-		</dict>
-		<key>^.*</key>
-		<true/>
-		<key>^Info\.plist$</key>
-		<dict>
-			<key>omit</key>
-			<true/>
-			<key>weight</key>
-			<real>20</real>
-		</dict>
-		<key>^PkgInfo$</key>
-		<dict>
-			<key>omit</key>
-			<true/>
-			<key>weight</key>
-			<real>20</real>
-		</dict>
-		<key>^Resources/</key>
-		<dict>
-			<key>weight</key>
-			<real>20</real>
-		</dict>
-		<key>^Resources/.*\.lproj/</key>
-		<dict>
-			<key>optional</key>
-			<true/>
-			<key>weight</key>
-			<real>1000</real>
-		</dict>
-		<key>^Resources/.*\.lproj/locversion.plist$</key>
-		<dict>
-			<key>omit</key>
-			<true/>
-			<key>weight</key>
-			<real>1100</real>
-		</dict>
-		<key>^Resources/Base\.lproj/</key>
-		<dict>
-			<key>weight</key>
-			<real>1010</real>
-		</dict>
-		<key>^[^/]+$</key>
-		<dict>
-			<key>nested</key>
-			<true/>
-			<key>weight</key>
-			<real>10</real>
-		</dict>
-		<key>^embedded\.provisionprofile$</key>
-		<dict>
-			<key>weight</key>
-			<real>20</real>
-		</dict>
-		<key>^version\.plist$</key>
-		<dict>
-			<key>weight</key>
-			<real>20</real>
-		</dict>
-	</dict>
-</dict>
-</plist>

+ 0 - 5
dist/config.ini

@@ -1,5 +0,0 @@
-[Account]
-email = apxeme@mailto.plus
-password = ccz14321@
-first_name = cheng
-last_name = zhen 

+ 0 - 80
dist/readme.md

@@ -1,80 +0,0 @@
-
-
-# Cursor Pro Keep Alive 使用说明文档
-
-## 1. 软件介绍
-Cursor Pro Keep Alive 是一个自动化工具,用于管理 Cursor 账号的注册和更新。该工具可以自动执行账号删除和重新注册流程,以保持账号活跃。
-
-> 在执行之前,一定要确保账号是通过 https://tempmail.plus/zh 获取的临时邮箱注册了 cursor账号。在注册账号时要设置好名字和密码。
-
-## 2. 安装和准备
-
-### 2.1 必要文件
-确保您有以下文件:
-- `cursor_pro_keep_alive.exe` - 主程序
-- `config.ini` - 配置文件
-
-
-
-## 3. 配置文件设置
-
-在运行程序前,需要正确配置 `config.ini` 文件:
-
-```ini
-[Account]
-email = your_username@mailto.plus    # 邮箱地址(必须使用 mailto.plus 域名)
-password = your_password             # 账号密码
-first_name = your_firstname          # 名字
-last_name = your_lastname           # 姓氏
-```
-
-注意事项:
-- 邮箱必须使用 `mailto.plus` 域名
-- 请确保配置文件使用 UTF-8 编码保存
-
-## 4. 运行程序
-
-### 4.1 运行步骤
-1. 确保所有必要文件都在同一目录下
-2. 双击运行 `cursor_pro_keep_alive.exe`
-3. 程序会自动执行以下操作:
-   - 删除现有账号
-   - 注册新账号
-   - 更新认证信息
-
-### 4.2 运行提示
-- 程序运行过程中会显示各个步骤的执行状态
-- 如果出现验证码,程序会自动处理
-- 运行完成后会显示操作结果
-
-## 5. 常见问题解决
-
-### 5.1 配置文件错误
-错误提示:`配置文件不存在`
-- 解决方法:确保 `config.ini` 文件在程序同目录下
-
-
-## 6. 注意事项
-
-1. 运行环境要求:
-   - Windows 操作系统
-   - 稳定的网络连接
-
-2. 安全提示:
-   - 请妥善保管配置文件,避免泄露账号信息
-   - 建议定期更改密码
-
-3. 使用建议:
-   - 建议在非高峰时段运行程序
-   - 保持配置文件的定期备份
-
-## 7. 技术支持
-
-如遇到问题,请检查:
-1. 配置文件格式是否正确
-2. 必要文件是否完整
-3. 网络连接是否正常
-
-## 8. 免责声明
-
-本程序仅供学习和研究使用,请遵守相关服务条款和法律法规。使用本程序产生的任何后果由用户自行承担。