diff --git a/app/core/config.py b/app/core/config.py index 3642ff6..dce5b78 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -262,6 +262,7 @@ class GlobalConfig(LQConfig): self.update_ThreadNumb = RangeConfigItem( "Update", "ThreadNumb", 8, RangeValidator(1, 32) ) + self.update_ProxyAddress = ConfigItem("Update", "ProxyAddress", "") self.update_ProxyUrlList = ConfigItem( "Update", "ProxyUrlList", [], UrlListValidator() ) @@ -706,7 +707,7 @@ class GeneralSubConfig(LQConfig): class AppConfig(GlobalConfig): - VERSION = "4.4.0.5" + VERSION = "4.4.0.6" stage_refreshed = Signal() PASSWORD_refreshed = Signal() @@ -780,7 +781,6 @@ class AppConfig(GlobalConfig): self.init_logger() self.check_data() - self.get_stage() logger.info("程序初始化完成") def init_logger(self) -> None: @@ -810,8 +810,8 @@ class AppConfig(GlobalConfig): logger.info("日志记录器初始化完成") def get_stage(self) -> None: + """从MAA服务器获取活动关卡信息""" - # 从MAA服务器获取活动关卡信息 network = Network.add_task( mode="get", url="https://api.maa.plus/MaaAssistantArknights/api/gui/StageActivity.json", diff --git a/app/core/network.py b/app/core/network.py index 15e3a26..003145a 100644 --- a/app/core/network.py +++ b/app/core/network.py @@ -30,6 +30,7 @@ from PySide6.QtCore import QObject, QThread, QEventLoop import re import time import requests +import truststore from pathlib import Path @@ -51,12 +52,21 @@ class NetworkThread(QThread): self.url = url self.path = path + from .config import Config + + self.proxies = { + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + } + self.status_code = None self.response_json = None self.error_message = None self.loop = QEventLoop() + truststore.inject_into_ssl() + @logger.catch def run(self) -> None: """运行网络请求线程""" @@ -73,7 +83,7 @@ class NetworkThread(QThread): for _ in range(self.max_retries): try: - response = requests.get(url, timeout=self.timeout) + response = requests.get(url, timeout=self.timeout, proxies=self.proxies) self.status_code = response.status_code self.response_json = response.json() self.error_message = None @@ -92,7 +102,7 @@ class NetworkThread(QThread): response = None try: - response = requests.get(url, timeout=10) + response = requests.get(url, timeout=10, proxies=self.proxies) if response.status_code == 200: with open(path, "wb") as file: file.write(response.content) diff --git a/app/services/notification.py b/app/services/notification.py index 6ea440d..56ddf04 100644 --- a/app/services/notification.py +++ b/app/services/notification.py @@ -199,7 +199,16 @@ class Notification(QObject): params = {"title": title, "desp": content, **options} headers = {"Content-Type": "application/json;charset=utf-8"} - response = requests.post(url, json=params, headers=headers, timeout=10) + response = requests.post( + url, + json=params, + headers=headers, + timeout=10, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, + ) result = response.json() if result.get("code") == 0: @@ -244,6 +253,10 @@ class Notification(QObject): url=webhook_url, json=data, timeout=10, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ) info = response.json() break @@ -307,7 +320,7 @@ class Notification(QObject): image_base64 = ImageUtils.get_base64_from_file(str(image_path)) image_md5 = ImageUtils.calculate_md5_from_file(str(image_path)) except Exception as e: - logger.error(f"图片编码或MD5计算失败:{e}") + logger.exception(f"图片编码或MD5计算失败:{e}") self.push_info_bar.emit( "error", "企业微信群机器人通知推送异常", @@ -327,6 +340,10 @@ class Notification(QObject): url=webhook_url, json=data, timeout=10, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ) info = response.json() break diff --git a/app/services/skland.py b/app/services/skland.py index c49724e..d752662 100644 --- a/app/services/skland.py +++ b/app/services/skland.py @@ -40,6 +40,8 @@ import hashlib import requests from urllib import parse +from app.core import Config + def skland_sign_in(token) -> dict: """森空岛签到""" @@ -137,7 +139,13 @@ def skland_sign_in(token) -> dict: # 通过grant code换cred和sign_token def get_cred(grant): rsp = requests.post( - cred_code_url, json={"code": grant, "kind": 1}, headers=header_login + cred_code_url, + json={"code": grant, "kind": 1}, + headers=header_login, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ).json() if rsp["code"] != 0: raise Exception(f'获得cred失败:{rsp.get("messgae")}') @@ -151,6 +159,10 @@ def skland_sign_in(token) -> dict: grant_code_url, json={"appCode": app_code, "token": token, "type": 0}, headers=header_login, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ).json() if rsp["status"] != 0: raise Exception( @@ -172,6 +184,10 @@ def skland_sign_in(token) -> dict: headers=get_sign_header( binding_url, "get", None, copy_header(cred), sign_token ), + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ).json() if rsp["code"] != 0: logger.error(f"森空岛服务 | 请求角色列表出现问题:{rsp['message']}") @@ -209,6 +225,10 @@ def skland_sign_in(token) -> dict: sign_url, "post", body, copy_header(cred), sign_token ), json=body, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ).json() if rsp["code"] != 0: diff --git a/app/ui/downloader.py b/app/ui/downloader.py index bebc307..ae3aac1 100644 --- a/app/ui/downloader.py +++ b/app/ui/downloader.py @@ -30,7 +30,6 @@ import zipfile import requests import subprocess import time -import psutil from functools import partial from pathlib import Path @@ -47,6 +46,7 @@ from PySide6.QtCore import QThread, Signal, QTimer, QEventLoop from typing import List, Dict, Union +from app.core import Config from app.services import System @@ -113,7 +113,14 @@ class DownloadProcess(QThread): start_time = time.time() response = requests.get( - self.url, headers=headers, timeout=10, stream=True + self.url, + headers=headers, + timeout=10, + stream=True, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ) if response.status_code not in [200, 206]: @@ -332,6 +339,10 @@ class DownloadManager(QDialog): allow_redirects=True, timeout=10, stream=True, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ) as response: if response.status_code == 200: return response.url @@ -339,7 +350,14 @@ class DownloadManager(QDialog): elif self.config["mode"] == "MirrorChyan": with requests.get( - self.config["url"], allow_redirects=True, timeout=10, stream=True + self.config["url"], + allow_redirects=True, + timeout=10, + stream=True, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, ) as response: if response.status_code == 200: return response.url @@ -448,7 +466,14 @@ class DownloadManager(QDialog): url = self.get_download_url("下载") self.downloaded_size_list: List[List[int, bool]] = [] - response = requests.head(url, timeout=10) + response = requests.head( + url, + timeout=10, + proxies={ + "http": Config.get(Config.update_ProxyAddress), + "https": Config.get(Config.update_ProxyAddress), + }, + ) self.file_size = int(response.headers.get("content-length", 0)) part_size = self.file_size // self.config["thread_numb"] diff --git a/app/ui/main_window.py b/app/ui/main_window.py index 595c751..3a97d12 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -361,6 +361,9 @@ class AUTO_MAA(MSFluentWindow): # 检查密码 self.setting.check_PASSWORD() + # 获取关卡号信息 + Config.get_stage() + # 获取主题图像 if Config.get(Config.function_HomeImageMode) == "主题图像": self.home.get_home_image() diff --git a/app/ui/setting.py b/app/ui/setting.py index 68d049e..71c35c7 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -1164,6 +1164,15 @@ class UpdaterSettingCard(HeaderCardWidget): configItem=Config.update_ThreadNumb, parent=self, ) + self.card_ProxyAddress = LineEditSettingCard( + icon=FluentIcon.PAGE_RIGHT, + title="网络代理地址", + content="使用网络代理软件时,若出现网络连接问题,请尝试设置代理地址,此设置全局生效", + text="请输入代理地址", + qconfig=Config, + configItem=Config.update_ProxyAddress, + parent=self, + ) self.card_ProxyUrlList = UrlListSettingCard( icon=FluentIcon.SETTING, title="代理地址列表", @@ -1196,6 +1205,7 @@ class UpdaterSettingCard(HeaderCardWidget): Layout.addWidget(self.card_IfAutoUpdate) Layout.addWidget(self.card_UpdateType) Layout.addWidget(self.card_ThreadNumb) + Layout.addWidget(self.card_ProxyAddress) Layout.addWidget(self.card_ProxyUrlList) Layout.addWidget(self.card_MirrorChyanCDK) self.viewLayout.addLayout(Layout) diff --git a/requirements.txt b/requirements.txt index 9448234..ab2ff4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ pywin32==310 keyboard==0.13.5 pycryptodome==3.23.0 certifi==2025.4.26 +truststore==0.10.1 requests==2.32.4 markdown==3.8.2 Jinja2==3.1.6 diff --git a/resources/version.json b/resources/version.json index 3226b06..e363cd9 100644 --- a/resources/version.json +++ b/resources/version.json @@ -1,6 +1,11 @@ { - "main_version": "4.4.0.5", + "main_version": "4.4.0.6", "version_info": { + "4.4.0.6": { + "修复BUG": [ + "信任系统证书,并添加网络代理地址配置项 #50" + ] + }, "4.4.0.5": { "新增功能": [ "添加导入导出通用配置功能"