2023-01-28 00:41:44 +08:00
|
|
|
|
import {layoutToJSON} from "../layout/util";
|
|
|
|
|
|
/// #if !BROWSER
|
2023-02-06 21:50:28 +08:00
|
|
|
|
import {ipcRenderer} from "electron";
|
2023-01-28 00:41:44 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
|
import {Tab} from "../layout/Tab";
|
2024-10-25 20:30:43 +08:00
|
|
|
|
import {fetchSyncPost} from "../util/fetch";
|
2023-02-07 11:58:24 +08:00
|
|
|
|
import {showMessage} from "../dialog/message";
|
2024-03-14 12:41:08 +08:00
|
|
|
|
import {getDisplayName, pathPosix} from "../util/pathName";
|
|
|
|
|
|
import {getSearch} from "../util/functions";
|
2023-01-28 00:41:44 +08:00
|
|
|
|
|
2023-09-02 20:09:52 +08:00
|
|
|
|
interface windowOptions {
|
|
|
|
|
|
position?: {
|
|
|
|
|
|
x: number,
|
|
|
|
|
|
y: number,
|
|
|
|
|
|
},
|
|
|
|
|
|
width?: number,
|
|
|
|
|
|
height?: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const openNewWindow = (tab: Tab, options: windowOptions = {}) => {
|
2023-01-28 00:41:44 +08:00
|
|
|
|
const json = {};
|
|
|
|
|
|
layoutToJSON(tab, json);
|
2023-01-31 21:10:37 +08:00
|
|
|
|
/// #if !BROWSER
|
2023-09-19 09:45:57 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
2023-09-02 20:09:52 +08:00
|
|
|
|
position: options.position,
|
|
|
|
|
|
width: options.width,
|
|
|
|
|
|
height: options.height,
|
2023-10-05 13:45:29 +08:00
|
|
|
|
// 需要 encode, 否则 https://github.com/siyuan-note/siyuan/issues/9343
|
2024-10-25 20:30:43 +08:00
|
|
|
|
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify([json]))}`
|
2023-02-26 10:19:47 +08:00
|
|
|
|
});
|
2023-01-31 21:10:37 +08:00
|
|
|
|
/// #endif
|
2023-01-28 00:41:44 +08:00
|
|
|
|
tab.parent.removeTab(tab.id);
|
2023-01-28 00:45:18 +08:00
|
|
|
|
};
|
2023-02-06 21:50:28 +08:00
|
|
|
|
|
2024-10-25 20:30:43 +08:00
|
|
|
|
export const openNewWindowById = async (id: string | string[], options: windowOptions = {}) => {
|
|
|
|
|
|
let ids = id;
|
|
|
|
|
|
if (typeof ids === "string") {
|
|
|
|
|
|
ids = [ids];
|
|
|
|
|
|
}
|
|
|
|
|
|
const json = [];
|
|
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
|
|
const response = await fetchSyncPost("/api/block/getBlockInfo", {id: ids[i]});
|
2023-02-07 11:58:24 +08:00
|
|
|
|
if (response.code === 3) {
|
|
|
|
|
|
showMessage(response.msg);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-10-25 20:30:43 +08:00
|
|
|
|
json.push({
|
2023-02-06 21:50:28 +08:00
|
|
|
|
title: response.data.rootTitle,
|
|
|
|
|
|
docIcon: response.data.rootIcon,
|
|
|
|
|
|
pin: false,
|
|
|
|
|
|
active: true,
|
|
|
|
|
|
instance: "Tab",
|
|
|
|
|
|
action: "Tab",
|
|
|
|
|
|
children: {
|
|
|
|
|
|
notebookId: response.data.box,
|
2024-10-25 20:30:43 +08:00
|
|
|
|
blockId: ids[i],
|
2023-02-06 21:50:28 +08:00
|
|
|
|
rootId: response.data.rootID,
|
|
|
|
|
|
mode: "wysiwyg",
|
|
|
|
|
|
instance: "Editor",
|
2024-10-25 20:30:43 +08:00
|
|
|
|
action: response.data.rootID === ids[i] ? Constants.CB_GET_SCROLL : Constants.CB_GET_ALL
|
2023-02-06 21:50:28 +08:00
|
|
|
|
}
|
2023-12-31 11:13:05 +08:00
|
|
|
|
});
|
2024-10-25 20:30:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
width: options.width,
|
|
|
|
|
|
height: options.height,
|
|
|
|
|
|
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
|
2023-02-06 21:50:28 +08:00
|
|
|
|
});
|
2024-10-25 20:30:43 +08:00
|
|
|
|
/// #endif
|
2024-03-14 12:41:08 +08:00
|
|
|
|
};
|
2023-02-06 21:50:28 +08:00
|
|
|
|
|
2024-03-14 12:41:08 +08:00
|
|
|
|
export const openAssetNewWindow = (assetPath: string, options: windowOptions = {}) => {
|
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
const suffix = pathPosix().extname(assetPath.split("?page")[0]);
|
|
|
|
|
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
|
|
|
|
|
|
let docIcon = "iconPDF";
|
|
|
|
|
|
if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
|
|
|
|
|
|
docIcon = "iconImage";
|
|
|
|
|
|
} else if (Constants.SIYUAN_ASSETS_AUDIO.includes(suffix)) {
|
|
|
|
|
|
docIcon = "iconRecord";
|
|
|
|
|
|
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(suffix)) {
|
|
|
|
|
|
docIcon = "iconVideo";
|
|
|
|
|
|
}
|
2024-10-25 20:30:43 +08:00
|
|
|
|
const json: any = [{
|
2024-03-14 12:41:08 +08:00
|
|
|
|
title: getDisplayName(assetPath),
|
|
|
|
|
|
docIcon,
|
|
|
|
|
|
pin: false,
|
|
|
|
|
|
active: true,
|
|
|
|
|
|
instance: "Tab",
|
|
|
|
|
|
action: "Tab",
|
|
|
|
|
|
children: {
|
|
|
|
|
|
path: assetPath,
|
|
|
|
|
|
page: parseInt(getSearch("page", assetPath)),
|
|
|
|
|
|
instance: "Asset",
|
|
|
|
|
|
}
|
2024-10-25 20:30:43 +08:00
|
|
|
|
}];
|
2024-03-14 12:41:08 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
|
|
|
|
|
position: options.position,
|
|
|
|
|
|
width: options.width,
|
|
|
|
|
|
height: options.height,
|
|
|
|
|
|
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
/// #endif
|
2023-02-06 21:50:28 +08:00
|
|
|
|
};
|