release: v3.26.95 真实升级进度环 + 浏览器收藏夹栏

This commit is contained in:
qiqi committed 2026-11-25 23:43:25 +08:00
1 parent 0ebe5a853c
commit 6d2280a75c
10 files changed
+205 -49

No files matched your search

+59 -8
View File
@@ -21,13 +21,34 @@
const useEffect = React.useEffect
// 升级图标(圆形内向上箭头):ICONS 在 app.js 里且行数已到棘轮上限,这里内联一份,不动宿主。
const UPGRADE_PATH = '<circle cx="12" cy="12" r="9"/><path d="M12 16V8"/><path d="m8.5 11.5 3.5-3.5 3.5 3.5"/>'
// v3.26.95:升级中**箭头不转**,外圈变成真实下载进度环(一圈闭合),进度来自 updater 的 on_chunk。
const RING_R = 9
const RING_C = 2 * Math.PI * RING_R
function UpgradeIcon (props) {
const pp = props || {}
const upgrading = !!pp.upgrading
const pct = (typeof pp.progress === 'number' && isFinite(pp.progress)) ? Math.max(0, Math.min(100, pp.progress)) : null
const indeterminate = upgrading && pct === null
const circle = {
cx: 12, cy: 12, r: RING_R, fill: 'none', stroke: 'currentColor', strokeWidth: 2,
transform: 'rotate(-90 12 12)',
}
return el('svg', {
className: 'iwb-ic' + ((props && props.spinning) ? ' iwb-nav-up-spin' : ''), viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
className: 'iwb-ic iwb-nav-up-ic', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
dangerouslySetInnerHTML: { __html: UPGRADE_PATH },
}, null)
},
upgrading ? el('circle', Object.assign({}, circle, { className: 'iwb-nav-up-track', opacity: 0.22 }), null) : null,
upgrading
? el('circle', Object.assign({}, circle, {
className: 'iwb-nav-up-bar' + (indeterminate ? ' iwb-nav-up-indet' : ''),
strokeLinecap: 'round',
strokeDasharray: indeterminate ? '10 47' : RING_C,
strokeDashoffset: indeterminate ? 0 : RING_C * (1 - pct / 100),
}), null)
: el('circle', circle, null),
el('path', { d: 'M12 16V8' }, null),
el('path', { d: 'm8.5 11.5 3.5-3.5 3.5 3.5' }, null),
)
}
// 「更多」菜单里的首页/插件是**网站页面**,不是软件内部页面(用户 2026-11-25 澄清);
@@ -67,7 +88,9 @@
const [morePos, setMorePos] = useState(null)
const [update, setUpdate] = useState(null) // null=无更新;{version,...}=有新版本
const [updateMsg, setUpdateMsg] = useState('')
const [upgrading, setUpgrading] = useState(false) // 升级中:箭头转圈(2026-11-26)
const [upgrading, setUpgrading] = useState(false) // 升级中:外圈进度环(v3.26.95)
const [updateProgress, setUpdateProgress] = useState(null) // 0~100;null = 不知道总大小
const [updatePhase, setUpdatePhase] = useState('') // 'downloading' | 'installing'
const checkUpdate = () => {
setUpdateMsg('正在检查…')
@@ -86,10 +109,37 @@
const upgrade = () => {
if (upgrading) return
setUpgrading(true)
setUpdateProgress(0)
setUpdatePhase('downloading')
setUpdateMsg('正在下载并安装,完成后会自动重启…')
invoke('install_update').then(() => setUpdateMsg('安装完成,正在重启…'))
.catch((e) => { setUpgrading(false); setUpdateMsg('更新失败:' + String((e && e.message) || e)) })
.catch((e) => { setUpgrading(false); setUpdateProgress(null); setUpdatePhase(''); setUpdateMsg('更新失败:' + String((e && e.message) || e)) })
}
// Rust 侧 updater 的 on_chunk 通过 iwb-update-progress 事件回报真实字节数。
// 只显示下载阶段;安装阶段没有字节进度,环走满并显示「正在安装…」。
useEffect(() => {
if (!upgrading) return undefined
let off = null
let cancelled = false
try {
const T = (typeof window !== 'undefined') ? window.__TAURI__ : null
if (T && T.event && typeof T.event.listen === 'function') {
T.event.listen('iwb-update-progress', (ev) => {
if (cancelled) return
const d = (ev && ev.payload) || {}
if (d.phase === 'installing') { setUpdatePhase('installing'); setUpdateProgress(100); return }
if (d.phase === 'downloading') {
setUpdatePhase('downloading')
const total = Number(d.total) || 0
const done = Number(d.downloaded) || 0
if (total > 0) setUpdateProgress(Math.max(1, Math.min(99, Math.round(done / total * 100))))
else setUpdateProgress(null)
}
}).then((f) => { if (cancelled) { try { f() } catch (e) { /* ignore */ } } else off = f }).catch(() => { /* 事件通道不可用:退回不确定态 */ })
}
} catch (e) { /* ignore */ }
return () => { cancelled = true; if (off) { try { off() } catch (e) { /* ignore */ } } }
}, [upgrading])
useEffect(() => {
if (!moreOpen) return undefined
const onDown = (e) => { if (!e.target.closest || !e.target.closest('.iwb-nav-more-menu, .iwb-nav-more-btn')) setMoreOpen(false) }
@@ -120,13 +170,14 @@
key, type: 'button', className: 'iwb-ctx-item' + (cls ? ' ' + cls : ''), onClick, title: title || text,
}, iconNode, el('span', null, text))
const upgradingText = updatePhase === 'installing' ? '正在安装…' : ('正在下载…' + (typeof updateProgress === 'number' ? ' ' + updateProgress + '%' : ''))
const menu = !moreOpen || !morePos ? null : ReactDOM.createPortal(
el('div', {
className: 'iwb-ctxmenu iwb-nav-more-menu',
style: { left: morePos.left + 'px', bottom: morePos.bottom + 'px' },
onPointerDown: (e) => e.stopPropagation(),
},
update ? menuItem('up', el(UpgradeIcon, { spinning: upgrading }), (upgrading ? '正在升级… ' : '升级到 v') + update.version + (!upgrading && update.notes ? ':' + update.notes : ''), act(upgrade), 'iwb-nav-more-up' + (upgrading ? ' iwb-nav-more-up-busy' : '')) : null,
update ? menuItem('up', el(UpgradeIcon, { upgrading, progress: updateProgress }), upgrading ? upgradingText : ('升级到 v' + update.version + (update.notes ? ':' + update.notes : '')), act(upgrade), 'iwb-nav-more-up' + (upgrading ? ' iwb-nav-more-up-busy' : '')) : null,
// 首页 / 插件 / 源码地址:全部打开**网站**(用户 2026-11-25 裁定),不再切软件内页面
menuItem('home', I('home'), '首页', act(() => openWeb(WEB_HOME)), null, '在浏览器打开官网首页 ' + WEB_HOME),
menuItem('plugins', I('box'), '插件', act(() => openWeb(WEB_PLUGINS)), null, '在浏览器打开插件市场 ' + WEB_PLUGINS),
@@ -159,7 +210,7 @@
'aria-expanded': moreOpen ? 'true' : 'false',
onPointerDown: (e) => e.stopPropagation(),
onClick: (e) => { e.stopPropagation(); toggleMore(e) },
}, update ? el(UpgradeIcon, { spinning: upgrading }) : I('more')),
}, update ? el(UpgradeIcon, { upgrading, progress: updateProgress }) : I('more')),
),
),
menu,