Skip to content

Commit 8aaee52

Browse files
committed
Register our own ServiceWorkerHandler
1 parent a438b5e commit 8aaee52

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

frontend/platform/Platform.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@ import { SettingsStorage } from "hydrogen-web/src/platform/web/dom/SettingsStora
33
import { Platform as BasePlatform } from "hydrogen-web/src/platform/web/Platform";
44
import { History } from "./History";
55
import { Navigation } from "./Navigation";
6+
import { ServiceWorkerHandler } from "./ServiceWorkerHandler";
67
import { StorageFactory } from "./StorageFactory";
78

89
export class Platform extends BasePlatform {
910
private settingsStorage: SettingsStorage;
1011
private sessionInfoStorage: SessionInfoStorage;
1112
private storageFactory: StorageFactory;
13+
private _serviceWorkerHandler: ServiceWorkerHandler;
1214

1315
constructor(options) {
16+
const assetPaths = structuredClone(options.assetPaths);
17+
18+
// Unset serviceWorker path so that the base constructor doesn't register the service worker handler.
19+
delete options.assetPaths.serviceWorker;
1420
super(options);
21+
22+
// Register our own service worker handler.
23+
if (assetPaths.serviceWorker && "serviceWorker" in navigator) {
24+
this._serviceWorkerHandler = new ServiceWorkerHandler();
25+
this._serviceWorkerHandler.registerAndStart(assetPaths.serviceWorker);
26+
}
27+
1528
this.settingsStorage = new SettingsStorage("chatrix_setting_v1_");
1629
this.sessionInfoStorage = new SessionInfoStorage("chatrix_sessions_v1");
17-
// @ts-ignore
1830
this.storageFactory = new StorageFactory(this._serviceWorkerHandler);
19-
// @ts-ignore
2031
this.history = new History();
2132
}
2233

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ServiceWorkerHandler as BaseHandler } from "hydrogen-web/src/platform/web/dom/ServiceWorkerHandler.js";
2+
3+
export class ServiceWorkerHandler extends BaseHandler {
4+
public registerAndStart(path: string) {
5+
super.registerAndStart(path);
6+
}
7+
8+
public async preventConcurrentSessionAccess(sessionId: string) {
9+
return super._sendAndWaitForReply("closeSession", { sessionId });
10+
}
11+
}

0 commit comments

Comments
 (0)