This commit is contained in:
Vanessa 2023-05-07 09:57:14 +08:00
parent 813bd27fb3
commit b6090f1bf3
5 changed files with 17 additions and 18 deletions

View file

@ -24,7 +24,7 @@ import {setTitle} from "../dialog/processSystem";
import {zoomOut} from "../menus/protyle"; import {zoomOut} from "../menus/protyle";
import {countBlockWord, countSelectWord} from "../layout/status"; import {countBlockWord, countSelectWord} from "../layout/status";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
import {getSearch, objEquals} from "../util/functions"; import {objEquals} from "../util/functions";
import {resize} from "../protyle/util/resize"; import {resize} from "../protyle/util/resize";
import {newCardModel} from "../card/newCardTab"; import {newCardModel} from "../card/newCardTab";
import {Search} from "../search"; import {Search} from "../search";
@ -160,16 +160,16 @@ export const openFile = (options: IOpenFileOptions) => {
/// #if !BROWSER /// #if !BROWSER
// https://github.com/siyuan-note/siyuan/issues/7491 // https://github.com/siyuan-note/siyuan/issues/7491
const currentWindowId = getCurrentWindow().id const currentWindowId = getCurrentWindow().id;
const hasMatch = BrowserWindow.getAllWindows().find(item => { const hasMatch = BrowserWindow.getAllWindows().find(item => {
if (item.id === currentWindowId) { if (item.id === currentWindowId) {
return; return;
} }
const ids = decodeURIComponent(new URL(item.webContents.getURL()).hash.substring(1)).split(Constants.ZWSP); const ids = decodeURIComponent(new URL(item.webContents.getURL()).hash.substring(1)).split(Constants.ZWSP);
if (ids.includes(options.rootID) || ids.includes(options.assetPath)) { if (ids.includes(options.rootID) || ids.includes(options.assetPath)) {
let execJS = `window.newWindow.switchTabById("${options.rootID || options.assetPath}");` let execJS = `window.newWindow.switchTabById("${options.rootID || options.assetPath}");`;
if (options.assetPath) { if (options.assetPath) {
execJS += `window.newWindow.positionPDF("${options.assetPath}", ${typeof options.page === "number" ? options.page : `"${options.page}"`})` execJS += `window.newWindow.positionPDF("${options.assetPath}", ${typeof options.page === "number" ? options.page : `"${options.page}"`})`;
} }
item.focus(); item.focus();
item.webContents.executeJavaScript(execJS); item.webContents.executeJavaScript(execJS);
@ -178,7 +178,7 @@ export const openFile = (options: IOpenFileOptions) => {
} }
return true; return true;
} }
}) });
if (hasMatch) { if (hasMatch) {
return; return;
} }

View file

@ -28,7 +28,7 @@ export const loadPlugins = (app: App) => {
console.error(`eval plugin ${item.name} error:`, e); console.error(`eval plugin ${item.name} error:`, e);
return; return;
} }
const pluginClass = (moduleObj.exports || exportsObj).default || moduleObj.exports const pluginClass = (moduleObj.exports || exportsObj).default || moduleObj.exports;
if (typeof pluginClass !== "function") { if (typeof pluginClass !== "function") {
console.error(`plugin ${item.name} has no export`); console.error(`plugin ${item.name} has no export`);
return; return;

View file

@ -11,7 +11,6 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {replaceFileName, validateName} from "../editor/rename"; import {replaceFileName, validateName} from "../editor/rename";
import {hideElements} from "../protyle/ui/hideElements"; import {hideElements} from "../protyle/ui/hideElements";
import {isMobile} from "./functions";
import {openMobileFileById} from "../mobile/editor"; import {openMobileFileById} from "../mobile/editor";
export const getNewFilePath = (useSavePath: boolean) => { export const getNewFilePath = (useSavePath: boolean) => {

View file

@ -25,13 +25,13 @@ export const switchTabById = (id: string) => {
} else if (tab.model instanceof Editor) { } else if (tab.model instanceof Editor) {
if (tab.model.editor.protyle.block.rootID === id) { if (tab.model.editor.protyle.block.rootID === id) {
tab.parent.switchTab(tab.headElement); tab.parent.switchTab(tab.headElement);
return true return true;
} }
} else if (tab.model instanceof Asset) { } else if (tab.model instanceof Asset) {
if (tab.model.path === id) { if (tab.model.path === id) {
tab.parent.switchTab(tab.headElement); tab.parent.switchTab(tab.headElement);
return true return true;
} }
} }
}); });
} };

View file

@ -58,21 +58,21 @@ export const setTabPosition = () => {
export const setModelsHash = () => { export const setModelsHash = () => {
if (!isWindow()) { if (!isWindow()) {
return return;
} }
let hash = "" let hash = "";
getAllTabs().forEach(tab => { getAllTabs().forEach(tab => {
if (!tab.model) { if (!tab.model) {
const initTab = tab.headElement.getAttribute("data-initdata"); const initTab = tab.headElement.getAttribute("data-initdata");
if (initTab) { if (initTab) {
const initTabData = JSON.parse(initTab); const initTabData = JSON.parse(initTab);
hash += initTabData.rootId + Constants.ZWSP hash += initTabData.rootId + Constants.ZWSP;
} }
} else if (tab.model instanceof Editor) { } else if (tab.model instanceof Editor) {
hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP;
} else if (tab.model instanceof Asset) { } else if (tab.model instanceof Asset) {
hash += tab.model.path + Constants.ZWSP hash += tab.model.path + Constants.ZWSP;
} }
}) });
window.location.hash = hash window.location.hash = hash;
} };