feat(utils): 更新器优化
- 更新信息样式优化 - 更新器支持动态获取下载站
This commit is contained in:
@@ -171,19 +171,23 @@ class ProgressRingMessageBox(MessageBoxBase):
|
||||
class NoticeMessageBox(MessageBoxBase):
|
||||
"""公告对话框"""
|
||||
|
||||
def __init__(self, parent, content: Dict[str, str]):
|
||||
def __init__(self, parent, title: str, content: Dict[str, str]):
|
||||
super().__init__(parent)
|
||||
|
||||
self.index = self.NoticeIndexCard(content, self)
|
||||
self.index = self.NoticeIndexCard(title, content, self)
|
||||
self.text = TextBrowser(self)
|
||||
self.text.setOpenExternalLinks(True)
|
||||
self.button = PrimaryPushButton("确认", self)
|
||||
self.button_yes = PrimaryPushButton("确认", self)
|
||||
self.button_cancel = PrimaryPushButton("取消", self)
|
||||
|
||||
self.buttonGroup.hide()
|
||||
|
||||
self.v_layout = QVBoxLayout()
|
||||
self.v_layout.addWidget(self.text)
|
||||
self.v_layout.addWidget(self.button)
|
||||
self.button_layout = QHBoxLayout()
|
||||
self.button_layout.addWidget(self.button_yes)
|
||||
self.button_layout.addWidget(self.button_cancel)
|
||||
self.v_layout.addLayout(self.button_layout)
|
||||
|
||||
self.h_layout = QHBoxLayout()
|
||||
self.h_layout.addWidget(self.index)
|
||||
@@ -196,7 +200,8 @@ class NoticeMessageBox(MessageBoxBase):
|
||||
self.widget.setFixedSize(800, 600)
|
||||
|
||||
self.index.index_changed.connect(self.__update_text)
|
||||
self.button.clicked.connect(self.yesButton.click)
|
||||
self.button_yes.clicked.connect(self.yesButton.click)
|
||||
self.button_cancel.clicked.connect(self.cancelButton.click)
|
||||
self.index.index_cards[0].clicked.emit()
|
||||
|
||||
def __update_text(self, text: str):
|
||||
@@ -219,9 +224,9 @@ class NoticeMessageBox(MessageBoxBase):
|
||||
|
||||
index_changed = Signal(str)
|
||||
|
||||
def __init__(self, content: Dict[str, str], parent=None):
|
||||
def __init__(self, title: str, content: Dict[str, str], parent=None):
|
||||
super().__init__(parent)
|
||||
self.setTitle("公告")
|
||||
self.setTitle(title)
|
||||
|
||||
self.Layout = QVBoxLayout()
|
||||
self.viewLayout.addLayout(self.Layout)
|
||||
@@ -229,18 +234,6 @@ class NoticeMessageBox(MessageBoxBase):
|
||||
|
||||
self.index_cards: List[QuantifiedItemCard] = []
|
||||
|
||||
if content:
|
||||
self.index_cards.append(QuantifiedItemCard(["ALL", ""]))
|
||||
self.index_cards[-1].clicked.connect(
|
||||
lambda: self.index_changed.emit(
|
||||
"\n---\n".join(
|
||||
[str(_) for _ in content.values() if isinstance(_, str)]
|
||||
)
|
||||
)
|
||||
)
|
||||
self.Layout.addWidget(self.index_cards[-1])
|
||||
else:
|
||||
self.Layout.addWidget(QuantifiedItemCard(["暂无公告", ""]))
|
||||
for index, text in content.items():
|
||||
|
||||
self.index_cards.append(QuantifiedItemCard([index, ""]))
|
||||
@@ -249,6 +242,9 @@ class NoticeMessageBox(MessageBoxBase):
|
||||
)
|
||||
self.Layout.addWidget(self.index_cards[-1])
|
||||
|
||||
if not content:
|
||||
self.Layout.addWidget(QuantifiedItemCard(["暂无信息", ""]))
|
||||
|
||||
self.Layout.addStretch(1)
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import requests
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Union
|
||||
|
||||
from app.core import Config, MainInfoBar
|
||||
from app.services import Crypto, System
|
||||
@@ -305,7 +306,9 @@ class Setting(QWidget):
|
||||
|
||||
# 从本地版本信息文件获取当前版本信息
|
||||
with Config.version_path.open(mode="r", encoding="utf-8") as f:
|
||||
version_current = json.load(f)
|
||||
version_current: Dict[
|
||||
str, Union[str, Dict[str, Union[str, Dict[str, List[str]]]]]
|
||||
] = json.load(f)
|
||||
main_version_current = list(
|
||||
map(int, version_current["main_version"].split("."))
|
||||
)
|
||||
@@ -322,7 +325,9 @@ class Setting(QWidget):
|
||||
response = requests.get(
|
||||
f"https://gitee.com/DLmaster_361/AUTO_MAA/raw/{Config.global_config.get(Config.global_config.update_UpdateType)}/resources/version.json"
|
||||
)
|
||||
version_remote = response.json()
|
||||
version_remote: Dict[
|
||||
str, Union[str, Dict[str, Union[str, Dict[str, List[str]]]]]
|
||||
] = response.json()
|
||||
break
|
||||
except Exception as e:
|
||||
err = e
|
||||
@@ -360,25 +365,48 @@ class Setting(QWidget):
|
||||
|
||||
# 生成版本更新信息
|
||||
if main_version_remote > main_version_current:
|
||||
main_version_info = f" 主程序:{version_text(main_version_current)} --> {version_text(main_version_remote)}\n"
|
||||
main_version_info = f"## 主程序:{version_text(main_version_current)} --> {version_text(main_version_remote)}\n\n"
|
||||
else:
|
||||
main_version_info = (
|
||||
f" 主程序:{version_text(main_version_current)}\n"
|
||||
f"## 主程序:{version_text(main_version_current)}\n\n"
|
||||
)
|
||||
if updater_version_remote > updater_version_current:
|
||||
updater_version_info = f" 更新器:{version_text(updater_version_current)} --> {version_text(updater_version_remote)}\n"
|
||||
updater_version_info = f"## 更新器:{version_text(updater_version_current)} --> {version_text(updater_version_remote)}\n\n"
|
||||
else:
|
||||
updater_version_info = (
|
||||
f" 更新器:{version_text(updater_version_current)}\n"
|
||||
f"## 更新器:{version_text(updater_version_current)}\n\n"
|
||||
)
|
||||
update_version_info = {}
|
||||
all_version_info = {}
|
||||
for v_i in [
|
||||
info
|
||||
for version, info in version_remote["version_info"].items()
|
||||
if list(map(int, version.split("."))) > main_version_current
|
||||
]:
|
||||
for key, value in v_i.items():
|
||||
if key in update_version_info:
|
||||
update_version_info[key] += value.copy()
|
||||
else:
|
||||
update_version_info[key] = value.copy()
|
||||
for v_i in version_remote["version_info"].values():
|
||||
for key, value in v_i.items():
|
||||
if key in all_version_info:
|
||||
all_version_info[key] += value.copy()
|
||||
else:
|
||||
all_version_info[key] = value.copy()
|
||||
|
||||
version_info = {
|
||||
"更新总览": f"{main_version_info}{updater_version_info}{version_info_markdown(update_version_info)}",
|
||||
"ALL~版本信息": version_info_markdown(all_version_info),
|
||||
**{
|
||||
version_text(list(map(int, k.split(".")))): version_info_markdown(v)
|
||||
for k, v in version_remote["version_info"].items()
|
||||
},
|
||||
}
|
||||
|
||||
# 询问是否开始版本更新
|
||||
if if_question:
|
||||
choice = MessageBox(
|
||||
"版本更新",
|
||||
f"发现新版本:\n{main_version_info}{updater_version_info} 更新说明:\n{version_remote['announcement'].replace("\n# ","\n !").replace("\n## ","\n - ").replace("\n- ","\n · ")}\n\n是否开始更新?\n\n 注意:主程序更新时AUTO_MAA将自动关闭",
|
||||
self.window(),
|
||||
)
|
||||
choice = NoticeMessageBox(self.window(), "版本更新", version_info)
|
||||
if not choice.exec():
|
||||
return None
|
||||
|
||||
@@ -394,6 +422,7 @@ class Setting(QWidget):
|
||||
"proxy_list": Config.global_config.get(
|
||||
Config.global_config.update_ProxyUrlList
|
||||
),
|
||||
"download_dict": version_remote["download_dict"],
|
||||
"thread_numb": Config.global_config.get(
|
||||
Config.global_config.update_ThreadNumb
|
||||
),
|
||||
@@ -461,12 +490,21 @@ class Setting(QWidget):
|
||||
else:
|
||||
time_local = datetime.strptime("2000-01-01 00:00", "%Y-%m-%d %H:%M")
|
||||
|
||||
notice["notice_dict"] = {
|
||||
"ALL~公告": "\n---\n".join(
|
||||
[str(_) for _ in notice["notice_dict"].values() if isinstance(_, str)]
|
||||
),
|
||||
**notice["notice_dict"],
|
||||
}
|
||||
|
||||
if if_show or (
|
||||
datetime.now() > datetime.strptime(notice["time"], "%Y-%m-%d %H:%M")
|
||||
and datetime.strptime(notice["time"], "%Y-%m-%d %H:%M") > time_local
|
||||
):
|
||||
|
||||
choice = NoticeMessageBox(self.window(), notice["notice_dict"])
|
||||
choice = NoticeMessageBox(self.window(), "公告", notice["notice_dict"])
|
||||
choice.button_cancel.hide()
|
||||
choice.button_layout.insertStretch(0, 1)
|
||||
if choice.exec():
|
||||
with (Config.app_path / "resources/notice.json").open(
|
||||
mode="w", encoding="utf-8"
|
||||
@@ -960,3 +998,14 @@ def version_text(version_numb: list) -> str:
|
||||
f"v{'.'.join(str(_) for _ in version_numb[0:3])}-beta.{version_numb[3]}"
|
||||
)
|
||||
return version
|
||||
|
||||
|
||||
def version_info_markdown(info: dict) -> str:
|
||||
"""将版本信息字典转为markdown信息"""
|
||||
|
||||
version_info = ""
|
||||
for key, value in info.items():
|
||||
version_info += f"### {key}\n\n"
|
||||
for v in value:
|
||||
version_info += f"- {v}\n\n"
|
||||
return version_info
|
||||
|
||||
@@ -219,9 +219,10 @@ class DownloadManager(QDialog):
|
||||
url_dict["官方镜像站"] = (
|
||||
f"https://gitee.com/DLmaster_361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
)
|
||||
url_dict["官方下载站"] = (
|
||||
f"https://jp-download.fearr.xyz/AUTO_MAA/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
)
|
||||
for name, download_url_head in self.config["download_dict"].items():
|
||||
url_dict[name] = (
|
||||
f"{download_url_head}AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
)
|
||||
for proxy_url in self.config["proxy_list"]:
|
||||
url_dict[proxy_url] = (
|
||||
f"{proxy_url}https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
@@ -234,33 +235,36 @@ class DownloadManager(QDialog):
|
||||
return f"https://jp-download.fearr.xyz/MAA/MAA-{version_text(self.main_version)}-win-x64.zip"
|
||||
|
||||
if "selected" in self.config:
|
||||
proxy_url = self.config["selected"]
|
||||
selected_url = self.config["selected"]
|
||||
elif "speed_result" in self.config:
|
||||
proxy_url = max(
|
||||
selected_url = max(
|
||||
self.config["speed_result"], key=self.config["speed_result"].get
|
||||
)
|
||||
|
||||
if self.name == "AUTO_MAA主程序":
|
||||
|
||||
if proxy_url == "GitHub站":
|
||||
if selected_url == "GitHub站":
|
||||
return f"https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
elif proxy_url == "官方镜像站":
|
||||
elif selected_url == "官方镜像站":
|
||||
return f"https://gitee.com/DLmaster_361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
elif proxy_url == "官方下载站":
|
||||
return f"https://jp-download.fearr.xyz/AUTO_MAA/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
elif selected_url in self.config["download_dict"].keys():
|
||||
return f"{self.config["download_dict"][selected_url]}AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
else:
|
||||
return f"{proxy_url}https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
return f"{selected_url}https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/AUTO_MAA_{version_text(self.main_version)}.zip"
|
||||
|
||||
elif self.name == "AUTO_MAA更新器":
|
||||
|
||||
if proxy_url == "GitHub站":
|
||||
if selected_url == "GitHub站":
|
||||
return f"https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/Updater_{version_text(self.updater_version)}.zip"
|
||||
elif proxy_url == "官方镜像站":
|
||||
elif selected_url == "官方镜像站":
|
||||
return f"https://gitee.com/DLmaster_361/AUTO_MAA/releases/download/{version_text(self.main_version)}/Updater_{version_text(self.updater_version)}.zip"
|
||||
elif proxy_url == "官方下载站":
|
||||
return f"https://jp-download.fearr.xyz/AUTO_MAA/Updater_{version_text(self.updater_version)}.zip"
|
||||
elif selected_url in self.config["download_dict"].keys():
|
||||
print(
|
||||
f"{self.config["download_dict"][selected_url]}Updater_{version_text(self.updater_version)}.zip"
|
||||
)
|
||||
return f"{self.config["download_dict"][selected_url]}Updater_{version_text(self.updater_version)}.zip"
|
||||
else:
|
||||
return f"{proxy_url}https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/Updater_{version_text(self.updater_version)}.zip"
|
||||
return f"{selected_url}https://github.com/DLmaster361/AUTO_MAA/releases/download/{version_text(self.main_version)}/Updater_{version_text(self.updater_version)}.zip"
|
||||
|
||||
def test_speed_task1(self) -> None:
|
||||
|
||||
@@ -618,6 +622,7 @@ if __name__ == "__main__":
|
||||
# 合并代理列表
|
||||
download_config = {
|
||||
"proxy_list": list(set(proxy_list + remote_proxy_list)),
|
||||
"download_dict": version_remote["download_dict"],
|
||||
"thread_numb": thread_numb,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user