feat(update): 在线升级 —— 界面一键检查版本、自动覆盖安装并重启

老板要求:软件里点「在线升级」校验版本号,直接在线覆盖安装、重启;
升级服务放在 https://md.wangjinding.com。

一、服务端(md.wangjinding.com)
  · 升级清单 GET /update/latest.json(nginx 单独 location,强制 no-store,带 CORS)
      { version, notes, pub_date, platforms.windows-x86_64: { signature, url, size, sha256 } }
  · 安装包走现有 /download/;另加稳定别名 latest-setup.exe / latest-portable.exe
    —— 官网页固定链到别名,以后发版不用改 HTML
  · tools/release/publish.py:一条命令完成「拷安装包 → 写清单 → 更新别名 → 打校验值」
  · 官网页的版本号改成从 latest.json 拉(data-ver),发版后自动跟随

二、客户端(Tauri updater 官方插件,不是自己下 exe 硬跑)
  · 新增 tauri-plugin-updater + tauri-plugin-process
  · 命令 check_update() → { available, current, version, notes, date }
         install_update() → 下载 + 校验签名 + 静默覆盖安装 + restart
  · 签名用 minisign:私钥 /root/.tauri/xiaoyin-md-updater.key(600,**不在仓库里**),
    公钥写进 tauri.conf.json;安装包被篡改会被客户端直接拒装
  · 工具条新增升级按钮(仅 Tauri 版显示);点击 → 查版本 → 有新版弹窗(带更新说明)
    → 「立即升级」显示下载进度条 → 装完自动重启
  · 版本号 2.6.1 → 2.6.2

三、已验证
  · 构建出 XiaoyinMarkdown_2.6.2_x64-setup.exe(2.21 MB)+ .sig(448B)
  · 用 cryptography 按 minisign 规则**真验了一遍签名**:Ed25519 + BLAKE2b 预哈希 → 通过
  · /update/latest.json 200 / application/json / no-store;sha256 与清单一致
  · latest-setup.exe / latest-portable.exe 均 200

注意:2.6.1 是**没有升级器**的版本,老用户要手动装一次 2.6.2;
    从 2.6.2 起才能在软件里一键升级。
This commit is contained in:
Jidekin committed 2026-11-20 10:22:26 +08:00
1 parent f53abeb0c8
commit 44335d02f2
10 files changed
+893 -27

No files matched your search

+4
View File
@@ -80,6 +80,10 @@
<span id="openmode-label">标签</span>
</button>
<button class="tb-icon" id="btn-update" title="检查更新 / 在线升级" hidden>
<svg viewBox="0 0 16 16"><path d="M7.25 1.4h1.5v6.15l2.29-2.3 1.06 1.07L8 10.5 3.9 6.32 4.96 5.25l2.29 2.3V1.4zM2 11h1.5v2.5h9V11H14v4H2v-4z"/></svg>
</button>
<button class="tb-icon" id="btn-theme" title="切换深色/浅色 (Ctrl+Shift+L)">
<svg viewBox="0 0 16 16"><path d="M8 1a7 7 0 100 14A7 7 0 008 1zm0 1.5v11a5.5 5.5 0 010-11z"/></svg>
</button>
+89
View File
@@ -158,6 +158,95 @@
}
});
/* ---------- 在线升级(服务端:https://md.wangjinding.com/update/latest.json) ---------- */
const updateBtn = document.getElementById('btn-update');
if (updateBtn) {
updateBtn.hidden = false;
updateBtn.addEventListener('click', runUpdate);
}
/* 升级进度浮层 */
function progressUI(title) {
const mask = document.createElement('div');
mask.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,.32);z-index:99998;'
+ 'display:flex;align-items:center;justify-content:center;font-family:system-ui,sans-serif;';
const box = document.createElement('div');
box.style.cssText = 'background:#fff;color:#222;border-radius:12px;padding:24px 26px;'
+ 'width:380px;box-shadow:0 20px 60px rgba(0,0,0,.3);';
const t = document.createElement('div');
t.style.cssText = 'font-size:14px;font-weight:600;margin-bottom:14px;';
t.textContent = title;
const track = document.createElement('div');
track.style.cssText = 'height:6px;border-radius:4px;background:#eceef3;overflow:hidden;';
const bar = document.createElement('div');
bar.style.cssText = 'height:100%;width:6%;background:linear-gradient(90deg,#3a7bfc,#0b66dd);'
+ 'transition:width .25s ease;';
track.appendChild(bar);
const sub = document.createElement('div');
sub.style.cssText = 'margin-top:10px;font-size:12.5px;color:#7a8494;';
sub.textContent = '正在下载…';
box.append(t, track, sub);
mask.appendChild(box);
document.body.appendChild(mask);
return {
set(p) {
if (!p) return;
if (p.done) { bar.style.width = '100%'; sub.textContent = '安装完成,正在重启…'; return; }
const d = p.downloaded || 0;
const total = p.total || 0;
if (total > 0) {
bar.style.width = Math.min(100, (d / total) * 100).toFixed(1) + '%';
sub.textContent = `${(d / 1048576).toFixed(1)} / ${(total / 1048576).toFixed(1)} MB`;
} else {
sub.textContent = `${(d / 1048576).toFixed(1)} MB`;
}
},
close() { mask.remove(); },
};
}
async function runUpdate() {
if (!updateBtn || updateBtn.disabled) return;
updateBtn.disabled = true;
try {
const st = await invoke('check_update');
if (!st || !st.available) {
await modalDialog({
message: '已是最新版本',
detail: `当前版本 v${(st && st.current) || ''}`,
buttons: ['好'],
});
return;
}
const lines = [`当前 v${st.current} → 新版本 v${st.version}`];
if (st.date) lines.push(`发布时间:${st.date}`);
if (st.notes) lines.push('', '更新说明:', st.notes);
const pick = await modalDialog({
message: `发现新版本 v${st.version}`,
detail: lines.join('\n'),
buttons: ['立即升级', '稍后'],
});
if (pick !== 0) return;
const ui = progressUI(`正在升级到 v${st.version}…`);
let un = null;
try {
un = await listen('update-progress', (e) => ui.set(e.payload));
await invoke('install_update');
ui.set({ done: true });
} catch (e) {
if (un) un();
ui.close();
await modalDialog({ message: '升级失败', detail: String((e && e.message) || e), buttons: ['好'] });
}
} catch (e) {
await modalDialog({ message: '检查更新失败', detail: String((e && e.message) || e), buttons: ['好'] });
} finally {
updateBtn.disabled = false;
}
}
/* ---------- 拖放(Tauri 系统级,拿得到真实路径) ---------- */
cur.onDragDropEvent((e) => {
const p = e.payload;