[enhancement]: save/restore screen position
This commit is contained in:
parent
2c17458fdf
commit
c0110eff82
1 changed files with 23 additions and 0 deletions
|
@ -24,6 +24,8 @@ import {
|
||||||
BrowserWindowConstructorOptions,
|
BrowserWindowConstructorOptions,
|
||||||
protocol,
|
protocol,
|
||||||
net,
|
net,
|
||||||
|
Rectangle,
|
||||||
|
screen,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import electronLocalShortcut from 'electron-localshortcut';
|
import electronLocalShortcut from 'electron-localshortcut';
|
||||||
import log from 'electron-log/main';
|
import log from 'electron-log/main';
|
||||||
|
@ -256,6 +258,26 @@ const createWindow = async (first = true) => {
|
||||||
...(nativeFrame && isWindows() && nativeFrameConfig.windows),
|
...(nativeFrame && isWindows() && nativeFrameConfig.windows),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// From https://github.com/electron/electron/issues/526#issuecomment-1663959513
|
||||||
|
const bounds = store.get('bounds') as Rectangle | undefined;
|
||||||
|
if (bounds) {
|
||||||
|
const screenArea = screen.getDisplayMatching(bounds).workArea;
|
||||||
|
if (
|
||||||
|
bounds.x > screenArea.x + screenArea.width ||
|
||||||
|
bounds.x < screenArea.x ||
|
||||||
|
bounds.y < screenArea.y ||
|
||||||
|
bounds.y > screenArea.y + screenArea.height
|
||||||
|
) {
|
||||||
|
if (bounds.width < screenArea.width && bounds.height < screenArea.height) {
|
||||||
|
mainWindow.setBounds({ height: bounds.height, width: bounds.width });
|
||||||
|
} else {
|
||||||
|
mainWindow.setBounds({ height: 900, width: 1440 });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainWindow.setBounds(bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
electronLocalShortcut.register(mainWindow, 'Ctrl+Shift+I', () => {
|
electronLocalShortcut.register(mainWindow, 'Ctrl+Shift+I', () => {
|
||||||
mainWindow?.webContents.openDevTools();
|
mainWindow?.webContents.openDevTools();
|
||||||
});
|
});
|
||||||
|
@ -385,6 +407,7 @@ const createWindow = async (first = true) => {
|
||||||
let saved = false;
|
let saved = false;
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
|
store.set('bounds', mainWindow?.getBounds());
|
||||||
if (!exitFromTray && store.get('window_exit_to_tray')) {
|
if (!exitFromTray && store.get('window_exit_to_tray')) {
|
||||||
if (isMacOS() && !forceQuit) {
|
if (isMacOS() && !forceQuit) {
|
||||||
exitFromTray = true;
|
exitFromTray = true;
|
||||||
|
|
Reference in a new issue