Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions file-toolkit/core/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""应用版本与许可证 — 运行时从 pyproject.toml 读取,避免界面上的版本号与发布版本脱节。

flet build 打包时 pyproject.toml 会随源码一起放进应用(而应用本身不是已安装的发行包,
importlib.metadata 取不到),所以直接读文件。
"""
import tomllib
from functools import cache
from pathlib import Path

_PYPROJECT = Path(__file__).parent.parent / "pyproject.toml"


@cache
def _project() -> dict:
try:
with _PYPROJECT.open("rb") as f:
return tomllib.load(f).get("project", {})
except (OSError, tomllib.TOMLDecodeError):
return {}


def app_version() -> str:
"""如 "1.1.0";读取失败时返回 "未知"。"""
return _project().get("version", "未知")


def app_license() -> str:
"""如 "Apache-2.0"。"""
lic = _project().get("license", {})
return lic.get("text", "") if isinstance(lic, dict) else str(lic)
2 changes: 1 addition & 1 deletion file-toolkit/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "file-toolkit"
version = "1.0.0"
version = "1.1.0"
description = "File Toolkit — Local file processing desktop application"
readme = { text = "File Toolkit — Local file processing desktop application", content-type = "text/plain" }
requires-python = ">=3.11"
Expand Down
14 changes: 14 additions & 0 deletions file-toolkit/tests/core/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""core.version 从 pyproject.toml 读取版本"""
import tomllib
from pathlib import Path

from core.version import app_license, app_version


def test_version_matches_pyproject():
data = tomllib.loads((Path(__file__).parents[2] / "pyproject.toml").read_text(encoding="utf-8"))
assert app_version() == data["project"]["version"]


def test_license_is_apache():
assert app_license() == "Apache-2.0"
5 changes: 3 additions & 2 deletions file-toolkit/ui/pages/settings_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""设置页 — Figma 设计语言统一"""
import flet as ft

from core.version import app_license, app_version
from services import settings_service
from services.prompt_image_service import DEFAULT_BASE_URL, DEFAULT_MODEL
from ui.palette import c
Expand Down Expand Up @@ -303,8 +304,8 @@ async def _test_ai_image_connection_async(self) -> None:
# ── 关于 ──────────────────────────────────────────────────────────
def _build_about(self) -> ft.Control:
return self._card("关于", ft.Icons.INFO_OUTLINED, c("#005f98"), c("#dee9ff"), [
self._row("版本", ft.Text("v1.0.0(Windows MVP)", size=13, color=c("#455c7f", "fg"))),
self._row("开源协议", ft.Text("MIT License", size=13, color=c("#455c7f", "fg"))),
self._row("版本", ft.Text(f"v{app_version()}", size=13, color=c("#455c7f", "fg"))),
self._row("开源协议", ft.Text(app_license() or "Apache-2.0", size=13, color=c("#455c7f", "fg"))),
])

# ── 通用布局 ──────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion file-toolkit/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading