Vanessa 2023-09-02 20:09:52 +08:00
parent f54705e151
commit 336eaef000
3 changed files with 35 additions and 7 deletions

View file

@ -699,10 +699,9 @@ app.whenReady().then(() => {
const win = new BrowserWindow({
show: true,
trafficLightPosition: {x: 8, y: 13},
width: mainScreen.size.width * 0.7,
height: mainScreen.size.height * 0.9,
width: data.width || mainScreen.size.width * 0.7,
height: data.height || mainScreen.size.height * 0.9,
minWidth: 493,
center: true,
minHeight: 376,
fullscreenable: true,
frame: "darwin" === process.platform,
@ -716,6 +715,11 @@ app.whenReady().then(() => {
autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587
},
});
if (data.position) {
win.setPosition(data.position.x, data.position.y);
} else {
win.center();
}
win.loadURL(data.url);
const targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
if (mainScreen.id !== targetScreen.id) {

View file

@ -27,17 +27,23 @@ openWindow = () => {
};
/// #else
openWindow = (options: {
position?: {
x: number,
y: number,
},
height?: number,
width?: number,
tab?: Tab,
doc?: {
id: string, // 块 id
},
}) => {
if (options.doc.id) {
openNewWindowById(options.doc.id);
openNewWindowById(options.doc.id, {position: options.position, width: options.width, height: options.height});
return;
}
if (options.tab) {
openNewWindow(options.tab)
openNewWindow(options.tab, {position: options.position, width: options.width, height: options.height});
return;
}
};

View file

@ -8,11 +8,23 @@ import {Tab} from "../layout/Tab";
import {fetchPost} from "../util/fetch";
import {showMessage} from "../dialog/message";
export const openNewWindow = (tab: Tab) => {
interface windowOptions {
position?: {
x: number,
y: number,
},
width?: number,
height?: number
}
export const openNewWindow = (tab: Tab, options: windowOptions = {}) => {
const json = {};
layoutToJSON(tab, json);
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
position: options.position,
width: options.width,
height: options.height,
id: getCurrentWindow().id,
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
});
@ -20,7 +32,7 @@ export const openNewWindow = (tab: Tab) => {
tab.parent.removeTab(tab.id);
};
export const openNewWindowById = (id: string) => {
export const openNewWindowById = (id: string, options: windowOptions = {}) => {
fetchPost("/api/block/getBlockInfo", {id}, (response) => {
if (response.code === 3) {
showMessage(response.msg);
@ -50,6 +62,9 @@ export const openNewWindowById = (id: string) => {
}
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
position: options.position,
width: options.width,
height: options.height,
id: getCurrentWindow().id,
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
});
@ -62,6 +77,9 @@ export const openNewWindowById = (id: string) => {
};
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
position: options.position,
width: options.width,
height: options.height,
id: getCurrentWindow().id,
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
});