fix(打开文档): 修复文档加载进度偶发隐藏
build.yaml / build (push) Successful in 45s

This commit is contained in:
xiaoqidun committed 2026-10-25 23:15:23 +08:00
1 parent 6601340fcc
commit 6832554ea3
1 file changed
+9 -7
+9 -7
View File
@@ -2903,6 +2903,7 @@ async function activateDocumentTab(tab, closing = false) {
async function mountDocumentTab(tab) { async function mountDocumentTab(tab) {
if (!isForegroundDocument(tab)) return; if (!isForegroundDocument(tab)) return;
const state = tab.state; const state = tab.state;
const openSeq = state.openSeq;
const callWASM = (name, ...args) => callTabWASM(tab, name, ...args); const callWASM = (name, ...args) => callTabWASM(tab, name, ...args);
if (tab.opening || tab.error) { if (tab.opening || tab.error) {
renderPageList(); renderPageList();
@@ -2927,11 +2928,11 @@ async function mountDocumentTab(tab) {
state.doc = await callWASM("ofdgoConfigure", await fontManager.files(fontManager.records()), state.renderAnnotations); state.doc = await callWASM("ofdgoConfigure", await fontManager.files(fontManager.records()), state.renderAnnotations);
tab.configurePending = false; tab.configurePending = false;
} }
if (!isForegroundDocument(tab)) return; if (!isForegroundDocument(tab) || openSeq !== state.openSeq) return;
await openDocument({ doc: state.wasmExited ? undefined : state.doc, pageIndex: state.pageIndex, fitMode: state.fitMode || "free", scale: state.scale, await openDocument({ doc: state.wasmExited ? undefined : state.doc, pageIndex: state.pageIndex, fitMode: state.fitMode || "free", scale: state.scale,
skipAutoFonts: !tab.initialLoad, keepSearch: true, keepCache: true, restoreTab: !tab.initialLoad, resetScroll: Boolean(tab.initialLoad), openSeq: state.openSeq }); skipAutoFonts: !tab.initialLoad, keepSearch: true, keepCache: true, restoreTab: !tab.initialLoad, resetScroll: Boolean(tab.initialLoad), openSeq });
if (!isForegroundDocument(tab) || openSeq !== state.openSeq) return;
tab.configurePending = false; tab.configurePending = false;
if (workspace.active !== tab) return;
tab.initialLoad = false; tab.initialLoad = false;
if (view?.anchor) restoreScaleAnchor(view.anchor); if (view?.anchor) restoreScaleAnchor(view.anchor);
showNavigation(view?.navigation || el.pagesTab); showNavigation(view?.navigation || el.pagesTab);
@@ -5747,6 +5748,7 @@ async function openOFD(file, remote = null, handle = file?.handle) {
tab.state.fileName = file.name || remote?.name || STATUS.opening; tab.state.fileName = file.name || remote?.name || STATUS.opening;
tab.status = STATUS.opening; tab.status = STATUS.opening;
workspace.tabs.push(tab); workspace.tabs.push(tab);
setBusy(true, "正在读取文档", 10, STATUS.opening, tab);
await activateDocumentTab(tab); await activateDocumentTab(tab);
if (workspace.active === tab && !previous.state.doc && !previous.opening && !previous.state.dirty && !previous.error) { if (workspace.active === tab && !previous.state.doc && !previous.opening && !previous.state.dirty && !previous.error) {
workspace.tabs.splice(workspace.tabs.indexOf(previous), 1); workspace.tabs.splice(workspace.tabs.indexOf(previous), 1);
@@ -5754,7 +5756,6 @@ async function openOFD(file, remote = null, handle = file?.handle) {
} }
renderDocumentTabs(); renderDocumentTabs();
const current = () => !tab.closed && tab.opening === request; const current = () => !tab.closed && tab.opening === request;
setBusy(true, "正在读取文档", 10, STATUS.opening, tab);
let accepted = false; let accepted = false;
let originalSource = null; let originalSource = null;
try { try {
@@ -5809,8 +5810,9 @@ async function openOFD(file, remote = null, handle = file?.handle) {
tab.busy = false; tab.busy = false;
accepted = true; accepted = true;
if (isForegroundDocument(tab)) { if (isForegroundDocument(tab)) {
await openDocument({doc, pageIndex: tab.state.pageIndex, activateActions: true, resetScroll: true, openSeq: tab.state.openSeq}); const openSeq = tab.state.openSeq;
if (isForegroundDocument(tab)) tab.initialLoad = false; await openDocument({doc, pageIndex: tab.state.pageIndex, activateActions: true, resetScroll: true, openSeq});
if (isForegroundDocument(tab) && openSeq === tab.state.openSeq) tab.initialLoad = false;
} }
else tab.status = "文档已打开"; else tab.status = "文档已打开";
} catch (err) { } catch (err) {
@@ -5821,7 +5823,7 @@ async function openOFD(file, remote = null, handle = file?.handle) {
} }
} finally { } finally {
if (tab.opening === request) tab.opening = null; if (tab.opening === request) tab.opening = null;
if (!tab.closed) setBusy(false, "", 0, "", tab); if (!accepted && !tab.closed) setBusy(false, "", 0, "", tab);
renderDocumentTabs(); renderDocumentTabs();
const source = tab.state.ofdBytes; const source = tab.state.ofdBytes;
if (!accepted && tab.worker) { if (!accepted && tab.worker) {