feat(core): 增强离线模式支持和版本管理

- 在主窗口中添加离线模式管理器,支持自动切换到离线模式。
- 更新下载管理器以处理离线模式下的下载逻辑,确保用户体验流畅。
- 添加版本警告机制,提示用户在版本过低时的操作选项。
- 优化配置管理器,确保在离线模式下仍可使用相关功能。
- 更新UI管理器以反映当前工作模式,提升用户界面友好性。
This commit is contained in:
hyb-oyqq
2025-08-06 15:22:44 +08:00
parent b18f4a276c
commit 7befe19f30
17 changed files with 1707 additions and 148 deletions

View File

@@ -18,7 +18,8 @@ class ConfigFetchThread(QThread):
try:
if self.debug_mode:
print("--- Starting to fetch cloud config ---")
print(f"DEBUG: Requesting URL: {self.url}")
# 完全隐藏URL
print(f"DEBUG: Requesting URL: ***URL protection***")
print(f"DEBUG: Using Headers: {self.headers}")
response = requests.get(self.url, headers=self.headers, timeout=10)
@@ -26,7 +27,18 @@ class ConfigFetchThread(QThread):
if self.debug_mode:
print(f"DEBUG: Response Status Code: {response.status_code}")
print(f"DEBUG: Response Headers: {response.headers}")
print(f"DEBUG: Response Text: {response.text}")
# 解析并隐藏响应中的敏感URL
try:
response_data = response.json()
# 创建安全版本用于日志输出
safe_response = self._create_safe_config_for_logging(response_data)
print(f"DEBUG: Response Text: {json.dumps(safe_response, indent=2)}")
except:
# 如果不是JSON直接打印文本
from utils.helpers import censor_url
censored_text = censor_url(response.text)
print(f"DEBUG: Response Text: {censored_text}")
response.raise_for_status()
@@ -62,4 +74,28 @@ class ConfigFetchThread(QThread):
self.finished.emit(None, error_msg)
finally:
if self.debug_mode:
print("--- Finished fetching cloud config ---")
print("--- Finished fetching cloud config ---")
def _create_safe_config_for_logging(self, config_data):
"""创建用于日志记录的安全配置副本隐藏敏感URL
Args:
config_data: 原始配置数据
Returns:
dict: 安全的配置数据副本
"""
if not config_data or not isinstance(config_data, dict):
return config_data
# 创建深拷贝,避免修改原始数据
import copy
safe_config = copy.deepcopy(config_data)
# 隐藏敏感URL
for key in safe_config:
if isinstance(safe_config[key], dict) and "url" in safe_config[key]:
# 完全隐藏URL
safe_config[key]["url"] = "***URL protection***"
return safe_config

View File

@@ -200,7 +200,15 @@ class DownloadThread(QThread):
command.append(self.url)
print(f"即将执行的 Aria2c 命令: {' '.join(command)}")
# 创建一个安全的命令副本隐藏URL
safe_command = command.copy()
if len(safe_command) > 0:
# 替换最后一个参数URL为安全版本
url = safe_command[-1]
if isinstance(url, str) and url.startswith("http"):
safe_command[-1] = "***URL protection***"
print(f"即将执行的 Aria2c 命令: {' '.join(safe_command)}")
creation_flags = subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding='utf-8', errors='replace', creationflags=creation_flags)
@@ -220,8 +228,11 @@ class DownloadThread(QThread):
else:
break
full_output.append(line)
print(line.strip())
# 处理输出行隐藏可能包含的URL
from utils.helpers import censor_url
censored_line = censor_url(line)
full_output.append(censored_line)
print(censored_line.strip())
match = progress_pattern.search(line)
if match:

View File

@@ -30,6 +30,9 @@ class IpOptimizer:
ip_txt_path = resource_path("ip.txt")
# 隐藏敏感URL
safe_url = "***URL protection***"
command = [
cst_path,
"-n", "1000", # 延迟测速线程数
@@ -39,10 +42,17 @@ class IpOptimizer:
"-dd", # 禁用下载测速
"-o"," " # 不写入结果文件
]
# 创建用于显示的安全命令副本
safe_command = command.copy()
for i, arg in enumerate(safe_command):
if arg == url:
safe_command[i] = safe_url
creation_flags = subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
print("--- CloudflareSpeedTest 开始执行 ---")
print(f"执行命令: {' '.join(safe_command)}")
self.process = subprocess.Popen(
command,
@@ -91,7 +101,9 @@ class IpOptimizer:
timeout_counter = 0
cleaned_line = line.strip()
# 处理输出行隐藏可能包含的URL
from utils.helpers import censor_url
cleaned_line = censor_url(line.strip())
if cleaned_line:
print(cleaned_line)
@@ -157,6 +169,9 @@ class IpOptimizer:
print(f"错误: ipv6.txt 未在资源路径中找到。")
return None
# 隐藏敏感URL
safe_url = "***URL protection***"
command = [
cst_path,
"-n", "1000", # 延迟测速线程数
@@ -166,10 +181,17 @@ class IpOptimizer:
"-dd", # 禁用下载测速
"-o", " " # 不写入结果文件
]
# 创建用于显示的安全命令副本
safe_command = command.copy()
for i, arg in enumerate(safe_command):
if arg == url:
safe_command[i] = safe_url
creation_flags = subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
print("--- CloudflareSpeedTest IPv6 开始执行 ---")
print(f"执行命令: {' '.join(safe_command)}")
self.process = subprocess.Popen(
command,
@@ -218,7 +240,9 @@ class IpOptimizer:
timeout_counter = 0
cleaned_line = line.strip()
# 处理输出行隐藏可能包含的URL
from utils.helpers import censor_url
cleaned_line = censor_url(line.strip())
if cleaned_line:
print(cleaned_line)