-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silently apply updates instead of asking user to confirm
- Loading branch information
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import { ServiceWorkerHandler as BaseHandler } from "hydrogen-web/src/platform/web/dom/ServiceWorkerHandler.js"; | ||
|
||
export class ServiceWorkerHandler extends BaseHandler { | ||
private get registration() { | ||
return super.getRegistration(); | ||
} | ||
|
||
public registerAndStart(path: string) { | ||
super.registerAndStart(path); | ||
} | ||
|
||
public async preventConcurrentSessionAccess(sessionId: string) { | ||
return super._sendAndWaitForReply("closeSession", { sessionId }); | ||
return this._sendAndWaitForReply("closeSession", { sessionId }); | ||
} | ||
|
||
async _proposeUpdate() { | ||
if (document.hidden) { | ||
return; | ||
} | ||
|
||
const version = await this._sendAndWaitForReply("version", null, this.registration.waiting); | ||
|
||
// Prevent any fetch requests from going to the service worker from any client, | ||
// so that it's not kept active when calling skipWaiting on the new one. | ||
await this._sendAndWaitForReply("haltRequests", null); | ||
|
||
console.log(`Updating to version ${version.version} (${version.buildHash})`); | ||
|
||
// Once all requests are blocked, ask the new service worker to skipWaiting. | ||
return this._send("skipWaiting", null, this.registration.waiting); | ||
} | ||
|
||
async _sendAndWaitForReply(type, payload: {}|null, worker = undefined) { | ||
return super._sendAndWaitForReply(type, payload, worker); | ||
} | ||
|
||
async _send(type, payload, worker = undefined) { | ||
return super._send(type, payload, worker); | ||
} | ||
} |