Skip to content

Commit cc7ab25

Browse files
committed
Fix update-worker breakage caused by use of Window in desktop API code
Window is not defined in service workers. The service worker code does import service-versions though, which in turn imports desktop-apis. This is a quick fix for this issue, avoiding directly depending on 'window' which results in the update-worker failing to run. It would be better to avoid loading this file entirely, using a dynamic import or something more thorough, but Webpack v4 seems to fail to handle dynamic imports in this case, so that's not possible for now. It would be even better to solve this more structurally - e.g. checking the service worker actually installs OK in a test - but that's hard and this fixes the immediate production issue for now.
1 parent bd9d252 commit cc7ab25

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/services/desktop-api.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ interface NativeContextMenuSubmenu {
5656
items: readonly NativeContextMenuItem[];
5757
}
5858

59-
export const DesktopApi: DesktopApi = window.desktopApi ?? {};
59+
// Quick fix to avoid this file crashing the update SW which doesn't have 'window' available, without
60+
// also breaking old Electron that doesn't have globalThis:
61+
const global = typeof globalThis !== 'undefined'
62+
? globalThis as unknown as Window
63+
: typeof window !== 'undefined'
64+
? window
65+
: {} as Window;
66+
67+
export const DesktopApi: DesktopApi = global.desktopApi ?? {};

0 commit comments

Comments
 (0)