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";
|
2023-02-06 21:50:28 +08:00
|
|
|
|
import {fetchPost} from "../util/fetch";
|
2023-02-07 11:58:24 +08:00
|
|
|
|
import {showMessage} from "../dialog/message";
|
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
|
|
|
|
|
|
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
|
|
|
|
|
2023-09-02 20:09:52 +08:00
|
|
|
|
export const openNewWindowById = (id: string, options: windowOptions = {}) => {
|
2023-04-09 09:31:42 +08:00
|
|
|
|
fetchPost("/api/block/getBlockInfo", {id}, (response) => {
|
2023-02-07 11:58:24 +08:00
|
|
|
|
if (response.code === 3) {
|
|
|
|
|
|
showMessage(response.msg);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-02-06 21:50:28 +08:00
|
|
|
|
const json: any = {
|
|
|
|
|
|
title: response.data.rootTitle,
|
|
|
|
|
|
docIcon: response.data.rootIcon,
|
|
|
|
|
|
pin: false,
|
|
|
|
|
|
active: true,
|
|
|
|
|
|
instance: "Tab",
|
|
|
|
|
|
action: "Tab",
|
|
|
|
|
|
children: {
|
|
|
|
|
|
notebookId: response.data.box,
|
|
|
|
|
|
blockId: id,
|
|
|
|
|
|
rootId: response.data.rootID,
|
|
|
|
|
|
mode: "wysiwyg",
|
|
|
|
|
|
instance: "Editor",
|
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
};
|
2023-02-06 21:50:28 +08:00
|
|
|
|
if (response.data.rootID === id) {
|
|
|
|
|
|
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
2023-05-14 11:50:41 +08:00
|
|
|
|
if (attrResponse.data.scroll) {
|
|
|
|
|
|
json.children.scrollAttr = JSON.parse(attrResponse.data.scroll);
|
2023-05-17 12:37:56 +08:00
|
|
|
|
// 历史数据兼容
|
|
|
|
|
|
json.children.scrollAttr.rootId = response.data.rootID;
|
2023-05-14 11:50:41 +08:00
|
|
|
|
}
|
2023-02-06 21:50:28 +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
|
|
|
|
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-02-06 21:50:28 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
json.children.action = Constants.CB_GET_ALL;
|
|
|
|
|
|
json.children.scrollAttr = {
|
2023-05-17 12:37:56 +08:00
|
|
|
|
zoomInId: id,
|
2023-02-06 21:54:26 +08:00
|
|
|
|
};
|
2023-02-06 21:50:28 +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
|
|
|
|
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-02-06 21:50:28 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
};
|