v3.3.9版本更新: 1.优化UI界面和按钮样式 2.改进使用说明文字,增加颜色标注 3.优化加载对话框样式 4.添加请求节流机制,防止重复提交 5.完善错误处理和提示信息 6.优化会员状态检查逻辑 7.改进禁用更新功能的实现
This commit is contained in:
@@ -9,6 +9,7 @@ from PyQt5.QtWidgets import (QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QDialog, QProgressBar, QStyle)
|
||||
from PyQt5.QtCore import Qt, QTimer, QThread, pyqtSignal
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
import time
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
|
||||
@@ -53,8 +54,9 @@ class LoadingDialog(QDialog):
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
QLabel {
|
||||
color: #333333;
|
||||
color: #0d6efd;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
padding: 10px;
|
||||
}
|
||||
QProgressBar {
|
||||
@@ -96,6 +98,11 @@ class MainWindow(QMainWindow):
|
||||
self._activation_status = None # 缓存的激活状态
|
||||
self._status_timer = None # 状态更新定时器
|
||||
|
||||
# 添加请求锁,防止重复提交
|
||||
self._is_requesting = False
|
||||
self._last_request_time = 0
|
||||
self._request_cooldown = 2 # 请求冷却时间(秒)
|
||||
|
||||
version = get_version()
|
||||
cursor_version = self.switcher.get_cursor_version()
|
||||
self.setWindowTitle(f"听泉Cursor助手 v{version} (本机Cursor版本: {cursor_version})")
|
||||
@@ -108,6 +115,8 @@ class MainWindow(QMainWindow):
|
||||
if not window_icon.isNull():
|
||||
self.setWindowIcon(window_icon)
|
||||
logging.info(f"成功设置窗口图标: {icon_path}")
|
||||
else:
|
||||
logging.warning("图标文件加载失败")
|
||||
|
||||
# 创建系统托盘图标
|
||||
self.tray_icon = QSystemTrayIcon(self)
|
||||
@@ -163,21 +172,6 @@ class MainWindow(QMainWindow):
|
||||
activation_frame = QFrame()
|
||||
activation_layout = QVBoxLayout(activation_frame)
|
||||
|
||||
# 使用说明
|
||||
usage_label = QLabel()
|
||||
usage_label.setText("使用说明:\n\n1. 输入激活码并点击激活\n2. 激活成功后点击\"刷新Cursor编辑器授权\"即可正常使用\n3. 如果刷新无效,请点击\"突破Cursor0.45.x限制\"\n4. 建议点击\"禁用Cursor版本更新\"保持长期稳定")
|
||||
usage_label.setStyleSheet("""
|
||||
QLabel {
|
||||
color: #6c757d;
|
||||
font-size: 13px;
|
||||
padding: 10px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
""")
|
||||
activation_layout.addWidget(usage_label)
|
||||
|
||||
# 激活码输入区域
|
||||
activation_layout.addWidget(QLabel("激活(叠加)会员,多个激活码可叠加整体时长"))
|
||||
input_frame = QFrame()
|
||||
@@ -186,11 +180,54 @@ class MainWindow(QMainWindow):
|
||||
self.activation_edit = QLineEdit()
|
||||
input_layout.addWidget(self.activation_edit)
|
||||
activate_btn = QPushButton("激活")
|
||||
activate_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 25px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
min-width: 80px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #0b5ed7;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #0a58ca;
|
||||
}
|
||||
""")
|
||||
activate_btn.clicked.connect(self.activate_account)
|
||||
input_layout.addWidget(activate_btn)
|
||||
activation_layout.addWidget(input_frame)
|
||||
main_layout.addWidget(activation_frame)
|
||||
|
||||
# 使用说明
|
||||
usage_label = QLabel()
|
||||
usage_text = (
|
||||
"<p style='margin-bottom: 10px;'><b style='color: #0d6efd;'>使用步骤:</b></p>"
|
||||
"<p style='line-height: 1.5;'>"
|
||||
"1. <span style='color: #0d6efd;'>第一步:</span>输入激活码并点击<span style='color: #0d6efd;'>【激活】</span>按钮<br>"
|
||||
"2. <span style='color: #198754;'>第二步:</span>激活成功后点击<span style='color: #198754;'>【刷新Cursor编辑器授权】</span>即可正常使用<br>"
|
||||
"3. <span style='color: #dc3545;'>如果刷新无效:</span>请先点击<span style='color: #198754;'>【突破Cursor0.45.x限制】</span>,然后再点击刷新<br>"
|
||||
"4. <span style='color: #6c757d;'>建议操作:</span>点击<span style='color: #dc3545;'>【禁用Cursor版本更新】</span>保持长期稳定"
|
||||
"</p>"
|
||||
)
|
||||
usage_label.setText(usage_text)
|
||||
usage_label.setStyleSheet("""
|
||||
QLabel {
|
||||
color: #333333;
|
||||
font-size: 13px;
|
||||
padding: 15px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
""")
|
||||
usage_label.setTextFormat(Qt.RichText)
|
||||
usage_label.setWordWrap(True)
|
||||
activation_layout.addWidget(usage_label)
|
||||
|
||||
# 操作按钮区域
|
||||
btn_frame = QFrame()
|
||||
btn_layout = QVBoxLayout(btn_frame)
|
||||
@@ -203,8 +240,8 @@ class MainWindow(QMainWindow):
|
||||
border: none;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
min-width: 200px;
|
||||
font-size: 13px;
|
||||
min-width: 300px;
|
||||
margin: 5px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
@@ -216,21 +253,21 @@ class MainWindow(QMainWindow):
|
||||
"""
|
||||
|
||||
# 刷新授权按钮
|
||||
refresh_btn = QPushButton("刷新Cursor编辑器授权")
|
||||
refresh_btn = QPushButton("刷新 Cursor 编辑器授权")
|
||||
refresh_btn.setStyleSheet(button_style)
|
||||
refresh_btn.clicked.connect(self.refresh_cursor_auth)
|
||||
refresh_btn.setMinimumHeight(50)
|
||||
btn_layout.addWidget(refresh_btn)
|
||||
|
||||
# 突破限制按钮
|
||||
bypass_btn = QPushButton("突破Cursor0.45.x限制")
|
||||
bypass_btn = QPushButton("突破 Cursor 0.45.x 限制")
|
||||
bypass_btn.setStyleSheet(button_style.replace("#0d6efd", "#198754").replace("#0b5ed7", "#157347").replace("#0a58ca", "#146c43"))
|
||||
bypass_btn.clicked.connect(self.dummy_function)
|
||||
bypass_btn.clicked.connect(self.bypass_cursor_limit)
|
||||
bypass_btn.setMinimumHeight(50)
|
||||
btn_layout.addWidget(bypass_btn)
|
||||
|
||||
# 禁用更新按钮
|
||||
disable_update_btn = QPushButton("禁用Cursor版本更新")
|
||||
disable_update_btn = QPushButton("禁用 Cursor 版本更新")
|
||||
disable_update_btn.setStyleSheet(button_style.replace("#0d6efd", "#dc3545").replace("#0b5ed7", "#bb2d3b").replace("#0a58ca", "#b02a37"))
|
||||
disable_update_btn.clicked.connect(self.disable_cursor_update)
|
||||
disable_update_btn.setMinimumHeight(50)
|
||||
@@ -271,14 +308,33 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def copy_device_id(self):
|
||||
"""复制设备ID到剪贴板"""
|
||||
if not self.check_status():
|
||||
return
|
||||
QApplication.clipboard().setText(self.hardware_id_edit.text())
|
||||
QMessageBox.information(self, "提示", "设备ID已复制到剪贴板")
|
||||
|
||||
def show_loading_dialog(self, message="请稍候..."):
|
||||
"""显示加载对话框"""
|
||||
self.loading_dialog = LoadingDialog(self, message)
|
||||
self.loading_dialog.setStyleSheet("""
|
||||
QDialog {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
QLabel {
|
||||
color: #0d6efd;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
padding: 10px;
|
||||
}
|
||||
QProgressBar {
|
||||
border: 2px solid #e9ecef;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #0d6efd;
|
||||
width: 10px;
|
||||
margin: 0.5px;
|
||||
}
|
||||
""")
|
||||
self.loading_dialog.show()
|
||||
|
||||
def hide_loading_dialog(self):
|
||||
@@ -286,7 +342,7 @@ class MainWindow(QMainWindow):
|
||||
if hasattr(self, 'loading_dialog'):
|
||||
self.loading_dialog.hide()
|
||||
self.loading_dialog.deleteLater()
|
||||
|
||||
|
||||
def activate_account(self):
|
||||
"""激活账号"""
|
||||
code = self.activation_edit.text().strip()
|
||||
@@ -460,19 +516,17 @@ class MainWindow(QMainWindow):
|
||||
# 更新会员信息显示
|
||||
self.update_status_display(account_info)
|
||||
# 更新激活状态缓存
|
||||
self._activation_status = True
|
||||
self._activation_status = account_info.get('status') == 'active'
|
||||
|
||||
# 更新状态定时器
|
||||
days_left = account_info.get('days_left', 0)
|
||||
seconds_left = days_left * 24 * 60 * 60
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
self._status_timer = QTimer(self)
|
||||
self._status_timer.setSingleShot(True)
|
||||
self._status_timer.timeout.connect(self.check_status)
|
||||
update_interval = min(seconds_left - 60, 24 * 60 * 60) # 最长1天更新一次
|
||||
if update_interval > 0:
|
||||
self._status_timer.start(update_interval * 1000) # 转换为毫秒
|
||||
if self._activation_status:
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
self._status_timer = QTimer(self)
|
||||
self._status_timer.setSingleShot(False)
|
||||
self._status_timer.timeout.connect(self.check_status)
|
||||
self._status_timer.start(60 * 1000) # 每60秒检测一次
|
||||
logging.info("已设置每分钟检测会员状态")
|
||||
|
||||
msg = QMessageBox(self)
|
||||
msg.setWindowTitle("激活成功")
|
||||
@@ -549,21 +603,26 @@ class MainWindow(QMainWindow):
|
||||
}
|
||||
""")
|
||||
msg.exec_()
|
||||
# 更新显示为未激活状态
|
||||
self.update_status_display(account_info)
|
||||
else:
|
||||
QMessageBox.critical(self, "错误", f"激活失败: {data}")
|
||||
# 更新为未激活状态
|
||||
device_info = self.switcher.get_device_info()
|
||||
inactive_status = {
|
||||
"status": "inactive",
|
||||
"expire_time": "",
|
||||
"total_days": 0,
|
||||
"days_left": 0,
|
||||
"device_info": device_info
|
||||
}
|
||||
self.update_status_display(inactive_status)
|
||||
|
||||
# 激活后检查一次状态
|
||||
self.check_status()
|
||||
|
||||
def update_status_display(self, status_info: dict):
|
||||
"""更新状态显示"""
|
||||
# 打印API返回的原始数据
|
||||
logging.info("=== API返回数据 ===")
|
||||
logging.info(f"状态信息: {status_info}")
|
||||
if 'activation_records' in status_info:
|
||||
logging.info("激活记录:")
|
||||
for record in status_info['activation_records']:
|
||||
logging.info(f"- 记录: {record}")
|
||||
|
||||
# 更新状态文本
|
||||
status_map = {
|
||||
@@ -581,18 +640,10 @@ class MainWindow(QMainWindow):
|
||||
f"剩余天数:{status_info.get('days_left', 0)}天"
|
||||
]
|
||||
|
||||
# 如果有激活记录,显示最近一次激活信息
|
||||
activation_records = status_info.get('activation_records', [])
|
||||
if activation_records:
|
||||
latest_record = activation_records[-1] # 获取最新的激活记录
|
||||
device_info = latest_record.get('device_info', {})
|
||||
|
||||
# 添加设备信息
|
||||
device_info = status_info.get('device_info', {})
|
||||
if device_info:
|
||||
status_lines.extend([
|
||||
"",
|
||||
"最近激活信息:",
|
||||
f"激活码:{latest_record.get('code', '')}",
|
||||
f"激活时间:{latest_record.get('activation_time', '')}",
|
||||
f"增加天数:{latest_record.get('days', 0)}天",
|
||||
"",
|
||||
"设备信息:",
|
||||
f"系统:{device_info.get('os', '')}",
|
||||
@@ -603,12 +654,13 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# 更新状态文本
|
||||
self.status_text.setPlainText("\n".join(status_lines))
|
||||
|
||||
|
||||
def check_status(self):
|
||||
"""检查会员状态(从API获取)"""
|
||||
try:
|
||||
# 显示加载对话框
|
||||
self.show_loading_dialog("正在检查会员状态,请稍候...")
|
||||
# 只在首次检查时显示加载对话框
|
||||
if self._activation_status is None:
|
||||
self.show_loading_dialog("正在检查会员状态,请稍候...")
|
||||
|
||||
# 创建工作线程
|
||||
self.worker = ApiWorker(self.switcher.get_member_status)
|
||||
@@ -616,175 +668,199 @@ class MainWindow(QMainWindow):
|
||||
self.worker.start()
|
||||
|
||||
except Exception as e:
|
||||
self.hide_loading_dialog()
|
||||
if self._activation_status is None:
|
||||
self.hide_loading_dialog()
|
||||
QMessageBox.critical(self, "错误", f"检查状态失败: {str(e)}")
|
||||
self._activation_status = False
|
||||
logging.error(f"检查状态时发生错误: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def on_status_check_complete(self, result):
|
||||
"""状态检查完成回调"""
|
||||
success, data = result
|
||||
self.hide_loading_dialog()
|
||||
|
||||
# 只在首次检查时隐藏加载对话框
|
||||
if self._activation_status is None:
|
||||
self.hide_loading_dialog()
|
||||
|
||||
if success and data:
|
||||
self.update_status_display(data)
|
||||
# 更新缓存的激活状态
|
||||
# 更新激活状态和定时器
|
||||
self._activation_status = data.get('status') == 'active'
|
||||
|
||||
# 设置状态更新定时器
|
||||
if self._activation_status:
|
||||
# 获取剩余时间(秒)
|
||||
days_left = data.get('days_left', 0)
|
||||
seconds_left = days_left * 24 * 60 * 60
|
||||
|
||||
# 创建定时器,在到期前1分钟更新状态
|
||||
# 设置定时器
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
self._status_timer = QTimer(self)
|
||||
self._status_timer.setSingleShot(True)
|
||||
self._status_timer.setSingleShot(False)
|
||||
self._status_timer.timeout.connect(self.check_status)
|
||||
update_interval = min(seconds_left - 60, 24 * 60 * 60) # 最长1天更新一次
|
||||
if update_interval > 0:
|
||||
self._status_timer.start(update_interval * 1000) # 转换为毫秒
|
||||
self._status_timer.start(60 * 1000) # 每60秒检测一次
|
||||
logging.info("已设置每分钟检测会员状态")
|
||||
else:
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
|
||||
return self._activation_status
|
||||
# 更新显示
|
||||
self.update_status_display(data)
|
||||
else:
|
||||
# 停止定时器
|
||||
if self._status_timer:
|
||||
self._status_timer.stop()
|
||||
self._activation_status = False
|
||||
|
||||
# 更新为未激活状态
|
||||
device_info = self.switcher.get_device_info()
|
||||
inactive_status = {
|
||||
"hardware_id": self.switcher.hardware_id,
|
||||
"expire_time": "",
|
||||
"days_left": 0,
|
||||
"total_days": 0,
|
||||
"status": "inactive",
|
||||
"activation_records": []
|
||||
"expire_time": "",
|
||||
"total_days": 0,
|
||||
"days_left": 0,
|
||||
"device_info": device_info
|
||||
}
|
||||
self.update_status_display(inactive_status)
|
||||
self._activation_status = False
|
||||
return False
|
||||
logging.warning("会员状态检查失败或未激活")
|
||||
|
||||
# 清除会员信息文件
|
||||
try:
|
||||
member_file = self.switcher.config.member_file
|
||||
if member_file.exists():
|
||||
member_file.unlink()
|
||||
logging.info("已清除会员信息文件")
|
||||
except Exception as e:
|
||||
logging.error(f"清除会员信息文件时出错: {str(e)}")
|
||||
|
||||
return self._activation_status
|
||||
|
||||
def check_activation_status(self) -> bool:
|
||||
"""检查是否已激活(使用缓存)
|
||||
|
||||
Returns:
|
||||
bool: 是否已激活
|
||||
"""
|
||||
# 如果缓存的状态是None,从API获取
|
||||
if self._activation_status is None:
|
||||
# 首次检查,从API获取
|
||||
return self.check_status()
|
||||
|
||||
# 如果未激活,显示购买信息
|
||||
if not self._activation_status:
|
||||
# 创建自定义消息框
|
||||
msg = QDialog(self)
|
||||
msg.setWindowTitle("会员未激活")
|
||||
msg.setFixedWidth(400)
|
||||
msg.setWindowFlags(msg.windowFlags() & ~Qt.WindowContextHelpButtonHint)
|
||||
|
||||
# 创建布局
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# 添加图标和文本
|
||||
icon_label = QLabel()
|
||||
icon_label.setPixmap(self.style().standardIcon(QStyle.SP_MessageBoxWarning).pixmap(32, 32))
|
||||
icon_label.setAlignment(Qt.AlignCenter)
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
text_label = QLabel("您还未激活会员或会员已过期")
|
||||
text_label.setAlignment(Qt.AlignCenter)
|
||||
text_label.setStyleSheet("font-size: 14px; font-weight: bold; color: #333333; padding: 10px;")
|
||||
layout.addWidget(text_label)
|
||||
|
||||
# 添加购买信息
|
||||
info_text = "获取会员激活码,请通过以下方式:\n\n" \
|
||||
"• 官方自助网站:cursor.nosqli.com\n" \
|
||||
"• 微信客服:behikcigar\n" \
|
||||
"• 闲鱼店铺:xxx\n\n" \
|
||||
"————————————————————\n" \
|
||||
"诚招代理商,欢迎加盟合作!"
|
||||
|
||||
info_label = QLabel(info_text)
|
||||
info_label.setAlignment(Qt.AlignLeft)
|
||||
info_label.setStyleSheet("""
|
||||
QLabel {
|
||||
color: #333333;
|
||||
font-size: 14px;
|
||||
padding: 15px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dee2e6;
|
||||
margin: 10px;
|
||||
}
|
||||
""")
|
||||
layout.addWidget(info_label)
|
||||
|
||||
# 添加复制按钮区域
|
||||
btn_layout = QHBoxLayout()
|
||||
|
||||
# 复制网站按钮
|
||||
copy_web_btn = QPushButton("复制网站")
|
||||
copy_web_btn.clicked.connect(lambda: self.copy_and_show_tip(msg, "cursor.nosqli.com", "网站地址已复制到剪贴板"))
|
||||
copy_web_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #0b5ed7;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(copy_web_btn)
|
||||
|
||||
# 复制微信按钮
|
||||
copy_wx_btn = QPushButton("复制微信")
|
||||
copy_wx_btn.clicked.connect(lambda: self.copy_and_show_tip(msg, "behikcigar", "微信号已复制到剪贴板"))
|
||||
copy_wx_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #198754;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #157347;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(copy_wx_btn)
|
||||
|
||||
# 确定按钮
|
||||
ok_btn = QPushButton("确定")
|
||||
ok_btn.clicked.connect(msg.accept)
|
||||
ok_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 25px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
min-width: 100px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #0b5ed7;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(ok_btn)
|
||||
|
||||
layout.addLayout(btn_layout)
|
||||
msg.setLayout(layout)
|
||||
msg.exec_()
|
||||
self.show_purchase_info()
|
||||
|
||||
return self._activation_status
|
||||
|
||||
|
||||
def show_purchase_info(self):
|
||||
"""显示购买信息对话框"""
|
||||
# 创建自定义消息框
|
||||
msg = QDialog(self)
|
||||
msg.setWindowTitle("会员未激活")
|
||||
msg.setFixedWidth(400)
|
||||
msg.setWindowFlags(msg.windowFlags() & ~Qt.WindowContextHelpButtonHint)
|
||||
|
||||
# 创建布局
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# 添加图标和文本
|
||||
icon_label = QLabel()
|
||||
icon_label.setPixmap(self.style().standardIcon(QStyle.SP_MessageBoxWarning).pixmap(32, 32))
|
||||
icon_label.setAlignment(Qt.AlignCenter)
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
text_label = QLabel("您还未激活会员或会员已过期")
|
||||
text_label.setAlignment(Qt.AlignCenter)
|
||||
text_label.setStyleSheet("font-size: 14px; font-weight: bold; color: #333333; padding: 10px;")
|
||||
layout.addWidget(text_label)
|
||||
|
||||
# 添加购买信息
|
||||
info_text = "获取会员激活码,请通过以下方式:\n\n" \
|
||||
"• 官方自助网站:cursor.nosqli.com\n" \
|
||||
"• 微信客服:behikcigar\n" \
|
||||
"• 闲鱼店铺:xxx\n\n" \
|
||||
"————————————————————\n" \
|
||||
"诚招代理商,欢迎加盟合作!"
|
||||
|
||||
info_label = QLabel(info_text)
|
||||
info_label.setAlignment(Qt.AlignLeft)
|
||||
info_label.setStyleSheet("""
|
||||
QLabel {
|
||||
color: #333333;
|
||||
font-size: 14px;
|
||||
padding: 15px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dee2e6;
|
||||
margin: 10px;
|
||||
}
|
||||
""")
|
||||
layout.addWidget(info_label)
|
||||
|
||||
# 添加复制按钮区域
|
||||
btn_layout = QHBoxLayout()
|
||||
|
||||
# 复制网站按钮
|
||||
copy_web_btn = QPushButton("复制网站")
|
||||
copy_web_btn.clicked.connect(lambda: self.copy_and_show_tip(msg, "cursor.nosqli.com", "网站地址已复制到剪贴板"))
|
||||
copy_web_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #0b5ed7;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(copy_web_btn)
|
||||
|
||||
# 复制微信按钮
|
||||
copy_wx_btn = QPushButton("复制微信")
|
||||
copy_wx_btn.clicked.connect(lambda: self.copy_and_show_tip(msg, "behikcigar", "微信号已复制到剪贴板"))
|
||||
copy_wx_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #198754;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #157347;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(copy_wx_btn)
|
||||
|
||||
# 确定按钮
|
||||
ok_btn = QPushButton("确定")
|
||||
ok_btn.clicked.connect(msg.accept)
|
||||
ok_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 25px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
min-width: 100px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #0b5ed7;
|
||||
}
|
||||
""")
|
||||
btn_layout.addWidget(ok_btn)
|
||||
|
||||
layout.addLayout(btn_layout)
|
||||
msg.setLayout(layout)
|
||||
msg.exec_()
|
||||
|
||||
def refresh_cursor_auth(self):
|
||||
"""刷新Cursor授权"""
|
||||
if not self.check_activation_status():
|
||||
return
|
||||
|
||||
if not self._check_request_throttle():
|
||||
return
|
||||
|
||||
try:
|
||||
# 显示加载对话框
|
||||
self.show_loading_dialog("正在刷新授权,请稍候...")
|
||||
@@ -795,6 +871,7 @@ class MainWindow(QMainWindow):
|
||||
self.worker.start()
|
||||
|
||||
except Exception as e:
|
||||
self._request_complete()
|
||||
self.hide_loading_dialog()
|
||||
self.show_custom_error("刷新授权失败", str(e))
|
||||
|
||||
@@ -802,6 +879,7 @@ class MainWindow(QMainWindow):
|
||||
"""刷新授权完成回调"""
|
||||
success, data = result
|
||||
self.hide_loading_dialog()
|
||||
self._request_complete()
|
||||
|
||||
if isinstance(data, tuple):
|
||||
success, message = data
|
||||
@@ -811,34 +889,185 @@ class MainWindow(QMainWindow):
|
||||
self.show_custom_error("刷新授权失败", message)
|
||||
else:
|
||||
self.show_custom_error("刷新授权失败", str(data))
|
||||
|
||||
|
||||
def disable_cursor_update(self):
|
||||
"""禁用Cursor更新"""
|
||||
if not self.check_activation_status():
|
||||
return
|
||||
|
||||
if not self._check_request_throttle():
|
||||
return
|
||||
|
||||
try:
|
||||
success, message = self.switcher.disable_cursor_update()
|
||||
if success:
|
||||
self.show_custom_message("成功", "禁用更新成功", message, QStyle.SP_DialogApplyButton, "#198754")
|
||||
else:
|
||||
self.show_custom_error("禁用更新失败", message)
|
||||
# 显示加载对话框
|
||||
self.show_loading_dialog("正在禁用更新,请稍候...")
|
||||
|
||||
# 创建工作线程
|
||||
from utils.cursor_registry import CursorRegistry
|
||||
registry = CursorRegistry()
|
||||
|
||||
def disable_func():
|
||||
try:
|
||||
# 1. 先关闭所有Cursor进程
|
||||
if sys.platform == "win32":
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 处理updater文件
|
||||
updater_path = Path(os.getenv('LOCALAPPDATA')) / "cursor-updater"
|
||||
try:
|
||||
# 如果是目录,则删除
|
||||
if updater_path.is_dir():
|
||||
import shutil
|
||||
shutil.rmtree(str(updater_path))
|
||||
logging.info("删除updater目录成功")
|
||||
# 如果是文件,则删除
|
||||
if updater_path.is_file():
|
||||
updater_path.unlink()
|
||||
logging.info("删除updater文件成功")
|
||||
|
||||
# 创建阻止文件
|
||||
updater_path.touch()
|
||||
logging.info("创建updater空文件成功")
|
||||
|
||||
# 设置文件权限
|
||||
import subprocess
|
||||
import stat
|
||||
|
||||
# 设置只读属性
|
||||
os.chmod(str(updater_path), stat.S_IREAD)
|
||||
logging.info("设置只读属性成功")
|
||||
|
||||
# 使用icacls设置权限(只读)
|
||||
username = os.getenv('USERNAME')
|
||||
cmd = f'icacls "{str(updater_path)}" /inheritance:r /grant:r "{username}:(R)"'
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
logging.error(f"设置文件权限失败: {result.stderr}")
|
||||
return False, "设置文件权限失败"
|
||||
logging.info("设置文件权限成功")
|
||||
|
||||
# 验证设置
|
||||
if not os.path.exists(updater_path):
|
||||
return False, "文件创建失败"
|
||||
if os.access(str(updater_path), os.W_OK):
|
||||
return False, "文件权限设置失败"
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"处理updater文件失败: {str(e)}")
|
||||
return False, "处理updater文件失败"
|
||||
|
||||
# 3. 修改package.json配置
|
||||
if not registry.fix_cursor_startup():
|
||||
return False, "修改配置失败"
|
||||
|
||||
# 4. 重启Cursor
|
||||
cursor_exe = registry.cursor_path / "Cursor.exe"
|
||||
if cursor_exe.exists():
|
||||
os.startfile(str(cursor_exe))
|
||||
logging.info("Cursor重启成功")
|
||||
return True, "Cursor更新已禁用,程序已重启"
|
||||
else:
|
||||
return False, "未找到Cursor程序"
|
||||
except Exception as e:
|
||||
logging.error(f"禁用更新时发生错误: {str(e)}")
|
||||
return False, str(e)
|
||||
|
||||
self.worker = ApiWorker(disable_func)
|
||||
self.worker.finished.connect(lambda result: self.on_disable_update_complete(result))
|
||||
self.worker.start()
|
||||
|
||||
except Exception as e:
|
||||
self._request_complete()
|
||||
self.hide_loading_dialog()
|
||||
self.show_custom_error("禁用更新失败", str(e))
|
||||
|
||||
def dummy_function(self):
|
||||
"""突破版本限制"""
|
||||
def on_disable_update_complete(self, result):
|
||||
"""禁用更新完成回调"""
|
||||
success, data = result
|
||||
self.hide_loading_dialog()
|
||||
self._request_complete()
|
||||
|
||||
if success:
|
||||
self.show_custom_message(
|
||||
"成功",
|
||||
"禁用更新成功",
|
||||
data,
|
||||
QStyle.SP_DialogApplyButton,
|
||||
"#198754"
|
||||
)
|
||||
else:
|
||||
self.show_custom_error("禁用更新失败", str(data))
|
||||
|
||||
def bypass_cursor_limit(self):
|
||||
"""突破Cursor版本限制"""
|
||||
if not self.check_activation_status():
|
||||
return
|
||||
|
||||
self.show_custom_message(
|
||||
"提示",
|
||||
"功能未实现",
|
||||
"此功能暂未实现,请等待后续更新。",
|
||||
QStyle.SP_MessageBoxInformation,
|
||||
"#0d6efd"
|
||||
)
|
||||
if not self._check_request_throttle():
|
||||
return
|
||||
|
||||
try:
|
||||
# 显示加载对话框
|
||||
self.show_loading_dialog("正在突破版本限制,请稍候...")
|
||||
|
||||
# 创建工作线程
|
||||
from utils.cursor_registry import CursorRegistry
|
||||
registry = CursorRegistry()
|
||||
|
||||
def reset_func():
|
||||
try:
|
||||
# 1. 先关闭所有Cursor进程
|
||||
if sys.platform == "win32":
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 清理注册表
|
||||
if not registry.clean_registry():
|
||||
return False, "清理注册表失败"
|
||||
|
||||
# 3. 清理文件
|
||||
if not registry.clean_cursor_files():
|
||||
return False, "清理文件失败"
|
||||
|
||||
# 4. 重启Cursor
|
||||
cursor_exe = self.cursor_path / "Cursor.exe"
|
||||
if cursor_exe.exists():
|
||||
os.startfile(str(cursor_exe))
|
||||
logging.info("Cursor重启成功")
|
||||
return True, "突破限制成功"
|
||||
else:
|
||||
return False, "未找到Cursor程序"
|
||||
except Exception as e:
|
||||
logging.error(f"突破限制时发生错误: {str(e)}")
|
||||
return False, str(e)
|
||||
|
||||
self.worker = ApiWorker(reset_func)
|
||||
self.worker.finished.connect(self.on_bypass_complete)
|
||||
self.worker.start()
|
||||
|
||||
except Exception as e:
|
||||
self._request_complete()
|
||||
self.hide_loading_dialog()
|
||||
self.show_custom_error("突破限制失败", str(e))
|
||||
|
||||
def on_bypass_complete(self, result):
|
||||
"""突破限制完成回调"""
|
||||
success, data = result
|
||||
self.hide_loading_dialog()
|
||||
self._request_complete()
|
||||
|
||||
if success:
|
||||
self.show_custom_message(
|
||||
"成功",
|
||||
"突破限制成功",
|
||||
"Cursor版本限制已突破,编辑器已重启。",
|
||||
QStyle.SP_DialogApplyButton,
|
||||
"#198754"
|
||||
)
|
||||
else:
|
||||
self.show_custom_error("突破限制失败", str(data))
|
||||
|
||||
def show_custom_message(self, title, header, message, icon_type, color):
|
||||
"""显示自定义消息框"""
|
||||
msg = QDialog(self)
|
||||
@@ -914,4 +1143,29 @@ class MainWindow(QMainWindow):
|
||||
message,
|
||||
QStyle.SP_MessageBoxCritical,
|
||||
"#dc3545"
|
||||
)
|
||||
)
|
||||
|
||||
def _check_request_throttle(self) -> bool:
|
||||
"""检查是否可以发送请求(防重复提交)
|
||||
|
||||
Returns:
|
||||
bool: 是否可以发送请求
|
||||
"""
|
||||
current_time = time.time()
|
||||
|
||||
# 如果正在请求中,返回False
|
||||
if self._is_requesting:
|
||||
return False
|
||||
|
||||
# 如果距离上次请求时间小于冷却时间,返回False
|
||||
if current_time - self._last_request_time < self._request_cooldown:
|
||||
return False
|
||||
|
||||
# 更新状态和时间
|
||||
self._is_requesting = True
|
||||
self._last_request_time = current_time
|
||||
return True
|
||||
|
||||
def _request_complete(self):
|
||||
"""请求完成,重置状态"""
|
||||
self._is_requesting = False
|
||||
Reference in New Issue
Block a user