remember window position (#2808)

This commit is contained in:
Max Novich
2025-06-06 21:22:18 -07:00
committed by GitHub
parent 1ce241bce1
commit 5222cd98e1
3 changed files with 51 additions and 14 deletions
+36 -2
View File
@@ -35,6 +35,7 @@
"dotenv": "^16.4.5",
"electron-log": "^5.2.2",
"electron-squirrel-startup": "^1.0.1",
"electron-window-state": "^5.0.3",
"express": "^4.21.1",
"framer-motion": "^11.11.11",
"lodash": "^4.17.21",
@@ -7812,6 +7813,40 @@
"dev": true,
"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": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/electron-winstaller/-/electron-winstaller-5.4.0.tgz",
@@ -9605,7 +9640,7 @@
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"dev": true,
"devOptional": true,
"license": "ISC"
},
"node_modules/graphemer": {
@@ -12607,7 +12642,6 @@
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
+1
View File
@@ -109,6 +109,7 @@
"dotenv": "^16.4.5",
"electron-log": "^5.2.2",
"electron-squirrel-startup": "^1.0.1",
"electron-window-state": "^5.0.3",
"express": "^4.21.1",
"framer-motion": "^11.11.11",
"lodash": "^4.17.21",
+14 -12
View File
@@ -34,6 +34,7 @@ import {
import * as crypto from 'crypto';
import * as electron from 'electron';
import * as yaml from 'yaml';
import windowStateKeeper from 'electron-window-state';
// Define temp directory for pasted images
const gooseTempDir = path.join(app.getPath('temp'), 'goose-pasted-images');
@@ -414,13 +415,21 @@ const createChat = async (
goosedProcess = newGoosedProcess;
}
// Load and manage window state
const mainWindowState = windowStateKeeper({
defaultWidth: 750,
defaultHeight: 800,
});
const mainWindow = new BrowserWindow({
titleBarStyle: process.platform === 'darwin' ? 'hidden' : 'default',
trafficLightPosition: process.platform === 'darwin' ? { x: 16, y: 20 } : undefined,
vibrancy: process.platform === 'darwin' ? 'window' : undefined,
frame: process.platform === 'darwin' ? false : true,
width: 750,
height: 800,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 650,
resizable: true,
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
//
// NOTE: We could use webContents.session.availableSpellCheckerLanguages to include
@@ -531,18 +543,8 @@ const createChat = async (
: `?view=${encodeURIComponent(viewType)}`;
}
const primaryDisplay = electron.screen.getPrimaryDisplay();
const { width } = primaryDisplay.workAreaSize;
// Increment window counter to track number of windows
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) {
mainWindow.loadURL(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}${queryParams}`);