chore: convert sw.js to typescript

This commit is contained in:
sua yoo
2023-11-29 15:54:44 -05:00
committed by emma
parent 9231ca0f34
commit 49246fee61
2 changed files with 11 additions and 4 deletions
+1
View File
@@ -1,4 +1,5 @@
declare module "*.svg";
declare module "*.html";
declare const __SW_NAME__: string;
declare const __HELPER_PROXY__: string;
declare const __GDRIVE_CLIENT_ID__: string;
+10 -4
View File
@@ -4,10 +4,16 @@ import { SWReplay } from "@webrecorder/wabac/src/swmain";
import { WorkerLoader } from "@webrecorder/wabac/src/loaders";
if (self.registration) {
type Self = Window &
typeof globalThis & {
registration: { scope: string };
sw: SWReplay;
};
if ((self as Self).registration) {
const staticData = new Map();
const prefix = self.registration.scope;
const prefix = (self as Self).registration.scope;
staticData.set(prefix, { type: "text/html", content: INDEX_HTML });
staticData.set(prefix + "index.html", {
@@ -17,13 +23,13 @@ if (self.registration) {
const sp = new URLSearchParams(self.location.search);
const defaultConfig = {};
const defaultConfig: { injectScripts?: string[] } = {};
if (sp.get("ruffle") == "1") {
defaultConfig.injectScripts = ["ruffle/ruffle.js"];
}
self.sw = new SWReplay({ staticData, defaultConfig });
(self as Self).sw = new SWReplay({ staticData, defaultConfig });
} else {
new WorkerLoader(self);
}