Skip to content

Commit

Permalink
Fix update-worker breakage caused by use of Window in desktop API code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pimterry committed Aug 15, 2023
1 parent bd9d252 commit c0b91e4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/services/desktop-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ interface NativeContextMenuSubmenu {
items: readonly NativeContextMenuItem[];
}

export const DesktopApi: DesktopApi = window.desktopApi ?? {};
// Quick fix to avoid this file crashing the update SW which doesn't have 'window' available, without
// also breaking old Electron that doesn't have globalThis:
const global = typeof globalThis !== 'undefined'
? globalThis
: typeof window !== 'undefined'
? window
: {};

export const DesktopApi: DesktopApi = global.desktopApi ?? {};

0 comments on commit c0b91e4

Please sign in to comment.