diff --git a/web/src/apply.ts b/web/src/apply.ts index eb7e255..59cecb3 100644 --- a/web/src/apply.ts +++ b/web/src/apply.ts @@ -1,5 +1,5 @@ import { exec, shellQuote, toast } from './ksu'; -import { copyFont, pickWghtRange, renderSlots, slots } from './slots'; +import { copyFont, pickWghtRange, renderSlots, setApplying, slots } from './slots'; import { applyWghtOverride, getSelectedWghtMode, writeWghtMode } from './wght'; import { invalidateTestFonts } from './testFonts'; import { applyBtn } from './dom'; @@ -14,7 +14,7 @@ document.getElementById('log-close')?.addEventListener('click', () => { async function apply() { if (!slots.hans.path) return; - applyBtn.disabled = true; + setApplying(true); renderSlots(); try { // 字重范围覆写: 用 UI 当前模式 (持久化到 FONTS/wght-mode.txt), 仅当存在可变字体且模式非 0 时处理 @@ -76,7 +76,7 @@ async function apply() { } catch (e) { toast(`应用失败: ${String(e)}`); } finally { - applyBtn.disabled = false; + setApplying(false); renderSlots(); } } diff --git a/web/src/slots.ts b/web/src/slots.ts index e0a5347..e91a77b 100644 --- a/web/src/slots.ts +++ b/web/src/slots.ts @@ -49,6 +49,12 @@ const wghtModeSub = document.getElementById('wght-mode-sub'); let pickingKey: SlotKey = 'hans'; +// 应用流程进行中: renderSlots 据此禁用/启用应用按钮 +export let applying = false; +export function setApplying(v: boolean): void { + applying = v; +} + const picker = new FontFilePicker((path, name) => { const slot = slots[pickingKey]; slot.path = path; @@ -140,8 +146,9 @@ export function renderSlots() { }); if (applyBtn) { - // 未选择简体字体时直接隐藏按钮 (不做半透明禁用) + // 未选择简体字体时直接隐藏按钮 (不做半透明禁用); 应用过程中禁用 applyBtn.style.display = !slots.hans.path ? 'none' : ''; + applyBtn.disabled = applying; } updateWghtModeDisabled(); // 通知其他模块 (如字重映射预览) 槽位已变化