From ebfe7b5d171ddc30cff64e264af5b05daaa90d01 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Tue, 7 Jul 2026 15:14:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2):=20O?= =?UTF-8?q?FDGo=20WebUI=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E6=9D=83=E9=99=90=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/index.html | 1 + assets/webui/ofdgo.css | 10 ++++++++++ assets/webui/ofdgo.js | 42 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/assets/webui/index.html b/assets/webui/index.html index 13fce55..3871800 100644 --- a/assets/webui/index.html +++ b/assets/webui/index.html @@ -101,6 +101,7 @@ +
diff --git a/assets/webui/ofdgo.css b/assets/webui/ofdgo.css index 88ce242..b18ee29 100644 --- a/assets/webui/ofdgo.css +++ b/assets/webui/ofdgo.css @@ -652,6 +652,16 @@ body[data-hide-meta] .meta-panel { gap: 8px; } +.font-permission-hint { + margin: 0 0 8px; + padding: 7px 8px; + border: 1px solid var(--line); + background: #ffffff; + color: var(--text-muted); + font-size: 12px; + line-height: 1.35; +} + .font-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index fc7f183..4680148 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -53,6 +53,7 @@ const state = { localFonts: [], userFonts: [], systemFontCatalog: [], + systemFontPermission: "prompt", doc: null, pageIndex: 0, scale: 1, @@ -108,6 +109,7 @@ const el = { docFontList: document.querySelector("#docFontList"), docFontSummary: document.querySelector("#docFontSummary"), availableFontSummary: document.querySelector("#availableFontSummary"), + fontPermissionHint: document.querySelector("#fontPermissionHint"), fontList: document.querySelector("#fontList"), statusText: document.querySelector("#statusText"), }; @@ -194,6 +196,7 @@ async function boot() { renderFontList(); updateControls(); updateLocalFontButton(); + await refreshLocalFontPermission(); setStatus(STATUS.ready); setBusy(false); } catch (err) { @@ -395,9 +398,19 @@ async function loadLocalFonts() { } async function queryLocalFonts() { - const available = await window.queryLocalFonts(); - state.systemFontCatalog = available; - return available; + try { + const available = await window.queryLocalFonts(); + state.systemFontCatalog = available; + state.systemFontPermission = "granted"; + updateFontPermissionHint(); + return available; + } catch (err) { + if (err && err.name === "NotAllowedError") { + state.systemFontPermission = "denied"; + updateFontPermissionHint(); + } + throw err; + } } async function autoLoadDocumentLocalFonts(openSeq) { @@ -765,12 +778,35 @@ function updateLocalFontButton() { const supported = canReadLocalFonts(); el.localFontButton.disabled = !supported; el.localFontButton.title = supported ? "授权读取浏览器可访问的系统字体" : "当前浏览器不支持读取系统字体"; + updateFontPermissionHint(); +} + +function updateFontPermissionHint() { + el.fontPermissionHint.hidden = !canReadLocalFonts() || state.systemFontPermission === "granted"; } function canReadLocalFonts() { return typeof window.queryLocalFonts === "function"; } +async function refreshLocalFontPermission() { + if (!canReadLocalFonts() || !navigator.permissions?.query) { + updateFontPermissionHint(); + return; + } + try { + const permission = await navigator.permissions.query({ name: "local-fonts" }); + state.systemFontPermission = permission.state; + permission.onchange = () => { + state.systemFontPermission = permission.state; + updateFontPermissionHint(); + }; + } catch { + state.systemFontPermission = "prompt"; + } + updateFontPermissionHint(); +} + async function openDocument(options = {}) { if (!state.ofdBytes) { return;