Skip to content

Commit 336eaef

Browse files
committed
🎨 #9032
1 parent f54705e commit 336eaef

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

app/electron/main.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,9 @@ app.whenReady().then(() => {
699699
const win = new BrowserWindow({
700700
show: true,
701701
trafficLightPosition: {x: 8, y: 13},
702-
width: mainScreen.size.width * 0.7,
703-
height: mainScreen.size.height * 0.9,
702+
width: data.width || mainScreen.size.width * 0.7,
703+
height: data.height || mainScreen.size.height * 0.9,
704704
minWidth: 493,
705-
center: true,
706705
minHeight: 376,
707706
fullscreenable: true,
708707
frame: "darwin" === process.platform,
@@ -716,6 +715,11 @@ app.whenReady().then(() => {
716715
autoplayPolicy: "user-gesture-required" // 桌面端禁止自动播放多媒体 https://github.com/siyuan-note/siyuan/issues/7587
717716
},
718717
});
718+
if (data.position) {
719+
win.setPosition(data.position.x, data.position.y);
720+
} else {
721+
win.center();
722+
}
719723
win.loadURL(data.url);
720724
const targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
721725
if (mainScreen.id !== targetScreen.id) {

app/src/plugin/API.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@ openWindow = () => {
2727
};
2828
/// #else
2929
openWindow = (options: {
30+
position?: {
31+
x: number,
32+
y: number,
33+
},
34+
height?: number,
35+
width?: number,
3036
tab?: Tab,
3137
doc?: {
3238
id: string, // 块 id
3339
},
3440
}) => {
3541
if (options.doc.id) {
36-
openNewWindowById(options.doc.id);
42+
openNewWindowById(options.doc.id, {position: options.position, width: options.width, height: options.height});
3743
return;
3844
}
3945
if (options.tab) {
40-
openNewWindow(options.tab)
46+
openNewWindow(options.tab, {position: options.position, width: options.width, height: options.height});
4147
return;
4248
}
4349
};

app/src/window/openNewWindow.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ import {Tab} from "../layout/Tab";
88
import {fetchPost} from "../util/fetch";
99
import {showMessage} from "../dialog/message";
1010

11-
export const openNewWindow = (tab: Tab) => {
11+
interface windowOptions {
12+
position?: {
13+
x: number,
14+
y: number,
15+
},
16+
width?: number,
17+
height?: number
18+
}
19+
20+
export const openNewWindow = (tab: Tab, options: windowOptions = {}) => {
1221
const json = {};
1322
layoutToJSON(tab, json);
1423
/// #if !BROWSER
1524
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
25+
position: options.position,
26+
width: options.width,
27+
height: options.height,
1628
id: getCurrentWindow().id,
1729
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
1830
});
1931
/// #endif
2032
tab.parent.removeTab(tab.id);
2133
};
2234

23-
export const openNewWindowById = (id: string) => {
35+
export const openNewWindowById = (id: string, options: windowOptions = {}) => {
2436
fetchPost("/api/block/getBlockInfo", {id}, (response) => {
2537
if (response.code === 3) {
2638
showMessage(response.msg);
@@ -50,6 +62,9 @@ export const openNewWindowById = (id: string) => {
5062
}
5163
/// #if !BROWSER
5264
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
65+
position: options.position,
66+
width: options.width,
67+
height: options.height,
5368
id: getCurrentWindow().id,
5469
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
5570
});
@@ -62,6 +77,9 @@ export const openNewWindowById = (id: string) => {
6277
};
6378
/// #if !BROWSER
6479
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
80+
position: options.position,
81+
width: options.width,
82+
height: options.height,
6583
id: getCurrentWindow().id,
6684
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`
6785
});

0 commit comments

Comments
 (0)