Files
XHS_Downloader/source/TUI/update.py
JoeanAmier 3e8b69f8e1 fix: 修复项目功能异常
1. 更新 Cookie 参数处理
2. 优化作品数据返回格式
3. 更新用户脚本链接提取功能
4. 优化项目运行信息提示
5. 修复 record_data 参数无效的问题
6. 新增作品下载记录开关
7. 适配小红书平台规则
8. 默认开启局域网访问
9. 格式化项目代码
10. 更新英语翻译

Closes #127
Closes #128
Closes #130
Closes #132
2024-08-03 14:30:35 +08:00

81 lines
2.6 KiB
Python

from typing import Callable
from rich.text import Text
from textual import work
from textual.app import ComposeResult
from textual.containers import Grid
from textual.screen import ModalScreen
from textual.widgets import Label
from textual.widgets import LoadingIndicator
from source.application import XHS
from source.module import (
ERROR,
WARNING,
INFO,
RELEASES,
)
__all__ = ["Update"]
class Update(ModalScreen):
def __init__(self, app: XHS, message: Callable[[str], str]):
super().__init__()
self.xhs = app
self.message = message
def compose(self) -> ComposeResult:
yield Grid(
Label(self.message("正在检查新版本,请稍等...")),
LoadingIndicator(),
classes="loading",
)
@work()
async def check_update(self) -> None:
try:
url = await self.xhs.html.request_url(RELEASES, False, None, timeout=5, )
version = url.split("/")[-1]
match self.compare_versions(f"{XHS.VERSION_MAJOR}.{XHS.VERSION_MINOR}", version, XHS.VERSION_BETA):
case 4:
tip = Text(f"{self.message("检测到新版本:{0}.{1}").format(
XHS.VERSION_MAJOR, XHS.VERSION_MINOR)}\n{RELEASES}", style=WARNING)
case 3:
tip = Text(
f"{self.message("当前版本为开发版, 可更新至正式版")}\n{RELEASES}",
style=WARNING)
case 2:
tip = Text(
self.message("当前已是最新开发版"),
style=WARNING)
case 1:
tip = Text(
self.message("当前已是最新正式版"),
style=INFO)
case _:
raise ValueError
except ValueError:
tip = Text(self.message("检测新版本失败"), style=ERROR)
self.dismiss(tip)
def on_mount(self) -> None:
self.check_update()
@staticmethod
def compare_versions(
current_version: str,
target_version: str,
is_development: bool) -> int:
current_major, current_minor = map(int, current_version.split('.'))
target_major, target_minor = map(int, target_version.split('.'))
if target_major > current_major:
return 4
if target_major == current_major:
if target_minor > current_minor:
return 4
if target_minor == current_minor:
return 3 if is_development else 1
return 2