Skip to content

Commit b7785d5

Browse files
committed
Add error handling & resilience to window style change
1 parent c5c9c49 commit b7785d5

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/handlers/appInfoHandlers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export class AppInfoHandlers {
2525
ipcMain.handle(
2626
IPC_CHANNELS.SET_WINDOW_STYLE,
2727
async (_event: Electron.IpcMainInvokeEvent, style: DesktopSettings['windowStyle']): Promise<void> => {
28-
await useDesktopConfig().setAsync('windowStyle', style);
29-
await appWindow.recreateWindow();
28+
await appWindow.setWindowStyle(style);
3029
}
3130
);
3231
ipcMain.handle(IPC_CHANNELS.GET_WINDOW_STYLE, async (): Promise<DesktopSettings['windowStyle']> => {

src/main-process/appWindow.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IPC_CHANNELS, ProgressStatus, ServerArgs } from '../constants';
1919
import { getAppResourcesPath } from '../install/resourcePaths';
2020
import { useDesktopConfig } from '../store/desktopConfig';
2121
import type { ElectronContextMenuOptions } from '../preload';
22+
import type { DesktopSettings } from '../store/desktopSettings';
2223

2324
/**
2425
* Creates a single application window that displays the renderer and encapsulates all the logic for sending messages to the renderer.
@@ -109,14 +110,41 @@ export class AppWindow {
109110
return window;
110111
}
111112

112-
async recreateWindow() {
113+
/**
114+
* Recreates the application window by closing the current window and creating a new one.
115+
*
116+
* After the new window is created, it reloads the last ComfyUI URL.
117+
* @returns A promise that resolves after the recreated window has loaded the last ComfyUI URL
118+
*/
119+
async recreateWindow(): Promise<void> {
113120
const { window } = this;
114121

115122
this.window = this.#createWindow();
116123
window.close();
117124
await this.reloadLastComfyUIUrl();
118125
}
119126

127+
/**
128+
* Changes the custom window style for win32 / linux. Recreates the window if the style is changed.
129+
* @param style The new window style to be applied
130+
* @returns A promise that resolves when the window style has been set and the window has been recreated.
131+
* Ignores attempts to unset the style or set it to the current value.
132+
*/
133+
async setWindowStyle(style: DesktopSettings['windowStyle']): Promise<void> {
134+
log.info(`Setting window style:`, style);
135+
if (!style) return;
136+
137+
const store = useDesktopConfig();
138+
const current = store.get('windowStyle');
139+
if (style === current) {
140+
log.warn(`Ignoring attempt to set window style to current value [${current}]`);
141+
// return;
142+
}
143+
144+
store.set('windowStyle', style);
145+
await this.recreateWindow();
146+
}
147+
120148
public isReady(): boolean {
121149
return this.rendererReady;
122150
}

0 commit comments

Comments
 (0)