Skip to content

Commit

Permalink
🐞 fix: fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
GalacticDevOps committed Jan 14, 2025
1 parent 6148219 commit ea4e3b8
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 110 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.6-alpha1] - 2024-01-13
## [1.0.8] - 2024-01-14

### Fixed
- 修复MacOs下一键重置功能异常的问题
- 修复了一些已知的可能问题
- Fix some known issues

### Pending
- Email problem for receiving emails

## [1.0.3] - 2024-01-10

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ez-cursor-free",
"version": "1.0.7-alpha1",
"version": "1.0.8",
"description": "Ez2 Use Cursor Free Tools",
"main": "./out/main/index.js",
"author": "Soleil",
Expand Down
18 changes: 10 additions & 8 deletions resources/workspace/browser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ def _get_browser_options(self):
try:
extension_path = self._get_extension_path()
if extension_path:
print(f"正在加载插件: {extension_path}")
co.add_extension(extension_path)
print("插件加载成功")
logging.info("插件加载成功")
else:
print("未找到插件目录")
logging.warning("未找到插件目录")
except Exception as e:
print(f"加载插件时出错: {e}")
logging.warning(f"加载插件时出错: {e}")

# 基本配置
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")
proxy = os.getenv('BROWSER_PROXY')
if proxy:
co.set_proxy(proxy)
co.auto_port()
co.headless(True)
co.headless(os.getenv('BROWSER_HEADLESS', 'True').lower() == 'true')

if sys.platform == "darwin":
co.set_argument("--no-sandbox")
Expand All @@ -64,13 +66,13 @@ def _get_extension_path(self):

# 检查插件文件是否完整
if os.path.exists(extension_path):
required_files = ['manifest.json', 'content.js']
required_files = ['manifest.json', 'script.js']
if all(os.path.exists(os.path.join(extension_path, f)) for f in required_files):
return extension_path
else:
print(f"插件目录 {extension_path} 文件不完整")
logging.warning(f"插件目录 {extension_path} 文件不完整")
else:
print(f"插件目录不存在: {extension_path}")
raise FileNotFoundError(f"插件不存在: {extension_path}")

return None

