From da302b445b1df94b9ae956b7596211eb7296917a Mon Sep 17 00:00:00 2001 From: Mihai Date: Tue, 17 Feb 2026 11:26:39 +0100 Subject: [PATCH] feat: minimise-to-tray-on-startup Signed-off-by: Mihai --- src/native/config.ts | 28 ++++++++++++++++++++++++---- src/native/window.ts | 9 +++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/native/config.ts b/src/native/config.ts index 35fb0ab..f7c2d37 100644 --- a/src/native/config.ts +++ b/src/native/config.ts @@ -16,6 +16,9 @@ const schema = { minimiseToTray: { type: "boolean", } as JSONSchema.Boolean, + startMinimisedToTray: { + type: "boolean", + } as JSONSchema.Boolean, spellchecker: { type: "boolean", } as JSONSchema.Boolean, @@ -29,16 +32,16 @@ const schema = { type: "object", properties: { x: { - type: 'number' + type: "number", } as JSONSchema.Number, y: { - type: 'number' + type: "number", } as JSONSchema.Number, width: { - type: 'number' + type: "number", } as JSONSchema.Number, height: { - type: 'number' + type: "number", } as JSONSchema.Number, isMaximised: { type: "boolean", @@ -53,6 +56,7 @@ const store = new Store({ firstLaunch: true, customFrame: true, minimiseToTray: true, + startMinimisedToTray: false, spellchecker: true, hardwareAcceleration: true, discordRpc: true, @@ -75,6 +79,7 @@ class Config { firstLaunch: this.firstLaunch, customFrame: this.customFrame, minimiseToTray: this.minimiseToTray, + startMinimisedToTray: this.startMinimisedToTray, spellchecker: this.spellchecker, hardwareAcceleration: this.hardwareAcceleration, discordRpc: this.discordRpc, @@ -123,6 +128,21 @@ class Config { this.sync(); } + get startMinimisedToTray() { + return (store as never as { get(k: string): boolean }).get( + "startMinimisedToTray", + ); + } + + set startMinimisedToTray(value: boolean) { + (store as never as { set(k: string, value: boolean): void }).set( + "startMinimisedToTray", + value, + ); + + this.sync(); + } + get spellchecker() { return (store as never as { get(k: string): boolean }).get("spellchecker"); } diff --git a/src/native/window.ts b/src/native/window.ts index 1f98076..8b9f578 100644 --- a/src/native/window.ts +++ b/src/native/window.ts @@ -36,6 +36,10 @@ const windowIcon = nativeImage.createFromDataURL(windowIconAsset); * Create the main application window */ export function createMainWindow() { + // (CLI arg --hidden or config) + const startHidden = + app.commandLine.hasSwitch("hidden") || config.startMinimisedToTray; + // create the window mainWindow = new BrowserWindow({ minWidth: 300, @@ -45,6 +49,7 @@ export function createMainWindow() { backgroundColor: "#191919", frame: !config.customFrame, icon: windowIcon, + show: !startHidden, webPreferences: { // relative to `.vite/build` preload: join(__dirname, "preload.js"), @@ -81,6 +86,10 @@ export function createMainWindow() { // load the entrypoint mainWindow.loadURL(BUILD_URL.toString()); + if (startHidden) { + mainWindow.hide(); + } + // minimise window to tray mainWindow.on("close", (event) => { if (!shouldQuit && config.minimiseToTray) {