Conversation
|
setchy
left a comment
There was a problem hiding this comment.
Thanks @afonsojramos - spotted a few areas of feedback, will provide more detail when I'm in front of my computer next (currently on mobile)
| * @param mb - The menubar instance used for the dialog parent window and quit. | ||
| */ | ||
| export function resetApp(mb: Menubar): void { | ||
| if (!mb.window) { |
There was a problem hiding this comment.
I like this.
Should we be following this pattern in other places within src/main/* instead of mb.window?. ?
There was a problem hiding this comment.
Agreed! I’ll update events.ts, utils.ts, handlers/system.ts, and lifecycle/window.ts to use the early return guard pattern instead of optional chaining. It’s more explicit about the intent and consistent across src/main/*.
| mb.window?.setSize(800, 600); | ||
| mb.window?.center(); | ||
| if (mb.window) { | ||
| mb.window.resizable = true; | ||
| } | ||
| mb.window?.setAlwaysOnTop(true); |
There was a problem hiding this comment.
Should all these setters be wrapped with if (mb.window) {, or better yet, an early return if (!mb.window) { return }
There was a problem hiding this comment.
Good catch!! Since we already have the early return at the top for the on() calls, the mb.window?. inside the callbacks is redundant-looking but technically correct since the callbacks run later. I’ll consolidate with an early return inside each callback for consistency.
| mb.window.webContents.on('devtools-closed', () => { | ||
| const trayBounds = mb.tray.getBounds(); | ||
| mb.window.setSize(WindowConfig.width, WindowConfig.height); | ||
| mb.window?.setSize(WindowConfig.width ?? 500, WindowConfig.height ?? 400); |
There was a problem hiding this comment.
Could we instead reference the window default/initialized dimensions vs inlining these values again here?
There was a problem hiding this comment.
Good point. I’ll reference WindowConfig.width! and WindowConfig.height! (they’re typed as number | undefined by Electron’s BrowserWindowConstructorOptions but we always set them).
| let title: string; | ||
| let body: string; | ||
| let url: string = null; | ||
| let url = ''; |
There was a problem hiding this comment.
I believe raiseNativeNotification within src/preload/index.ts checks for null to determine whether to open the external link via a native notification. initializing to an empty string will break this logic
raiseNativeNotification: (title: string, body: string, url?: string) => {
const notification = new Notification(title, { body: body, silent: true });
notification.onclick = () => {
if (url) {
api.app.hide();
api.openExternalLink(url, true);
} else {
api.app.show();
}
};
return notification;
}
There was a problem hiding this comment.
You’re right, the preload checks if (url) which would be falsy for null but truthy for an empty string ''. I’ll change it back to url: string | null = null to preserve the existing behavior.
| try { | ||
| return safeStorage.decryptString(Buffer.from(value, 'base64')); | ||
| } catch (err) { | ||
| } catch (err: unknown) { |
There was a problem hiding this comment.
What are your thoughts on using something like this for the catch/err patterns, instead of the casting
} catch (err: unknown) {
if (err instanceof Error) {
......
}
}
There was a problem hiding this comment.
That’s much safer pattern for sure! I’ll switch all the catch (err: unknown) blocks to use instanceof Error checks. For the logError calls that expect Error, we can also wrap with a fallback: logError(..., err instanceof Error ? err : new Error(String(err))).


Summary
"strict": trueintsconfig.jsononMainEvent/handleMainEventIPC helpers to avoid type casting at every call sitenumber | nulldelay parameterglobalErrortype fromGitifyErrortoGitifyError | undefinednulltoundefinedin optional Gitify type fields for consistencyerr as Errorcasts in catch blocksTest plan
pnpm tsc --noEmitpasses with zero errors