mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
feat: 优化程序交互提示
This commit is contained in:
@@ -26,7 +26,7 @@ class About(Screen):
|
|||||||
description=_("退出程序")),
|
description=_("退出程序")),
|
||||||
Binding(
|
Binding(
|
||||||
key="U",
|
key="U",
|
||||||
action="check_update",
|
action="update",
|
||||||
description=_("检查更新")),
|
description=_("检查更新")),
|
||||||
Binding(
|
Binding(
|
||||||
key="B",
|
key="B",
|
||||||
@@ -76,5 +76,5 @@ class About(Screen):
|
|||||||
async def action_back(self) -> None:
|
async def action_back(self) -> None:
|
||||||
await self.app.action_back()
|
await self.app.action_back()
|
||||||
|
|
||||||
async def action_check_update(self):
|
async def action_update(self):
|
||||||
await self.app.run_action("update_and_return")
|
await self.app.run_action("update")
|
||||||
|
|||||||
@@ -95,18 +95,12 @@ class XHSDownloader(App):
|
|||||||
self.install_screen(Record(self.APP, ), name="record")
|
self.install_screen(Record(self.APP, ), name="record")
|
||||||
await self.push_screen("index")
|
await self.push_screen("index")
|
||||||
|
|
||||||
def update_result(self, tip: str) -> None:
|
def update_result(self, args: tuple[str, str]) -> None:
|
||||||
log = self.query_one(RichLog)
|
self.notify(args[0], severity=args[1], )
|
||||||
log.write(tip)
|
|
||||||
log.write(">" * 50)
|
|
||||||
|
|
||||||
async def action_update(self):
|
async def action_update(self):
|
||||||
await self.push_screen(Update(self.APP, ), callback=self.update_result)
|
await self.push_screen(Update(self.APP, ), callback=self.update_result)
|
||||||
|
|
||||||
async def action_update_and_return(self):
|
|
||||||
await self.action_back()
|
|
||||||
await self.action_update()
|
|
||||||
|
|
||||||
async def close_database(self):
|
async def close_database(self):
|
||||||
await self.APP.id_recorder.cursor.close()
|
await self.APP.id_recorder.cursor.close()
|
||||||
await self.APP.id_recorder.database.close()
|
await self.APP.id_recorder.database.close()
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class Index(Screen):
|
|||||||
Button(_("清空输入框"), id="reset"),
|
Button(_("清空输入框"), id="reset"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
yield RichLog(markup=True, wrap=True, )
|
yield RichLog(markup=True, wrap=True, auto_scroll=True, )
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
@@ -91,6 +91,7 @@ class Index(Screen):
|
|||||||
50}",
|
50}",
|
||||||
style=MASTER),
|
style=MASTER),
|
||||||
animate=True,
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
)
|
)
|
||||||
self.xhs.manager.print_proxy_tip(log=self.tip, )
|
self.xhs.manager.print_proxy_tip(log=self.tip, )
|
||||||
|
|
||||||
@@ -102,10 +103,12 @@ class Index(Screen):
|
|||||||
self.tip.write(
|
self.tip.write(
|
||||||
Text(_("未输入任何小红书作品链接"), style=WARNING),
|
Text(_("未输入任何小红书作品链接"), style=WARNING),
|
||||||
animate=True,
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
)
|
)
|
||||||
self.tip.write(
|
self.tip.write(
|
||||||
Text(">" * 50, style=GENERAL),
|
Text(">" * 50, style=GENERAL),
|
||||||
animate=True,
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@on(Button.Pressed, "#reset")
|
@on(Button.Pressed, "#reset")
|
||||||
@@ -125,10 +128,12 @@ class Index(Screen):
|
|||||||
self.tip.write(
|
self.tip.write(
|
||||||
Text(_("下载小红书作品文件失败"), style=ERROR),
|
Text(_("下载小红书作品文件失败"), style=ERROR),
|
||||||
animate=True,
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
)
|
)
|
||||||
self.tip.write(
|
self.tip.write(
|
||||||
Text(">" * 50, style=GENERAL),
|
Text(">" * 50, style=GENERAL),
|
||||||
animate=True,
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
)
|
)
|
||||||
await self.app.action_back()
|
await self.app.action_back()
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,10 @@ class Monitor(Screen):
|
|||||||
self.query_one(RichLog).write(
|
self.query_one(RichLog).write(
|
||||||
Text(_(
|
Text(_(
|
||||||
"程序会自动读取并提取剪贴板中的小红书作品链接,并自动下载链接对应的作品文件,如需关闭,请点击关闭按钮,或者向剪贴板写入 “close” 文本!"),
|
"程序会自动读取并提取剪贴板中的小红书作品链接,并自动下载链接对应的作品文件,如需关闭,请点击关闭按钮,或者向剪贴板写入 “close” 文本!"),
|
||||||
style=MASTER))
|
style=MASTER),
|
||||||
|
animate=True,
|
||||||
|
scroll_end=True,
|
||||||
|
)
|
||||||
self.run_monitor()
|
self.run_monitor()
|
||||||
|
|
||||||
async def action_close(self):
|
async def action_close(self):
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class Record(ModalScreen):
|
|||||||
|
|
||||||
async def delete(self, text: str):
|
async def delete(self, text: str):
|
||||||
await self.xhs.id_recorder.delete(text)
|
await self.xhs.id_recorder.delete(text)
|
||||||
|
self.app.notify(_("删除下载记录成功"))
|
||||||
|
|
||||||
@on(Button.Pressed, "#enter")
|
@on(Button.Pressed, "#enter")
|
||||||
async def save_settings(self):
|
async def save_settings(self):
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from rich.text import Text
|
|
||||||
from textual import work
|
from textual import work
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
from textual.containers import Grid
|
from textual.containers import Grid
|
||||||
@@ -8,9 +7,6 @@ from textual.widgets import LoadingIndicator
|
|||||||
|
|
||||||
from ..application import XHS
|
from ..application import XHS
|
||||||
from ..module import (
|
from ..module import (
|
||||||
ERROR,
|
|
||||||
WARNING,
|
|
||||||
INFO,
|
|
||||||
RELEASES,
|
RELEASES,
|
||||||
)
|
)
|
||||||
from ..translation import _
|
from ..translation import _
|
||||||
@@ -37,25 +33,33 @@ class Update(ModalScreen):
|
|||||||
version = url.split("/")[-1]
|
version = url.split("/")[-1]
|
||||||
match self.compare_versions(f"{XHS.VERSION_MAJOR}.{XHS.VERSION_MINOR}", version, XHS.VERSION_BETA):
|
match self.compare_versions(f"{XHS.VERSION_MAJOR}.{XHS.VERSION_MINOR}", version, XHS.VERSION_BETA):
|
||||||
case 4:
|
case 4:
|
||||||
tip = Text(f"{_("检测到新版本:{0}.{1}").format(
|
args = (
|
||||||
XHS.VERSION_MAJOR, XHS.VERSION_MINOR)}\n{RELEASES}", style=WARNING)
|
_("检测到新版本:{0}.{1}").format(
|
||||||
|
XHS.VERSION_MAJOR,
|
||||||
|
XHS.VERSION_MINOR,
|
||||||
|
),
|
||||||
|
"warning",
|
||||||
|
)
|
||||||
case 3:
|
case 3:
|
||||||
tip = Text(
|
args = (
|
||||||
f"{_("当前版本为开发版, 可更新至正式版")}\n{RELEASES}",
|
_("当前版本为开发版, 可更新至正式版"),
|
||||||
style=WARNING)
|
"warning",
|
||||||
|
)
|
||||||
case 2:
|
case 2:
|
||||||
tip = Text(
|
args = (
|
||||||
_("当前已是最新开发版"),
|
_("当前已是最新开发版"),
|
||||||
style=WARNING)
|
"warning",
|
||||||
|
)
|
||||||
case 1:
|
case 1:
|
||||||
tip = Text(
|
args = (
|
||||||
_("当前已是最新正式版"),
|
_("当前已是最新正式版"),
|
||||||
style=INFO)
|
"information",
|
||||||
|
)
|
||||||
case _:
|
case _:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
except ValueError:
|
except ValueError:
|
||||||
tip = Text(_("检测新版本失败"), style=ERROR)
|
args = (_("检测新版本失败"), "error",)
|
||||||
self.dismiss(tip)
|
self.dismiss(args)
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
self.check_update()
|
self.check_update()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def retry(function):
|
|||||||
def logging(log, text, style=INFO):
|
def logging(log, text, style=INFO):
|
||||||
string = Text(text, style=style)
|
string = Text(text, style=style)
|
||||||
if log:
|
if log:
|
||||||
log.write(string, animate=True, )
|
log.write(string, animate=True, scroll_end=True, )
|
||||||
else:
|
else:
|
||||||
print(string)
|
print(string)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user