fix: correctly handle config updates

fix: synchronise updates to config with preload
fix: send config on web contents load
fix: hide menu when custom frame is off
chore: add workarounds for developing on Nix
chore: bump version to 1.1.10
This commit is contained in:
izzy
2025-10-10 12:28:03 +01:00
parent 8fd6f35729
commit 2517f412ab
6 changed files with 72 additions and 8 deletions
+31 -4
View File
@@ -66,6 +66,18 @@ const store = new Store({
* Shim for `electron-store` because typings are broken
*/
class Config {
sync() {
mainWindow.webContents.send("config", {
firstLaunch: this.firstLaunch,
customFrame: this.customFrame,
minimiseToTray: this.minimiseToTray,
spellchecker: this.spellchecker,
hardwareAcceleration: this.hardwareAcceleration,
discordRpc: this.discordRpc,
windowState: this.windowState,
});
}
get firstLaunch() {
return (store as never as { get(k: string): boolean }).get("firstLaunch");
}
@@ -75,6 +87,8 @@ class Config {
"firstLaunch",
value,
);
this.sync();
}
get customFrame() {
@@ -86,6 +100,8 @@ class Config {
"customFrame",
value,
);
this.sync();
}
get minimiseToTray() {
@@ -99,6 +115,8 @@ class Config {
"minimiseToTray",
value,
);
this.sync();
}
get spellchecker() {
@@ -112,6 +130,8 @@ class Config {
"spellchecker",
value,
);
this.sync();
}
get hardwareAcceleration() {
@@ -125,6 +145,8 @@ class Config {
"hardwareAcceleration",
value,
);
this.sync();
}
get discordRpc() {
@@ -142,6 +164,8 @@ class Config {
"discordRpc",
value,
);
this.sync();
}
get windowState() {
@@ -156,13 +180,16 @@ class Config {
set(k: string, value: DesktopConfig["windowState"]): void;
}
).set("windowState", value);
this.sync();
}
}
export const config = new Config();
ipcMain.on("config", (newConfig) =>
ipcMain.on("config", (_, newConfig: Partial<DesktopConfig>) => {
console.info("Received new configuration", newConfig);
Object.entries(newConfig).forEach(
([key, value]) => (config[key as keyof DesktopConfig] = value),
),
);
([key, value]) => (config[key as keyof DesktopConfig] = value as never),
);
});
+4
View File
@@ -18,6 +18,10 @@ export function initTray() {
updateTrayMenu();
tray.setToolTip("Stoat for Desktop");
tray.setImage(trayIcon);
tray.on("click", () => {
mainWindow.show();
mainWindow.focus();
});
}
export function updateTrayMenu() {
+8 -2
View File
@@ -40,8 +40,8 @@ export function createMainWindow() {
mainWindow = new BrowserWindow({
minWidth: 300,
minHeight: 300,
width: 1100,
height: 600,
width: 1280,
height: 720,
backgroundColor: "#191919",
frame: !config.customFrame,
icon: windowIcon,
@@ -54,6 +54,9 @@ export function createMainWindow() {
},
});
// hide the options
mainWindow.setMenu(null);
// maximise the window if it was maximised before
if (config.windowState.isMaximised) {
mainWindow.maximize();
@@ -101,6 +104,9 @@ export function createMainWindow() {
}
});
// send the config
mainWindow.webContents.on("did-finish-load", () => config.sync());
// configure spellchecker context menu
mainWindow.webContents.on("context-menu", (_, params) => {
const menu = new Menu();