mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
64b6001947
commit
7e8e6167ff
4 changed files with 6 additions and 48 deletions
|
|
@ -180,12 +180,10 @@ export const openFile = (options: IOpenFileOptions) => {
|
|||
}
|
||||
const ids = decodeURIComponent(new URL(item.webContents.getURL()).hash.substring(1)).split(Constants.ZWSP);
|
||||
if (ids.includes(options.rootID) || ids.includes(options.assetPath)) {
|
||||
let execJS = `window.newWindow.switchTabById("${options.rootID || options.assetPath}");`;
|
||||
if (options.assetPath) {
|
||||
execJS += `window.newWindow.positionPDF("${options.assetPath}", ${typeof options.page === "number" ? options.page : `"${options.page}"`})`;
|
||||
}
|
||||
item.focus();
|
||||
item.webContents.executeJavaScript(execJS);
|
||||
const optionsClone = Object.assign({}, options);
|
||||
delete optionsClone.app
|
||||
item.webContents.executeJavaScript(`window.newWindow.openFile(${JSON.stringify(optionsClone)});`);
|
||||
if (options.afterOpen) {
|
||||
options.afterOpen();
|
||||
}
|
||||
|
|
|
|||
3
app/src/types/index.d.ts
vendored
3
app/src/types/index.d.ts
vendored
|
|
@ -95,8 +95,7 @@ interface Window {
|
|||
}
|
||||
|
||||
newWindow: {
|
||||
positionPDF(pathStr: string, page: string | number): void
|
||||
switchTabById(id: string): void
|
||||
openFile(options: IOpenFileOptions): void
|
||||
}
|
||||
|
||||
Protyle: import("../protyle/method").default
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
import {getAllTabs} from "../../layout/getAll";
|
||||
import {Asset} from "../../asset";
|
||||
import {Editor} from "../../editor";
|
||||
|
||||
export const positionPDF = (pathStr: string, page: string | number) => {
|
||||
getAllTabs().forEach((tab) => {
|
||||
if (tab.model instanceof Asset && tab.model.pdfObject && tab.model.path === pathStr) {
|
||||
tab.parent.switchTab(tab.headElement);
|
||||
tab.model.goToPage(page);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const switchTabById = (id: string) => {
|
||||
getAllTabs().find((tab) => {
|
||||
if (!tab.model) {
|
||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (initTabData.instance === "Editor" && initTabData.rootId === id) {
|
||||
tab.parent.switchTab(tab.headElement);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (tab.model instanceof Editor) {
|
||||
if (tab.model.editor.protyle.block.rootID === id) {
|
||||
tab.parent.switchTab(tab.headElement);
|
||||
return true;
|
||||
}
|
||||
} else if (tab.model instanceof Asset) {
|
||||
if (tab.model.path === id) {
|
||||
tab.parent.switchTab(tab.headElement);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -7,7 +7,7 @@ import {addScript, addScriptSync} from "../protyle/util/addScript";
|
|||
import {genUUID} from "../util/genID";
|
||||
import {fetchGet, fetchPost} from "../util/fetch";
|
||||
import {addBaseURL, setNoteBook} from "../util/pathName";
|
||||
import {openFileById} from "../editor/util";
|
||||
import {openFile, openFileById} from "../editor/util";
|
||||
import {
|
||||
processSync, progressBackgroundTask,
|
||||
progressLoading,
|
||||
|
|
@ -19,7 +19,6 @@ import {initMessage} from "../dialog/message";
|
|||
import {getAllTabs} from "../layout/getAll";
|
||||
import {getLocalStorage} from "../protyle/util/compatibility";
|
||||
import {init} from "../window/init";
|
||||
import {positionPDF, switchTabById} from "./global/function";
|
||||
import {loadPlugins} from "../plugin/loader";
|
||||
|
||||
class App {
|
||||
|
|
@ -152,6 +151,5 @@ new App();
|
|||
|
||||
// 再次点击新窗口已打开的 PDF 时,需进行定位
|
||||
window.newWindow = {
|
||||
positionPDF: positionPDF,
|
||||
switchTabById: switchTabById
|
||||
openFile: openFile,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue