-
-
Notifications
You must be signed in to change notification settings - Fork 861
fix(electron): disable service worker in desktop runtime #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,33 @@ export function getRuntimeBackendUrl(): string { | |
| ); | ||
| } | ||
|
|
||
| export interface ServiceWorkerRuntimeContext { | ||
| readonly electronBridge?: unknown; | ||
| readonly protocol?: string; | ||
| } | ||
|
|
||
| function getDefaultServiceWorkerRuntimeContext(): ServiceWorkerRuntimeContext { | ||
| const browserWindow = globalThis.window as | ||
| | (Window & { electron?: unknown }) | ||
| | undefined; | ||
|
|
||
| return { | ||
| electronBridge: browserWindow?.electron, | ||
| protocol: | ||
| browserWindow?.location?.protocol ?? globalThis.location?.protocol, | ||
| }; | ||
| } | ||
|
|
||
| export function shouldEnableServiceWorker( | ||
| production = AppConfig.production, | ||
| navigatorRef: Navigator | undefined = globalThis.navigator | ||
| navigatorRef: Navigator | undefined = globalThis.navigator, | ||
| runtimeContext = getDefaultServiceWorkerRuntimeContext() | ||
| ): boolean { | ||
| return production && !!navigatorRef && 'serviceWorker' in navigatorRef; | ||
| return ( | ||
| production && | ||
| !!navigatorRef && | ||
| 'serviceWorker' in navigatorRef && | ||
| !runtimeContext.electronBridge && | ||
| runtimeContext.protocol !== 'file:' | ||
|
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a user upgrades from a desktop version that already registered Useful? React with 👍 / 👎. |
||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
electronBridge-only guardThe Electron test always supplies both
electronBridgeandprotocol: 'file:', so neither condition is ever isolated. If an Electron build ever uses a non-file:scheme (e.g.app://or a customiptvnator://protocol), the only guard that fires is!electronBridge, but no test exercises that path. Adding a case whereelectronBridgeis set andprotocolis'https:'(or any non-file:value) would pin that contract.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!