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

View file

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

View file

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