remember window position (#2808)
This commit is contained in:
Generated
+36
-2
@@ -35,6 +35,7 @@
|
|||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"electron-log": "^5.2.2",
|
"electron-log": "^5.2.2",
|
||||||
"electron-squirrel-startup": "^1.0.1",
|
"electron-squirrel-startup": "^1.0.1",
|
||||||
|
"electron-window-state": "^5.0.3",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"framer-motion": "^11.11.11",
|
"framer-motion": "^11.11.11",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@@ -7812,6 +7813,40 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/electron-window-state": {
|
||||||
|
"version": "5.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-5.0.3.tgz",
|
||||||
|
"integrity": "sha512-1mNTwCfkolXl3kMf50yW3vE2lZj0y92P/HYWFBrb+v2S/pCka5mdwN3cagKm458A7NjndSwijynXgcLWRodsVg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"jsonfile": "^4.0.0",
|
||||||
|
"mkdirp": "^0.5.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/electron-window-state/node_modules/jsonfile": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"optionalDependencies": {
|
||||||
|
"graceful-fs": "^4.1.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/electron-window-state/node_modules/mkdirp": {
|
||||||
|
"version": "0.5.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||||
|
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"minimist": "^1.2.6"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"mkdirp": "bin/cmd.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/electron-winstaller": {
|
"node_modules/electron-winstaller": {
|
||||||
"version": "5.4.0",
|
"version": "5.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/electron-winstaller/-/electron-winstaller-5.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/electron-winstaller/-/electron-winstaller-5.4.0.tgz",
|
||||||
@@ -9605,7 +9640,7 @@
|
|||||||
"version": "4.2.11",
|
"version": "4.2.11",
|
||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/graphemer": {
|
"node_modules/graphemer": {
|
||||||
@@ -12607,7 +12642,6 @@
|
|||||||
"version": "1.2.8",
|
"version": "1.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
|||||||
@@ -109,6 +109,7 @@
|
|||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"electron-log": "^5.2.2",
|
"electron-log": "^5.2.2",
|
||||||
"electron-squirrel-startup": "^1.0.1",
|
"electron-squirrel-startup": "^1.0.1",
|
||||||
|
"electron-window-state": "^5.0.3",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"framer-motion": "^11.11.11",
|
"framer-motion": "^11.11.11",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
+14
-12
@@ -34,6 +34,7 @@ import {
|
|||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import * as electron from 'electron';
|
import * as electron from 'electron';
|
||||||
import * as yaml from 'yaml';
|
import * as yaml from 'yaml';
|
||||||
|
import windowStateKeeper from 'electron-window-state';
|
||||||
|
|
||||||
// Define temp directory for pasted images
|
// Define temp directory for pasted images
|
||||||
const gooseTempDir = path.join(app.getPath('temp'), 'goose-pasted-images');
|
const gooseTempDir = path.join(app.getPath('temp'), 'goose-pasted-images');
|
||||||
@@ -414,13 +415,21 @@ const createChat = async (
|
|||||||
goosedProcess = newGoosedProcess;
|
goosedProcess = newGoosedProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load and manage window state
|
||||||
|
const mainWindowState = windowStateKeeper({
|
||||||
|
defaultWidth: 750,
|
||||||
|
defaultHeight: 800,
|
||||||
|
});
|
||||||
|
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
titleBarStyle: process.platform === 'darwin' ? 'hidden' : 'default',
|
titleBarStyle: process.platform === 'darwin' ? 'hidden' : 'default',
|
||||||
trafficLightPosition: process.platform === 'darwin' ? { x: 16, y: 20 } : undefined,
|
trafficLightPosition: process.platform === 'darwin' ? { x: 16, y: 20 } : undefined,
|
||||||
vibrancy: process.platform === 'darwin' ? 'window' : undefined,
|
vibrancy: process.platform === 'darwin' ? 'window' : undefined,
|
||||||
frame: process.platform === 'darwin' ? false : true,
|
frame: process.platform === 'darwin' ? false : true,
|
||||||
width: 750,
|
x: mainWindowState.x,
|
||||||
height: 800,
|
y: mainWindowState.y,
|
||||||
|
width: mainWindowState.width,
|
||||||
|
height: mainWindowState.height,
|
||||||
minWidth: 650,
|
minWidth: 650,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
@@ -444,6 +453,9 @@ const createChat = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Let windowStateKeeper manage the window
|
||||||
|
mainWindowState.manage(mainWindow);
|
||||||
|
|
||||||
// Enable spellcheck / right and ctrl + click on mispelled word
|
// Enable spellcheck / right and ctrl + click on mispelled word
|
||||||
//
|
//
|
||||||
// NOTE: We could use webContents.session.availableSpellCheckerLanguages to include
|
// NOTE: We could use webContents.session.availableSpellCheckerLanguages to include
|
||||||
@@ -531,18 +543,8 @@ const createChat = async (
|
|||||||
: `?view=${encodeURIComponent(viewType)}`;
|
: `?view=${encodeURIComponent(viewType)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryDisplay = electron.screen.getPrimaryDisplay();
|
|
||||||
const { width } = primaryDisplay.workAreaSize;
|
|
||||||
|
|
||||||
// Increment window counter to track number of windows
|
// Increment window counter to track number of windows
|
||||||
const windowId = ++windowCounter;
|
const windowId = ++windowCounter;
|
||||||
const direction = windowId % 2 === 0 ? 1 : -1; // Alternate direction
|
|
||||||
const initialOffset = 50;
|
|
||||||
|
|
||||||
// Set window position with alternating offset strategy
|
|
||||||
const baseXPosition = Math.round(width / 2 - mainWindow.getSize()[0] / 2);
|
|
||||||
const xOffset = direction * initialOffset * Math.floor(windowId / 2);
|
|
||||||
mainWindow.setPosition(baseXPosition + xOffset, 100);
|
|
||||||
|
|
||||||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
||||||
mainWindow.loadURL(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}${queryParams}`);
|
mainWindow.loadURL(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}${queryParams}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user