diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfd5f2f..0b25f67 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,25 +3,31 @@ name: Running tests on: push: pull_request: + types: + - opened + - synchronize permissions: contents: read jobs: - build-and-deploy: + run_tests: runs-on: ubuntu-latest - + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.13' + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - cd gui + cd ./Gui/ python -m pip install --upgrade pip - pip install -r tests/requirements.txt + pip install -r ./tests/requirements.txt - name: Test🔍 run: | + python --version pytest diff --git a/Gui/check_update.py b/Gui/check_update.py index c686ae2..cf50e22 100644 --- a/Gui/check_update.py +++ b/Gui/check_update.py @@ -44,12 +44,12 @@ def get_value_by_indices(data, indices_list): keys_update = None # 检察更新的函数 -def get_version(website: str='github', include_prerelease: bool=False) -> str | None: +def get_version(include_prerelease: bool=False) -> str | None: '''获取最新的版本号''' if keys is None: - return get_lang('b2'), -1 + return [get_lang('b2'), -1] if web_data is None: - return get_lang('b1'), -1 + return [get_lang('b1'), -1] try: web = web_data['api_web'] @@ -58,8 +58,8 @@ def get_version(website: str='github', include_prerelease: bool=False) -> str | else_data = web_data['addtional_info'] releases_tag_condition = web_data['releases_tag_condition'] condition = eval(web_data['condition']) - except Exception as e: - return format_exc(), -1 + except Exception: + return [format_exc(), -1] try: # 获取版本号 @@ -73,27 +73,25 @@ def get_version(website: str='github', include_prerelease: bool=False) -> str | latest_tag = get_value_by_indices(releases, releases_tag_condition) return latest_tag except Exception: - return format_exc(), -1, -1 + return [format_exc(), -1, -1] def check_update( - use_website = 'github', include_prerelease=False ): '''检查更新''' # 获取版本号 installed_version = __version__ version = get_version( - use_website, include_prerelease, ) + version.append(version[0]) version[0] = re.sub(r'-re\d+$', '', version[0]) # 去除结尾重制版标志 latest_version = version[0] version_update_info = version[1] version_data = version[2] - latest_version if version_update_info == -1: # 出错 - return latest_version, -1, -1 + return latest_version, -1, -1, -1 # 获取哈希 if web_data['has_hash']: @@ -116,7 +114,7 @@ def check_update( else: needs_update = False - return needs_update, latest_version, version_update_info, hash_data + return [needs_update, latest_version, version_update_info, hash_data, version[-1]] def download_file(url, save_path): ''' diff --git a/Gui/main.py b/Gui/main.py index f892d91..0cecd0a 100644 --- a/Gui/main.py +++ b/Gui/main.py @@ -1056,12 +1056,17 @@ def on_check_update(self): # 检查更新 self.update_checked = True if should_check_update_res: - self.check_update_thread = QtThread(check_update, args=('github', True)) + self.check_update_thread = QtThread(check_update, args=(False,)) self.check_update_thread.finished.connect(self.on_check_update_result) self.check_update_thread.start() else: logger.info('使用缓存检查更新') self.on_check_update_result(update_cache) + + def save(self): + '''保存更新缓存''' + if should_check_update_res: + save_update_cache(should_update=result[0], latest_version=result[1], update_info=result[2], hash=result[3], update_version_tag=result[4]) # 缓存最新版本 def on_check_update_result(self, check_data): '''检查更新结果''' @@ -1071,14 +1076,17 @@ def on_check_update_result(self, check_data): if should_check_update_res: result = check_data else: - result = (update_cache['should_update'], update_cache['latest_version'], None, update_cache['hash']) # 使用缓存 + result = [update_cache['should_update'], update_cache['latest_version'], None, update_cache['hash'], update_cache['update_version_tag']] # 使用缓存 + + if result[3] is None and web_data['has_hash']: # 哈希为空,但是有哈希属性,说明这个版本没有发布的编译压缩包 + self.save() + result[0] = False # 因为没有最新版本,没有编译后版本,所以认为不需要更新 + return # 检查结果处理 if settings.get('update_notify', 0) in {0}: # 判断是否需要弹出通知 if result[1] != -1: # -1表示函数出错 - if should_check_update_res: - save_update_cache(should_update=result[0], latest_version=result[1], update_info=result[2], hash=result[3]) # 缓存最新版本 - pass + self.save() if result[0]: # 检查到需要更新 logger.info('检查到更新') # 弹出更新窗口 @@ -1092,8 +1100,7 @@ def on_check_update_result(self, check_data): MessageBox.critical(self, get_lang('14'), f'{get_lang('18')}\n{result[0]}') else: if result[1] != -1: - if should_check_update_res: - save_update_cache(should_update=result[0], latest_version=result[1], update_info=result[2], hash=result[3]) + self.save() def on_update(self, judge = False): '''显示更新提示''' @@ -1921,7 +1928,7 @@ def on_update(self): try: self.close() os.rename('updater', 'updater.old') - self.down_thread = QtThread(download_file, args=(web_data['down_web'].format(latest_version=result[1]), 'updater.old/clickmouse.7z')) + self.down_thread = QtThread(download_file, args=(web_data['down_web'].format(latest_version=result[4]), 'updater.old/clickmouse.7z')) self.down_thread.finished.connect(self.on_update_finished) self.down_thread.start() except: diff --git a/Gui/res/versions.json b/Gui/res/versions.json index a9083bb..cc0684e 100644 --- a/Gui/res/versions.json +++ b/Gui/res/versions.json @@ -1 +1 @@ -{"package_format_version": "1.2.0", "clickmouse":"3.2.0.18beta6"} +{"package_format_version": "1.2.0", "clickmouse":"3.2.0.18beta7"}