mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 15:06:46 +08:00
1 parent
1c576bde18
commit
1de949abfc
8 files changed
+215
-23
No files matched your search
+36
-8
@@ -2631,7 +2631,15 @@ async function closeWorkspace() {
|
||||
async function closeApplicationWindow() {
|
||||
window.removeEventListener("beforeunload", warnUnsaved);
|
||||
window.removeEventListener("beforeunload", warnBatch);
|
||||
await nativeHost.call("window.close", {});
|
||||
let closed = false;
|
||||
try {
|
||||
closed = await nativeHost.call("window.close", {});
|
||||
} finally {
|
||||
if (!closed) {
|
||||
window.addEventListener("beforeunload", warnUnsaved);
|
||||
window.addEventListener("beforeunload", warnBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createDocumentTab(value = createDocumentState()) {
|
||||
@@ -2848,18 +2856,20 @@ async function activateDocumentTab(tab, closing = false) {
|
||||
const focused = el.documentTitleBar.contains(document.activeElement);
|
||||
workspace.switching = true;
|
||||
try {
|
||||
if (!documentTab().busy && !await commitDocumentView()) return false;
|
||||
detachDocumentView();
|
||||
attachDocumentTab(tab);
|
||||
if (focused) el.documentTabs.querySelector('[data-selected="true"]')?.focus({preventScroll: true});
|
||||
workspace.switching = false;
|
||||
try {
|
||||
if (!documentTab().busy && !await commitDocumentView()) return false;
|
||||
detachDocumentView();
|
||||
attachDocumentTab(tab);
|
||||
if (focused) el.documentTabs.querySelector('[data-selected="true"]')?.focus({preventScroll: true});
|
||||
} finally {
|
||||
workspace.switching = false;
|
||||
}
|
||||
await mountDocumentTab(tab);
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (isForegroundDocument(tab)) showError(error, !state.doc);
|
||||
return false;
|
||||
} finally {
|
||||
if (workspace.active === tab) workspace.switching = false;
|
||||
const next = workspace.nextTab;
|
||||
workspace.nextTab = null;
|
||||
if (next && next !== workspace.active && !next.closed) queueMicrotask(() => activateDocumentTab(next));
|
||||
@@ -5163,7 +5173,25 @@ async function boot() {
|
||||
}
|
||||
}
|
||||
|
||||
async function openNativeFiles(files) {
|
||||
async function openNativeDocument(file) {
|
||||
let retained = false;
|
||||
try {
|
||||
retained = await openOFD(file);
|
||||
} catch (error) {
|
||||
showError(error, !state.doc);
|
||||
} finally {
|
||||
if (!retained) await nativeHost.discardFiles([file]);
|
||||
}
|
||||
}
|
||||
|
||||
async function openNativeFiles(files, launch = false) {
|
||||
if (launch) {
|
||||
for (const file of files) {
|
||||
while (workspace.closing || workspace.switching || batchElements.Panel.open || documentDialogs?.applicationOpen()) await new Promise(resolve => setTimeout(resolve, 100));
|
||||
void openNativeDocument(file).catch(error => showError(error, !state.doc));
|
||||
}
|
||||
return;
|
||||
}
|
||||
let retained = [];
|
||||
try {
|
||||
if (workspace.closing || batchElements.Panel.open && batch.running) { setStatus("请等待当前操作完成"); return; }
|
||||
|
||||
@@ -726,6 +726,13 @@ class NativeHost {
|
||||
}
|
||||
|
||||
async start(onFiles, onError) {
|
||||
let launching = Promise.resolve();
|
||||
this.bridge.on("ofdgo.launch", values => {
|
||||
launching = launching.then(async () => {
|
||||
try { await onFiles(values.map(value => new NativeFile(value)), true); }
|
||||
finally { await this.call("launch.done", {}); }
|
||||
}).catch(onError);
|
||||
});
|
||||
this.bridge.on("ofdgo.files", async values => {
|
||||
try { await onFiles(values.map(value => new NativeFile(value))); }
|
||||
catch (error) { onError(error); }
|
||||
|
||||
Reference in new issue
Block a user