Expand Down
38 changes: 19 additions & 19 deletions resources/workspace/cursor_pro_keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_cursor_session_token(tab, max_attempts=3, retry_interval=2):
:param retry_interval: 重试间隔(秒)
:return: session token 或 None
"""
print("开始获取cookie")
logging.info("开始获取cookie")
attempts = 0

while attempts < max_attempts:
Expand Down Expand Up @@ -123,18 +123,18 @@ def get_temp_email(tab):
if current_email == last_email:
stable_count += 1
if stable_count >= 2: # 连续两次获取到相同的邮箱地址
print(f"邮箱地址已稳定: {current_email}")
logging.info(f"邮箱地址已稳定: {current_email}")
return current_email
else:
stable_count = 0
last_email = current_email
print(f"检测到邮箱地址: {current_email},等待稳定...")
logging.info(f"检测到邮箱地址: {current_email},等待稳定...")

print(f"等待邮箱加载... ({i+1}/{max_retries})")
time.sleep(2)

except Exception as e:
print(f"获取邮箱时出错: {str(e)}")
logging.warning(f"获取邮箱时出错: {str(e)}")
time.sleep(2)
stable_count = 0 # 发生错误时重置稳定计数

Expand All @@ -143,7 +143,7 @@ def get_temp_email(tab):

def sign_up_account(browser, tab, account_info):
"""注册账号"""
print("开始注册...")
logging.info("开始注册...")
tab.get(SIGN_UP_URL) # 使用常量 SIGN_UP_URL

try:
Expand All @@ -160,7 +160,7 @@ def sign_up_account(browser, tab, account_info):
tab.actions.click("@type=submit")

except Exception as e:
print("打开注册页面失败")
logging.warning("打开注册页面失败")
return False

handle_turnstile(tab)
Expand All @@ -171,15 +171,15 @@ def sign_up_account(browser, tab, account_info):
time.sleep(random.uniform(1, 3))

tab.ele("@type=submit").click()
print("请稍等...")
logging.info("请稍等...")

except Exception as e:
print("执行失败")
logging.warning("执行失败")
return False

time.sleep(random.uniform(1, 3))
if tab.ele("This email is not available."):
print("执行失败")
logging.warning("执行失败")
return False

handle_turnstile(tab)
Expand Down Expand Up @@ -218,16 +218,16 @@ def handle_verification_code(browser, tab, account_info):
while time.time() - start_time < max_wait:
try:
if tab.ele("Account Settings"):
print("注册成功")
logging.info("注册成功")
return True

if tab.ele("@data-index=0"):
code = email_handler.get_verification_code(account_info["email"])
if not code:
print("无法获取验证码")
logging.error("无法获取验证码")
return False

print(f"输入验证码: {code}")
logging.info(f"输入验证码: {code}")
for i, digit in enumerate(code):
tab.ele(f"@data-index={i}").input(digit)
time.sleep(random.uniform(0.1, 0.3))
Expand All @@ -236,10 +236,10 @@ def handle_verification_code(browser, tab, account_info):
time.sleep(2)

except Exception as e:
print(f"处理验证码时出错: {str(e)}")
logging.error(f"处理验证码时出错: {str(e)}")
time.sleep(2)

print("验证码处理超时")
logging.error("验证码处理超时")
return False


Expand Down Expand Up @@ -333,7 +333,7 @@ def main():
extension_path = args.extension_path or default_extension_path

if os.path.exists(extension_path):
required_files = ['manifest.json', 'content.js']
required_files = ['manifest.json', 'script.js']
missing_files = [f for f in required_files
if not os.path.exists(os.path.join(extension_path, f))]
if missing_files:
Expand Down Expand Up @@ -375,16 +375,16 @@ def main():
if sign_up_account(browser, signup_tab, account_info):
token = get_cursor_session_token(signup_tab)
if token:
print(f"注册成功! Token: {token}")
logging.info(f"注册成功! Token: {token}")
update_cursor_auth(
email=account_info["email"], access_token=token, refresh_token=token
)
else:
print("获取token失败")
logging.error("获取token失败")
else:
print("注册失败")
logging.error("注册失败")

print("执行完毕")
logging.info("执行完毕")
cleanup_and_exit(browser_manager, 0)

except Exception as e:
Expand Down
50 changes: 25 additions & 25 deletions resources/workspace/get_email_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from DrissionPage.common import Keys
import time
import re
import logging


class EmailVerificationHandler:
Expand All @@ -13,74 +14,73 @@ def get_verification_code(self, email):
code = None

try:
print("正在处理...")
# 打开新标签页访问临时邮箱
logging.info("正在处理...")
tab_mail = self.browser.new_tab(self.mail_url)
self.browser.activate_tab(tab_mail)

# 等待并获取最新邮件
code = self._get_latest_mail_code(tab_mail)

# 清理邮件
# self._cleanup_mail(tab_mail)

# 关闭标签页
tab_mail.close()

except Exception as e:
print(f"获取验证码失败: {str(e)}")
logging.error(f"获取验证码失败: {str(e)}")

return code

def _get_latest_mail_code(self, tab):
code = None
# 等待并点击验证邮件
while True:
retry_count = 0
max_retries = 3

while retry_count < max_retries:
try:
# 查找邮件表格中的所有行
email_row = tab.ele("css:tbody > tr.border-b.cursor-pointer", timeout=2)
if email_row:
# 查找主题单元格
subject_cell = email_row.ele("css:td:nth-child(2)")
if subject_cell and "Verify your email address" in subject_cell.text:
print("找到验证邮件,正在打开...")
logging.info("找到验证邮件,正在打开...")
email_row.click()
time.sleep(2)
break
print("等待验证邮件...")

logging.info("等待验证邮件...")
time.sleep(2)
# 刷新页面
tab.refresh()
time.sleep(3)

retry_count += 1

except Exception as e:
print(f"查找邮件时出错: {str(e)}")
logging.error(f"查找邮件时出错: {str(e)}")
time.sleep(2)
retry_count += 1

if retry_count >= max_retries:
logging.error("无法找到验证邮件,结束任务。")
raise Exception("无法找到验证邮件。")

# 提取验证码
max_retries = 10
for attempt in range(max_retries):
try:
# 查找邮件内容区域
content_td = tab.ele("css:td.px-3.text-black.text-base", timeout=2)
if content_td:
content = content_td.text
if content:
matches = re.findall(r'\b\d{6}\b', content)
for match in matches:
if "verification code" in content.lower() or "verify" in content.lower():
print(f"从内容中提取到验证码: {match}")
logging.info(f"从内容中提取到验证码: {match}")
return match
print(f"等待验证码加载... ({attempt + 1}/{max_retries})")

logging.info(f"等待验证码加载... ({attempt + 1}/{max_retries})")
time.sleep(2)

except Exception as e:
print(f"提取验证码时出错: {str(e)}")
logging.error(f"提取验证码时出错: {str(e)}")
time.sleep(2)
print("无法获取验证码")

logging.error("无法获取验证码")
return None

def _cleanup_mail(self, tab):
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ app.whenReady().then(() => {
let command: string;
switch (process.platform) {
case 'win32':
command = `start /MIN cmd.exe /K "cd /d "${workspacePath}" && python "${scriptPath}" && pause"`;
command = `start /B cmd.exe /K "cd /d "${workspacePath}" && python "${scriptPath}" && exit"`;
break;
case 'darwin': // macOS
// 修复 macOS 命令,正确处理路径中的空格和引号
Expand Down
22 changes: 13 additions & 9 deletions workspace/browser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,31 @@ def init_browser(self):
def _get_browser_options(self):
"""获取浏览器配置"""
co = ChromiumOptions()

browser_path = os.getenv("BROWSER_PATH", None)
if browser_path and os.path.exists(browser_path):
co.set_paths(browser_path=browser_path)
# 尝试加载插件
try:
extension_path = self._get_extension_path()
if extension_path:
print(f"正在加载插件: {extension_path}")
co.add_extension(extension_path)
print("插件加载成功")
logging.info("插件加载成功")
else:
print("未找到插件目录")
logging.warning("未找到插件目录")
except Exception as e:
print(f"加载插件时出错: {e}")
logging.warning(f"加载插件时出错: {e}")

# 基本配置
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")
proxy = os.getenv('BROWSER_PROXY')
if proxy:
co.set_proxy(proxy)
co.auto_port()
co.headless(True)
co.headless(os.getenv('BROWSER_HEADLESS', 'True').lower() == 'true')

if sys.platform == "darwin":
co.set_argument("--no-sandbox")
Expand All @@ -62,13 +66,13 @@ def _get_extension_path(self):

# 检查插件文件是否完整
if os.path.exists(extension_path):
required_files = ['manifest.json', 'content.js']
required_files = ['manifest.json', 'script.js']
if all(os.path.exists(os.path.join(extension_path, f)) for f in required_files):
return extension_path
else:
print(f"插件目录 {extension_path} 文件不完整")
logging.warning(f"插件目录 {extension_path} 文件不完整")
else:
print(f"插件目录不存在: {extension_path}")
raise FileNotFoundError(f"插件不存在: {extension_path}")

return None

Expand Down
Loading

0 comments on commit ea4e3b8

Please sign in to comment.