diff --git a/docs/DESKTOP_UPDATE.md b/docs/DESKTOP_UPDATE.md new file mode 100644 index 0000000..49f04f9 --- /dev/null +++ b/docs/DESKTOP_UPDATE.md @@ -0,0 +1,82 @@ +# 桌面版在线更新:方案与落地清单(2026-11-17) + +> 现状:设置 → 通用 已有「版本与更新」区块(版本号 + 「检查更新」按钮)。 +> 按钮会检测 `window.__TAURI__.updater`;插件装上并配好更新源后自动生效,现在点它只会提示"尚未启用"。 + +## 一、三种方案 + +| 方案 | 用户体验 | 需要什么 | 适合 | +|---|---|---|---| +| **A. Tauri 官方 updater** | 应用内检查→下载→自动替换→重启 | 更新源(HTTPS 静态) + 一对签名密钥 + 发布流程 | 要发给别人 | +| B. 手动下载 | 去网盘/Release 下新包替换 | 一个能放包的地方 | 自用、低频 | +| C. 只提示(自研检查) | 提示"有新版本"+下载链接,不自动装 | 一个 version.json | 轻量折中 | + +**建议**:现在自用 → 先做 **C**(零密钥、能及时知道);要发给别人再升 A。 + +## 二、A 方案要素 + +### 1. 依赖 +```bash +# Cargo.toml: tauri-plugin-updater = "2" +npm i @tauri-apps/plugin-updater +``` +lib.rs: `.plugin(tauri_plugin_updater::Builder::new().build())`;capabilities 加 `"updater:default"` + +### 2. 签名密钥(一次生成,永久保管) +```bash +npx tauri signer generate -w ~/.tauri/image-workbench.key +``` +私钥绝不进仓库;公钥写进 `plugins.updater.pubkey`。 +**丢了私钥 = 老用户永远收不到更新。** + +### 3. 配置 +```json +{ + "plugins": { "updater": { + "pubkey": "<公钥>", + "endpoints": ["https://<域名>/image-workbench/latest.json"] + } }, + "bundle": { "createUpdaterArtifacts": true } +} +``` + +### 4. 清单 latest.json +```json +{ + "version": "3.25.0", + "notes": "…", + "pub_date": "2026-11-17T10:00:00Z", + "platforms": { + "darwin-aarch64": { "signature": "", "url": "…app.tar.gz" }, + "windows-x86_64": { "signature": "", "url": "…nsis.zip" } + } +} +``` + +### 5. 构建带签名 +```bash +TAURI_SIGNING_PRIVATE_KEY=... TAURI_SIGNING_PRIVATE_KEY_PASSWORD=... npm run app:build +``` +产出 `*.app.tar.gz(.sig)` / `*.nsis.zip(.sig)`,与清单一起上传。 + +### 6. 托管选择 +| 位置 | 可行 | 注意 | +|---|---|---| +| GitHub Releases | ✅ | 私有库资产需匿名可读 | +| Cloudflare R2/Pages | ✅ | 公开读 + HTTPS | +| 飞牛 NAS / Gitea | ⚠️ | 必须公网 HTTPS 且免鉴权;私有库要 token ⇒ 不可用 | + +## 三、现在就该定的事 +1. 版本号三处一致(tauri.conf / Cargo / package.json),每次发布递增 +2. macOS 要出 aarch64 + x64 两套;Windows 出 x64 +3. 私钥本机签还是 CI 签 + +## 四、C 方案(建议先做) +1. 静态放 `version.json`:`{version, notes, url}` +2. 「检查更新」改成 HTTP GET 比对版本,有新版给下载链接 +3. 零密钥、零签名、不影响安装包 + +## 五、现状 +- ✅ 通用页已显示版本号 + 检查更新按钮 +- ⬜ 待你定:A 还是 C +- 提醒:未签名的 macOS 应用即使更新成功,首次打开仍有 Gatekeeper 提示;要消除需 Apple Developer ID($99/年),不影响自用。 diff --git a/src/ui-settings-modal.js b/src/ui-settings-modal.js index d2d4a46..315aaf6 100644 --- a/src/ui-settings-modal.js +++ b/src/ui-settings-modal.js @@ -435,6 +435,7 @@ function SettingsModal(props) { const imgTab = el('div', null, transferSection) const generalTab = Sections ? Sections.renderGeneralTab({ imageLibSection: imageLibSection, + appVersion: APP_VERSION, GEN_CONCURRENCY_DEFAULT, GEN_CONCURRENCY_MAX, GEN_CONCURRENCY_MIN, TASK_STALL_END_MAX, TASK_STALL_END_MIN, applyTheme, draft, setDraft, setTheme, theme, }) : el('div', { className: 'iwb-hint' }, 'generalTab 未就绪(请刷新页面)') const updateSizePreset = (index, patch) => setDraft((d) => { diff --git a/src/ui-settings-sections.js b/src/ui-settings-sections.js index 95d51d8..e2c0a93 100644 --- a/src/ui-settings-sections.js +++ b/src/ui-settings-sections.js @@ -74,6 +74,45 @@ return pluginsTab } + // 版本与更新(独立组件:自己持有提示状态,不污染 generalTab 的 hook 顺序) + function VersionBlock (props) { + const version = props && props.version ? String(props.version) : '' + const [msg, setMsg] = React.useState('') + const check = async () => { + try { + const U = (typeof window !== 'undefined' && window.__TAURI__ && window.__TAURI__.updater) ? window.__TAURI__.updater : null + if (!U || typeof U.check !== 'function') { + setMsg('在线更新尚未启用:需要配置更新源地址与签名公钥(见 docs/DESKTOP_UPDATE.md)') + return + } + setMsg('正在检查…') + const u = await U.check() + if (!u) { setMsg('已是最新版本'); return } + setMsg('发现新版本 ' + (u.version || '') + ',点「立即更新」下载安装') + window.__IWB_UPDATE__ = u + } catch (e) { setMsg('检查失败:' + String((e && e.message) || e)) } + } + const install = async () => { + try { + const u = window.__IWB_UPDATE__ + if (!u || typeof u.downloadAndInstall !== 'function') { setMsg('没有可安装的更新'); return } + setMsg('正在下载安装…') + await u.downloadAndInstall() + setMsg('安装完成,请重启应用') + } catch (e) { setMsg('更新失败:' + String((e && e.message) || e)) } + } + return el('div', null, + el('div', { className: 'iwb-section-sub' }, '版本与更新'), + el('div', { className: 'iwb-row' }, + el('span', { className: 'iwb-label' }, '版本'), + el('span', { className: 'iwb-hint', style: { flex: '1 1 auto' } }, version || '未知'), + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: check }, '检查更新'), + window.__IWB_UPDATE__ ? el('button', { className: 'iwb-btn iwb-btn-sm', onClick: install }, '立即更新') : null, + ), + el('div', { className: 'iwb-hint' }, '当前为本地目录版;在线更新需要「更新源 + 签名密钥」两样东西配好才会生效。'), + msg ? el('div', { className: 'iwb-hint' }, msg) : null, + ) + } // 桌面端专属:默认下载文件夹。独立组件持有 useState ⇒ 不干扰 generalTab 的 hook 顺序。 function DownloadDirBlock () { const D = (typeof window !== 'undefined') ? window.IWBDesktop : null @@ -169,7 +208,7 @@ } function renderGeneralTab (ctx) { - const { TASK_STALL_END_MAX, TASK_STALL_END_MIN, applyTheme, draft, imageLibSection, setDraft, setTheme, theme } = ctx + const { TASK_STALL_END_MAX, TASK_STALL_END_MIN, appVersion, applyTheme, draft, imageLibSection, setDraft, setTheme, theme } = ctx const generalTab = el('div', { className: 'iwb-section' }, el('div', { className: 'iwb-section-title' }, '数据与目录'), // 桌面端才有目录概念;网页版退回原来的浏览器说明 @@ -194,6 +233,8 @@ el('div', { style: { height: 16 } }), // 原「图片保存」页并入这里(定时清理已去掉) imageLibSection || null, + el('div', { style: { height: 16 } }), + el(VersionBlock, { version: appVersion }), // 桌面端没有服务端、也没有「浏览器本地模式」这回事 ⇒ 整段不渲染 isDesk() ? null : el('div', { className: 'iwb-section-sub' }, '访问口令'), isDesk() ? null : el('div', { className: 'iwb-hint' }, '口令是服务端(Node 版 image-workbench-app)的 Basic Auth 功能;当前为浏览器本地模式(数据存在你的浏览器),页面与数据本就只在本机,无需设置口令。'),