From decd416da2e026236fa871b0fd99e61e42207dc2 Mon Sep 17 00:00:00 2001 From: ColdDivinity <4059044+ColdDivinity@users.noreply.github.com> Date: Sun, 25 Jun 2023 12:02:15 -0500 Subject: [PATCH] Remember window position --- apps/desktop/main/src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/desktop/main/src/index.ts b/apps/desktop/main/src/index.ts index e9e74198..2a38136e 100644 --- a/apps/desktop/main/src/index.ts +++ b/apps/desktop/main/src/index.ts @@ -1,10 +1,11 @@ -import { app, BrowserWindow, dialog, ipcMain, Menu, screen, shell } from "electron"; +import { app, BrowserWindow, dialog, ipcMain, Menu, Rectangle, screen, shell } from "electron"; import { setupEventListeners } from "./app/events"; import { windows } from "./app/windows"; import { join } from "path"; import { format } from "url"; import { environment } from "./environments/environment"; import log from "electron-log"; +import * as Store from "electron-store"; const { ELECTRON_IS_DEV } = process.env; @@ -29,6 +30,8 @@ const rendererAppDevPort = 4200; */ const desktopFrontendFile = (fileName: string) => join(__dirname, "frontend", fileName); +const config = new Store(); + function createFrontendWindow() { const workAreaSize = screen.getPrimaryDisplay().workAreaSize; const width = Math.min(DEFAULT_WIDTH, workAreaSize.width || DEFAULT_WIDTH); @@ -53,10 +56,18 @@ function createFrontendWindow() { contextIsolation: false, }, }); - frontend.center(); + const bounds = config.get('frontendBounds') as Rectangle; + if (bounds) { + frontend.setBounds(bounds); + } else { + frontend.center(); + } frontend.on("ready-to-show", () => { windows.frontend?.show(); }); + frontend.on("close", () => { + config.set('frontendBounds', frontend.getBounds()); + }); frontend.on("closed", () => { windows.frontend = null; app.quit();