diff --git a/main.py b/main.py deleted file mode 100644 index 5e6d0fa..0000000 --- a/main.py +++ /dev/null @@ -1,45 +0,0 @@ -import sys -from PyQt5.QtWidgets import QApplication -from utils.browser_utils import open_website -from utils.config_handler import ConfigHandler -from ui.base_window import BaseWindow -from ui.components.progress_handler import ProgressHandler -from utils.style_handler import StyleManager -import ctypes - -ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid") - - -class XDUScript(BaseWindow): - def __init__(self): - super().__init__() - - # 初始化配置处理器 - self.config_handler = ConfigHandler(self) - - # 初始化进度处理器 - self.progress_handler = ProgressHandler(self) - - # 连接开始按钮的点击事件 - self.start_button.clicked.connect(self.config_handler.get_config) - - # 样式处理器属性 - self.style_handler = None - - # 初始化时打开网页 - open_website( - "https://ehall.xidian.edu.cn/jwapp/sys/wspjyyapp/*default/index.do", - self.console_output, - ) - - -if __name__ == "__main__": - app = QApplication(sys.argv) - ex = XDUScript() - - # 加载样式 - ex.style_handler = StyleManager(ex, app) - ex.style_handler.apply_styles() - - ex.show() - sys.exit(app.exec_()) diff --git a/main.spec b/main.spec deleted file mode 100644 index b8b9523..0000000 --- a/main.spec +++ /dev/null @@ -1,55 +0,0 @@ -# -*- mode: python ; coding: utf-8 -*- - -block_cipher = None - -a = Analysis( - [ - 'main.py', - 'D:/dev/XDU_WallNut/ui/__init__.py', - 'D:/dev/XDU_WallNut/ui/base_window.py', - 'D:/dev/XDU_WallNut/ui/components/console_section.py', - 'D:/dev/XDU_WallNut/ui/components/input_section.py', - 'D:/dev/XDU_WallNut/ui/components/console_section.py', - 'D:/dev/XDU_WallNut/utils/__init__.py', - 'D:/dev/XDU_WallNut/utils/browser_utils.py', - 'D:/dev/XDU_WallNut/utils/config_handler.py', - 'D:/dev/XDU_WallNut/utils/style_handler.py', - ], # 此项目中所有的 python 脚本 - pathex=['D:\\dev\\XDU_WallNut'], # 项目绝对路径 - binaries=[], - datas=[ - ('styles/base.qss', 'styles'), - ('favicon.ico', '.') - ], - hiddenimports=[], - hookspath=[], - runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, - cipher=block_cipher, - noarchive=False -) - -pyz = PYZ( - a.pure, a.zipped_data, - cipher=block_cipher -) - -exe = EXE( - pyz, - a.scripts, - a.binaries, - a.zipfiles, - a.datas, - [], - name='XDU_WallNut', # 打包程序的名字 - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - upx_exclude=[], - runtime_tmpdir=None, - icon='D:/dev/XDU_WallNut/favicon.ico', # 图标路径 - console=False -) \ No newline at end of file diff --git a/favicon.ico b/src/main/favicon.ico similarity index 100% rename from favicon.ico rename to src/main/favicon.ico diff --git a/src/main/main.py b/src/main/main.py new file mode 100644 index 0000000..ffed23f --- /dev/null +++ b/src/main/main.py @@ -0,0 +1,84 @@ +import sys +from PyQt5.QtWidgets import QApplication, QMessageBox +from utils.browser_utils import open_website +from utils.config_handler import ConfigHandler +from ui.base_window import BaseWindow +from ui.components.progress_handler import ProgressHandler +from utils.style_handler import StyleManager +import ctypes + +ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid") + +from utils.version_checker import VersionChecker +from utils.updater import Updater + + +class XDUScript(BaseWindow): + def __init__(self): + super().__init__() + + # 初始化配置处理器 + self.config_handler = ConfigHandler(self) + + # 初始化进度处理器 + self.progress_handler = ProgressHandler(self) + + # 连接开始按钮的点击事件,获取用户配置数据,并执行vbs脚本 + self.start_button.clicked.connect(self.config_handler.get_config) + + # 样式处理器属性 + self.style_handler = None + + # 初始化版本检查器 + self.version_checker = VersionChecker(self) + + def check_updates(self): + self.console_output.append("正在检查更新...") + has_new_version, latest_version = self.version_checker.check_for_updates() + + if has_new_version: + self.console_output.append(f"发现新版本: {self.version_checker.current_version} -> {latest_version}") + + # 更新确认对话框 + reply = QMessageBox.question( + self, + '发现新版本', + f'检测到新版本 {latest_version},是否现在更新?', + QMessageBox.Yes | QMessageBox.No, + QMessageBox.Yes + ) + + if reply == QMessageBox.Yes: + self.console_output.append("正在启动更新程序...") + self.close() + error = Updater.run_update("updater.exe") + if error: + self.console_output.append(f"更新失败: {error}") + else: + self.console_output.append("用户取消更新") + else: + self.console_output.append(f"当前已是最新版本: {latest_version}") + + +if __name__ == "__main__": + app = QApplication(sys.argv) + ex = XDUScript() + + # 加载样式 + ex.style_handler = StyleManager(ex, app) + ex.style_handler.apply_styles() + + ex.console_output.append("XDU 启动!") + + ex.show() + + # 检查更新 + ex.check_updates() + + # 检测完成后打开网页 + open_website( + "https://ehall.xidian.edu.cn/jwapp/sys/wspjyyapp/*default/index.do", + ex.console_output, + ) + + sys.exit(app.exec_()) diff --git a/src/main/main.spec b/src/main/main.spec new file mode 100644 index 0000000..e0e1ffb --- /dev/null +++ b/src/main/main.spec @@ -0,0 +1,59 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + +a = Analysis( + [ + 'main.py', + 'D:/dev/XDU_WallNut/src/main/ui/__init__.py', + 'D:/dev/XDU_WallNut/src/main/ui/base_window.py', + 'D:/dev/XDU_WallNut/src/main/ui/components/console_section.py', + 'D:/dev/XDU_WallNut/src/main/ui/components/input_section.py', + 'D:/dev/XDU_WallNut/src/main/ui/components/console_section.py', + 'D:/dev/XDU_WallNut/src/main/utils/__init__.py', + 'D:/dev/XDU_WallNut/src/main/utils/browser_utils.py', + 'D:/dev/XDU_WallNut/src/main/utils/config_handler.py', + 'D:/dev/XDU_WallNut/src/main/utils/style_handler.py', + 'D:/dev/XDU_WallNut/src/main/utils/version_checker.py', + 'D:/dev/XDU_WallNut/src/main/utils/updater.py', + ], # 此项目中所有的 python 脚本 + pathex=['D:\\dev\\XDU_WallNut\\src\\main'], # 项目绝对路径 + binaries=[], + datas=[ + ('styles/base.qss', 'styles'), + ('favicon.ico', '.'), + ('version.json', '.') + ], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False +) + +pyz = PYZ( + a.pure, a.zipped_data, + cipher=block_cipher +) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='XDU_WallNut', # 打包程序的名字 + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + icon='D:/dev/XDU_WallNut/src/main/favicon.ico', # 图标路径 + console=False , + distpath='D:/dev/XDU_WallNut/dist', # 打包输出路径 +) \ No newline at end of file diff --git a/script.vbs b/src/main/script.vbs similarity index 100% rename from script.vbs rename to src/main/script.vbs diff --git a/styles/base.qss b/src/main/styles/base.qss similarity index 100% rename from styles/base.qss rename to src/main/styles/base.qss diff --git a/ui/__init__.py b/src/main/ui/__init__.py similarity index 100% rename from ui/__init__.py rename to src/main/ui/__init__.py diff --git a/ui/base_window.py b/src/main/ui/base_window.py similarity index 82% rename from ui/base_window.py rename to src/main/ui/base_window.py index ecc5940..199d2f8 100644 --- a/ui/base_window.py +++ b/src/main/ui/base_window.py @@ -1,3 +1,7 @@ +""" +该模块用于处理主窗口相关操作 +""" + from PyQt5.QtWidgets import ( QWidget, QVBoxLayout @@ -8,6 +12,7 @@ sys.path.append('utils') from ui.components.input_section import InputSection +from ui.components.console_section import ConsoleSection class BaseWindow(QWidget): def __init__(self): @@ -22,7 +27,7 @@ def initUI(self): self.setGeometry(100, 100, 600, 400) # 设置窗口标题 - self.setWindowTitle("XDU一键评教") + self.setWindowTitle(f"XDU一键评教") # 设置窗口图标(不生效) if getattr(sys, 'frozen', False): @@ -41,7 +46,10 @@ def initUI(self): self.input_section.init_layout_number_of_textboxes() self.input_section.init_layout_comments() self.input_section.init_start_button() - self.input_section.init_console_output() + + # 初始化控制台输出组件 + self.console_section = ConsoleSection(self) + self.console_section.init_console_output() # 创建全局布局 global_layout = QVBoxLayout() @@ -59,7 +67,7 @@ def initUI(self): # 将全局布局设置为窗口的布局 self.setLayout(global_layout) - # 初始化时调用一次,设置正确的初始状态 + # 初始化时调用一次对不必要显示的组件进行隐藏,设置正确的初始状态 self.input_section.toggle_textbox_count() self.input_section.toggle_select_questions() \ No newline at end of file diff --git a/src/main/ui/components/console_section.py b/src/main/ui/components/console_section.py new file mode 100644 index 0000000..ea96af7 --- /dev/null +++ b/src/main/ui/components/console_section.py @@ -0,0 +1,24 @@ +""" +该模块用于处理控制台输出组件初始化 +""" + +from PyQt5.QtWidgets import QTextEdit + + +class ConsoleSection(QTextEdit): + def __init__(self, window): + super().__init__() + + # 初始化窗口 + self.window = window + + def init_console_output(self): + """ + 控制台输出 + """ + self.window.console_output = QTextEdit(self.window) + + # 设置只读 + self.window.console_output.setReadOnly(True) + + self.window.console_output.setPlaceholderText("控制台输出将显示在这里...") diff --git a/ui/components/input_section.py b/src/main/ui/components/input_section.py similarity index 93% rename from ui/components/input_section.py rename to src/main/ui/components/input_section.py index e42d8ae..e314c8f 100644 --- a/ui/components/input_section.py +++ b/src/main/ui/components/input_section.py @@ -1,3 +1,7 @@ +""" +该模块用于处理输入组件初始化 +""" + from PyQt5.QtWidgets import ( QVBoxLayout, QHBoxLayout, @@ -6,7 +10,6 @@ QButtonGroup, QLineEdit, QPushButton, - QTextEdit, ) class InputSection(QVBoxLayout): @@ -72,7 +75,6 @@ def init_layout_number_of_select_questions(self): self.window.layout_number_of_select_questions.addWidget( self.window.number_of_select_questions ) - return self.window.layout_number_of_select_questions def init_layout_which_option(self): """ @@ -90,7 +92,6 @@ def init_layout_which_option(self): self.window.option_group.addButton(option_button) option_layout.addWidget(option_button) self.window.layout_which_option.addLayout(option_layout) - return self.window.layout_which_option def init_layout_auto_textbox(self): @@ -156,11 +157,4 @@ def init_start_button(self): """ self.window.start_button = QPushButton("开始运行", self.window) - def init_console_output(self): - """ - 控制台输出 - """ - self.window.console_output = QTextEdit(self.window) - self.window.console_output.setReadOnly(True) - self.window.console_output.setPlaceholderText("控制台输出将显示在这里...") - return self.window.console_output + diff --git a/ui/components/progress_handler.py b/src/main/ui/components/progress_handler.py similarity index 98% rename from ui/components/progress_handler.py rename to src/main/ui/components/progress_handler.py index 227046d..0ea9fc4 100644 --- a/ui/components/progress_handler.py +++ b/src/main/ui/components/progress_handler.py @@ -1,3 +1,7 @@ +""" +该模块用于处理进度相关操作 +""" + from PyQt5.QtCore import QTimer from PyQt5.QtGui import QTextCursor import random diff --git a/utils/__init__.py b/src/main/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to src/main/utils/__init__.py diff --git a/utils/browser_utils.py b/src/main/utils/browser_utils.py similarity index 95% rename from utils/browser_utils.py rename to src/main/utils/browser_utils.py index fb86d23..dcc3206 100644 --- a/utils/browser_utils.py +++ b/src/main/utils/browser_utils.py @@ -1,3 +1,7 @@ +""" +该模块用于浏览器相关操作 +""" + import os import webbrowser diff --git a/utils/config_handler.py b/src/main/utils/config_handler.py similarity index 99% rename from utils/config_handler.py rename to src/main/utils/config_handler.py index 311a9ab..bb50ea3 100644 --- a/utils/config_handler.py +++ b/src/main/utils/config_handler.py @@ -1,3 +1,7 @@ +""" +该模块用于处理配置相关操作 +""" + from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QApplication diff --git a/utils/style_handler.py b/src/main/utils/style_handler.py similarity index 97% rename from utils/style_handler.py rename to src/main/utils/style_handler.py index 8793844..61b2a14 100644 --- a/utils/style_handler.py +++ b/src/main/utils/style_handler.py @@ -1,9 +1,10 @@ +""" +该模块用于处理样式相关操作 +""" + import os import sys -from PyQt5.QtWidgets import QApplication -from PyQt5.QtCore import QSize - class StyleManager: def __init__(self, window, app): diff --git a/src/main/utils/updater.py b/src/main/utils/updater.py new file mode 100644 index 0000000..23cd8fb --- /dev/null +++ b/src/main/utils/updater.py @@ -0,0 +1,22 @@ +import subprocess +import os +import sys +from typing import Optional + +class Updater: + @staticmethod + def run_update(updater_path: str) -> Optional[str]: + try: + # 检查更新程序是否存在 + if not os.path.exists(updater_path): + return "更新程序不存在" + + # 使用子进程运行更新程序 + subprocess.Popen([updater_path], + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) + + # 退出当前程序 + sys.exit(0) + + except Exception as e: + return f"启动更新程序失败: {str(e)}" \ No newline at end of file diff --git a/src/main/utils/version_checker.py b/src/main/utils/version_checker.py new file mode 100644 index 0000000..8fcdd42 --- /dev/null +++ b/src/main/utils/version_checker.py @@ -0,0 +1,80 @@ +import requests +import json +import os +import subprocess +from typing import Tuple +from requests.exceptions import SSLError + + +class VersionChecker: + def __init__(self, window): + + # 窗口对象 + self.window = window + + self.current_version = self._get_current_version() + self.latest_version = None + + # 请求更新信息的 URL + self.update_url = ( + "https://api.github.com/repos/Yang-ZhiHang/XDU-WallNut/releases/latest" + ) + + def _get_current_version(self) -> str: + """ + 获取当前版本 + """ + + try: + # 读取 version.json 文件,获取当前版本号 + with open("version.json", "r", encoding="utf-8") as f: + version_info = json.load(f) + return version_info.get("version") + except FileNotFoundError: + self.window.console_output.append("version.json 文件不存在") + return "0.0.0" + + def check_for_updates(self) -> Tuple[bool, str]: + """ + 检查更新 + returns: + Tuple[bool, str]: 是否需要更新,最新版本号 + """ + try: + # 请求更新 + response = requests.get(self.update_url) + if response.status_code == 200: + + # 获取最新版本信息 + release_info = response.json() + + # 获取最新版本号 + self.latest_version = release_info["tag_name"].replace("v", "") + + # 比较版本 + return self._compare_versions(), self.latest_version + + elif response.status_code == 404: + self.window.console_output.append("更新信息获取失败.") + return False, self.current_version + elif response.status_code == 403: + self.window.console_output.append("API 请求被拒绝.") + return False, self.current_version + else: + self.window.console_output.append(f"检查更新时出错: {response.text}") + return False, self.current_version + + except SSLError: + self.window.console_output.append(f"网络连接失败,请检查网络设置.") + return False, self.current_version + except Exception as e: + self.window.console_output.append(f"检查更新时出错: {str(e)}") + return False, self.current_version + + def _compare_versions(self) -> bool: + """ + 比较版本 + """ + current = [int(x) for x in self.current_version.split(".")] + latest = [int(x) for x in self.latest_version.split(".")] + return latest > current diff --git a/src/main/version.json b/src/main/version.json new file mode 100644 index 0000000..a298e4d --- /dev/null +++ b/src/main/version.json @@ -0,0 +1,3 @@ +{ + "version": "1.2.1" +} \ No newline at end of file diff --git a/src/updater/main.py b/src/updater/main.py new file mode 100644 index 0000000..3c6ee76 --- /dev/null +++ b/src/updater/main.py @@ -0,0 +1,26 @@ +import sys +from PyQt5.QtWidgets import QApplication +from updater_window import UpdaterWindow + +def main(): + """ + 更新程序的主程序 + """ + + # 创建应用程序实例 + app = QApplication(sys.argv) + + # 创建更新窗口实例 + window = UpdaterWindow() + + # 显示主窗口 + window.show() + + # 开始更新 + window.start_update() + + # 程序结束 + sys.exit(app.exec_()) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/updater/thread_utils.py b/src/updater/thread_utils.py new file mode 100644 index 0000000..0e96468 --- /dev/null +++ b/src/updater/thread_utils.py @@ -0,0 +1,96 @@ +from PyQt5.QtCore import QThread, pyqtSignal +import requests +import os + + +class DownloadThread(QThread): + """下载进度信号 + --------------------------------------""" + # 进度信号 + progress_signal = pyqtSignal(int) + + # 状态信号 + status_signal = pyqtSignal(str) + + # 完成信号 + finished_signal = pyqtSignal(bool) + + # 版本检查信号 + version_check_signal = pyqtSignal(dict) + """ 下载进度信号 end + -------------------------------------- """ + + def __init__(self, api_url, download_url, save_path): + super().__init__() + self.download_url = download_url + self.save_path = save_path + self.api_url = api_url + self.release_info = None + + def run(self): + try: + self.status_signal.emit("准备更新...") + + # 获取发布信息 + response = requests.get(self.api_url) + response.raise_for_status() + self.release_info = response.json() + + # 发送版本检查信号 + self.version_check_signal.emit(self.release_info) + + # 开始下载 + self.status_signal.emit("准备开始下载...") + + # 下载到临时文件 + temp_path = f"{self.save_path}.tmp" + + # 开始流下载文件 + response = requests.get(self.download_url, stream=True) + print(response) + + # 获取文件大小 + total_size = int(response.headers.get("content-length", 0)) + + if total_size == 0: + self.status_signal.emit("无法获取文件大小") + self.finished_signal.emit(False) + return + + # 每次下载的块大小 + block_size = 1024 + + # 已下载大小 + downloaded = 0 + + with open(temp_path, "wb") as f: + for data in response.iter_content(block_size): + downloaded += len(data) + f.write(data) + + # 计算下载进度 + progress = int((downloaded / total_size) * 100) + + # 发送下载进度信号 + self.progress_signal.emit(progress) + + # 发送状态信号 + self.status_signal.emit(f"下载中... {progress}%") + + # 下载完成后替换文件 + if os.path.exists(self.save_path): + os.remove(self.save_path) + os.rename(temp_path, self.save_path) + + # 发送完成状态信号 + self.status_signal.emit("更新完成!") + + # 发送完成信号 + self.finished_signal.emit(True) + + except requests.exceptions.SSLError: + self.status_signal.emit("下载失败,请检查网络") + self.finished_signal.emit(False) + except Exception as e: + self.status_signal.emit(f"更新失败: {str(e)}") + self.finished_signal.emit(False) diff --git a/src/updater/updater.ico b/src/updater/updater.ico new file mode 100644 index 0000000..0b93191 Binary files /dev/null and b/src/updater/updater.ico differ diff --git a/src/updater/updater.spec b/src/updater/updater.spec new file mode 100644 index 0000000..f6f516f --- /dev/null +++ b/src/updater/updater.spec @@ -0,0 +1,46 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + +a = Analysis( + [ + 'main.py', + 'D:/dev/XDU_WallNut/src/updater/updater_window.py', + 'D:/dev/XDU_WallNut/src/updater/thread_utils.py', + ], # 此项目中所有的 python 脚本 + pathex=['D:\\dev\\XDU_WallNut\\src\\updater'], # 项目绝对路径 + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False +) + +pyz = PYZ( + a.pure, a.zipped_data, + cipher=block_cipher +) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='Updater', # 打包程序的名字 + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + icon='D:/dev/XDU_WallNut/src/updater/updater.ico', # 图标路径 + console=False , + distpath='D:/dev/XDU_WallNut/dist', # 打包输出路径 +) \ No newline at end of file diff --git a/src/updater/updater_window.py b/src/updater/updater_window.py new file mode 100644 index 0000000..be66cf7 --- /dev/null +++ b/src/updater/updater_window.py @@ -0,0 +1,122 @@ +from PyQt5.QtWidgets import QMainWindow, QProgressBar, QLabel, QVBoxLayout, QWidget +from PyQt5.QtCore import Qt +import os +import sys +import json +from thread_utils import DownloadThread + + +class UpdaterWindow(QMainWindow): + def __init__(self): + super().__init__() + + # 初始化 UI + self.initUI() + + def initUI(self): + """ + 初始化更新窗口的 UI + UI 总体布局: + | - windows title ----------------------------- | + | status label | + | ///////////// progress bar 50% /// | + | version label | + | ------------- error label ------------------- | + """ + + # 设置窗口标题 + self.setWindowTitle("XDU WallNut 更新程序") + + # 设置窗口大小 + self.setFixedSize(800, 150) + + # 设置中央主窗口部件 layout + main_window = QWidget() + self.setCentralWidget(main_window) + layout = QVBoxLayout(main_window) + + # 状态标签 + self.status_label = QLabel("正在初始化...") + self.status_label.setAlignment(Qt.AlignCenter) + layout.addWidget(self.status_label) + + # 进度条 + self.progress_bar = QProgressBar() + layout.addWidget(self.progress_bar) + + # 版本信息标签 + self.version_label = QLabel() + self.version_label.setAlignment(Qt.AlignCenter) + layout.addWidget(self.version_label) + + def start_update(self): + """ + 开始更新 + """ + try: + with open("version.json", "r", encoding="utf-8") as f: + current_version = json.load(f)["version"] + except Exception as e: + current_version = "未知" + self.version_label.setText(f"获取当前版本失败: {e}") + + self.version_label.setText(f"当前版本: {current_version}") + + # 获取程序路径 + if getattr(sys, "frozen", False): + app_path = os.path.dirname(sys.executable) + else: + app_path = os.path.dirname(os.path.abspath(__file__)) + + exe_path = os.path.join(app_path, "XDU_WallNut.exe") + + # 创建下载线程 + self.download_thread = DownloadThread( + "https://api.github.com/repos/Yang-ZhiHang/XDU-WallNut/releases/latest", + "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/latest/download/XDU_WallNut.exe", + exe_path, + ) + + # 检查版本 + def check_version(release_info): + latest_version = release_info.get("tag_name", "").replace("v", "") + if current_version != "未知" and current_version == latest_version: + self.status_label.setText("当前已是最新版本") + return False + return True + + # 连接信号 + self.download_thread.progress_signal.connect(self.progress_bar.setValue) + self.download_thread.status_signal.connect(self.status_label.setText) + self.download_thread.finished_signal.connect(self.update_finished) + self.download_thread.version_check_signal.connect(check_version) + + # 启动下载 + self.download_thread.start() + + def update_finished(self, success): + """ + 更新完成,保存版本信息,重启主程序,关闭更新器 + """ + if success and hasattr(self.download_thread, "release_info"): + # 提取并保存版本信息 + release_info = self.download_thread.release_info + version_data = { + "version": release_info.get("tag_name", "").replace("v", ""), + "author": release_info.get("author", ""), + "name": release_info.get("name", ""), + "published_at": release_info.get("published_at", ""), + "description": release_info.get("body", ""), + } + + try: + with open("version.json", "w", encoding="utf-8") as f: + json.dump(version_data, f, ensure_ascii=False, indent=4) + except Exception as e: + print(f"保存版本信息失败: {e}") + + # 重启主程序 + os.startfile("XDU_WallNut.exe") + + # 关闭更新器 + sys.exit() diff --git a/src/updater/version.json b/src/updater/version.json new file mode 100644 index 0000000..98f72b6 --- /dev/null +++ b/src/updater/version.json @@ -0,0 +1,27 @@ +{ + "version": "1.2.2", + "author": { + "login": "Yang-ZhiHang", + "id": 152758723, + "node_id": "U_kgDOCRrpww", + "avatar_url": "https://avatars.githubusercontent.com/u/152758723?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Yang-ZhiHang", + "html_url": "https://github.com/Yang-ZhiHang", + "followers_url": "https://api.github.com/users/Yang-ZhiHang/followers", + "following_url": "https://api.github.com/users/Yang-ZhiHang/following{/other_user}", + "gists_url": "https://api.github.com/users/Yang-ZhiHang/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Yang-ZhiHang/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Yang-ZhiHang/subscriptions", + "organizations_url": "https://api.github.com/users/Yang-ZhiHang/orgs", + "repos_url": "https://api.github.com/users/Yang-ZhiHang/repos", + "events_url": "https://api.github.com/users/Yang-ZhiHang/events{/privacy}", + "received_events_url": "https://api.github.com/users/Yang-ZhiHang/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "name": "v1.2.2", + "published_at": "2024-11-17T15:42:45Z", + "description": "## 🚀更新概况🚀\r\n\r\n- 修复了字体自适应问题" +} \ No newline at end of file diff --git a/ui/components/console_section.py b/ui/components/console_section.py deleted file mode 100644 index 145742c..0000000 --- a/ui/components/console_section.py +++ /dev/null @@ -1,12 +0,0 @@ -from PyQt5.QtWidgets import QTextEdit - -class ConsoleSection(QTextEdit): - def __init__(self): - super().__init__() - - # 设置只读 - self.setReadOnly(True) - - # 设置占位符 - self.setPlaceholderText("控制台输出将显示在这里...") - \ No newline at end of file