web: Use publicPath() instead of ruffleRuntimePath

Similarly to how selfhosted currently does.
This commit is contained in:
relrelb 2021-03-09 22:33:20 +02:00 committed by Mike Welsh
parent 1aa77b04fe
commit 56cece3336
6 changed files with 12 additions and 37 deletions

View File

@ -1,9 +1,7 @@
/* eslint @typescript-eslint/naming-convention:off */
declare let __webpack_public_path__: string;
declare let ruffleRuntimePath: string;
interface Error {
ruffleIsExtension?: boolean;
ruffleIndexError?: number;
}

View File

@ -22,36 +22,13 @@ async function fetchRuffle(): Promise<{ new (...args: any[]): Ruffle }> {
// libraries, if needed.
setPolyfillsOnLoad();
let isExtension = true;
try {
// If ruffleRuntimePath is defined then we are executing inside the extension
// closure. In that case, we configure our local Webpack instance.
__webpack_public_path__ = ruffleRuntimePath + "dist/";
} catch (e) {
// Checking an undefined closure variable usually throws ReferenceError,
// so we need to catch it here and continue onward.
if (!(e instanceof ReferenceError)) {
throw e;
}
isExtension = false;
}
// We currently assume that if we are not executing inside the extension,
// then we can use webpack to get Ruffle.
try {
// wasm files are set to use file-loader,
// so this package will resolve to the URL of the wasm file.
const ruffleWasm = await import(
/* webpackMode: "eager" */
"../pkg/ruffle_web_bg.wasm"
);
await init(ruffleWasm.default);
} catch (e) {
e.ruffleIsExtension = isExtension;
throw e;
}
// wasm files are set to use file-loader,
// so this package will resolve to the URL of the wasm file.
const ruffleWasm = await import(
/* webpackMode: "eager" */
"../pkg/ruffle_web_bg.wasm"
);
await init(ruffleWasm.default);
return Ruffle;
}

View File

@ -346,7 +346,7 @@ export class RufflePlayer extends HTMLElement {
// Serious duck typing. In error conditions, let's not make assumptions.
if (window.location.protocol === "file:") {
e.ruffleIndexError = PanicError.FileProtocol;
} else if (!e.ruffleIsExtension) {
} else {
e.ruffleIndexError = PanicError.WasmNotFound;
const message = String(e.message).toLowerCase();
if (message.includes("mime")) {

View File

@ -4,6 +4,7 @@
"webextensions": true
},
"globals": {
"__webpack_public_path__": true,
"obfuscatedEventPrefix": true
}
}

View File

@ -1,10 +1,11 @@
import { PublicAPI, SourceAPI } from "ruffle-core";
import { PublicAPI, SourceAPI, publicPath } from "ruffle-core";
window.RufflePlayer = PublicAPI.negotiate(
window.RufflePlayer,
"extension",
new SourceAPI("extension")
);
__webpack_public_path__ = publicPath(window.RufflePlayer.config, "extension");
if (obfuscatedEventPrefix) {
document.addEventListener(obfuscatedEventPrefix + "_request", function (e) {

View File

@ -154,9 +154,7 @@ getSyncStorage(["ruffleEnable", "ignoreOptout"], function (data) {
let ruffleSrcResp = await fetch(extPath + "dist/ruffle.js");
if (ruffleSrcResp.ok) {
let ruffleSource =
'(function () { var ruffleRuntimePath = "' +
extPath +
'";\nvar obfuscatedEventPrefix = "' +
'(function () { var obfuscatedEventPrefix = "' +
obfuscatedEventPrefix +
'";\n' +
(await ruffleSrcResp.text()) +