feat: minimise-to-tray-on-startup

Signed-off-by: Mihai <cristian@mihaimuresan.com>
This commit is contained in:
Mihai 2026-02-17 11:26:39 +01:00 committed by Mihai
parent 2e99b19353
commit da302b445b
2 changed files with 33 additions and 4 deletions

View File

@ -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");
}

View File

@ -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) {