feat: 优化程序交互提示

This commit is contained in:
JoeanAmier 2024-12-29 11:00:04 +08:00
parent 1d2731b93a
commit 63c8a9e325
7 changed files with 36 additions and 29 deletions

View File

@ -26,7 +26,7 @@ class About(Screen):
description=_("退出程序")),
Binding(
key="U",
action="check_update",
action="update",
description=_("检查更新")),
Binding(
key="B",
@ -76,5 +76,5 @@ class About(Screen):
async def action_back(self) -> None:
await self.app.action_back()
async def action_check_update(self):
await self.app.run_action("update_and_return")
async def action_update(self):
await self.app.run_action("update")

View File

@ -95,18 +95,12 @@ class XHSDownloader(App):
self.install_screen(Record(self.APP, ), name="record")
await self.push_screen("index")
def update_result(self, tip: str) -> None:
log = self.query_one(RichLog)
log.write(tip)
log.write(">" * 50)
def update_result(self, args: tuple[str, str]) -> None:
self.notify(args[0], severity=args[1], )
async def action_update(self):
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):
await self.APP.id_recorder.cursor.close()
await self.APP.id_recorder.database.close()

View File

@ -76,7 +76,7 @@ class Index(Screen):
Button(_("清空输入框"), id="reset"),
),
)
yield RichLog(markup=True, wrap=True, )
yield RichLog(markup=True, wrap=True, auto_scroll=True, )
yield Footer()
def on_mount(self) -> None:
@ -91,6 +91,7 @@ class Index(Screen):
50}",
style=MASTER),
animate=True,
scroll_end=True,
)
self.xhs.manager.print_proxy_tip(log=self.tip, )
@ -102,10 +103,12 @@ class Index(Screen):
self.tip.write(
Text(_("未输入任何小红书作品链接"), style=WARNING),
animate=True,
scroll_end=True,
)
self.tip.write(
Text(">" * 50, style=GENERAL),
animate=True,
scroll_end=True,
)
@on(Button.Pressed, "#reset")
@ -125,10 +128,12 @@ class Index(Screen):
self.tip.write(
Text(_("下载小红书作品文件失败"), style=ERROR),
animate=True,
scroll_end=True,
)
self.tip.write(
Text(">" * 50, style=GENERAL),
animate=True,
scroll_end=True,
)
await self.app.action_back()

View File

@ -52,7 +52,10 @@ class Monitor(Screen):
self.query_one(RichLog).write(
Text(_(
"程序会自动读取并提取剪贴板中的小红书作品链接,并自动下载链接对应的作品文件,如需关闭,请点击关闭按钮,或者向剪贴板写入 “close” 文本!"),
style=MASTER))
style=MASTER),
animate=True,
scroll_end=True,
)
self.run_monitor()
async def action_close(self):

View File

@ -31,6 +31,7 @@ class Record(ModalScreen):
async def delete(self, text: str):
await self.xhs.id_recorder.delete(text)
self.app.notify(_("删除下载记录成功"))
@on(Button.Pressed, "#enter")
async def save_settings(self):

View File

@ -1,4 +1,3 @@
from rich.text import Text
from textual import work
from textual.app import ComposeResult
from textual.containers import Grid
@ -8,9 +7,6 @@ from textual.widgets import LoadingIndicator
from ..application import XHS
from ..module import (
ERROR,
WARNING,
INFO,
RELEASES,
)
from ..translation import _
@ -37,25 +33,33 @@ class Update(ModalScreen):
version = url.split("/")[-1]
match self.compare_versions(f"{XHS.VERSION_MAJOR}.{XHS.VERSION_MINOR}", version, XHS.VERSION_BETA):
case 4:
tip = Text(f"{_("检测到新版本:{0}.{1}").format(
XHS.VERSION_MAJOR, XHS.VERSION_MINOR)}\n{RELEASES}", style=WARNING)
args = (
_("检测到新版本:{0}.{1}").format(
XHS.VERSION_MAJOR,
XHS.VERSION_MINOR,
),
"warning",
)
case 3:
tip = Text(
f"{_("当前版本为开发版, 可更新至正式版")}\n{RELEASES}",
style=WARNING)
args = (
_("当前版本为开发版, 可更新至正式版"),
"warning",
)
case 2:
tip = Text(
args = (
_("当前已是最新开发版"),
style=WARNING)
"warning",
)
case 1:
tip = Text(
args = (
_("当前已是最新正式版"),
style=INFO)
"information",
)
case _:
raise ValueError
except ValueError:
tip = Text(_("检测新版本失败"), style=ERROR)
self.dismiss(tip)
args = (_("检测新版本失败"), "error",)
self.dismiss(args)
def on_mount(self) -> None:
self.check_update()

View File

@ -22,7 +22,7 @@ def retry(function):
def logging(log, text, style=INFO):
string = Text(text, style=style)
if log:
log.write(string, animate=True, )
log.write(string, animate=True, scroll_end=True, )
else:
print(string)