web: Use publicPath() instead of ruffleRuntimePath
Similarly to how selfhosted currently does.
This commit is contained in:
parent
1aa77b04fe
commit
56cece3336
|
@ -1,9 +1,7 @@
|
||||||
/* eslint @typescript-eslint/naming-convention:off */
|
/* eslint @typescript-eslint/naming-convention:off */
|
||||||
|
|
||||||
declare let __webpack_public_path__: string;
|
declare let __webpack_public_path__: string;
|
||||||
declare let ruffleRuntimePath: string;
|
|
||||||
|
|
||||||
interface Error {
|
interface Error {
|
||||||
ruffleIsExtension?: boolean;
|
|
||||||
ruffleIndexError?: number;
|
ruffleIndexError?: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,36 +22,13 @@ async function fetchRuffle(): Promise<{ new (...args: any[]): Ruffle }> {
|
||||||
// libraries, if needed.
|
// libraries, if needed.
|
||||||
setPolyfillsOnLoad();
|
setPolyfillsOnLoad();
|
||||||
|
|
||||||
let isExtension = true;
|
// wasm files are set to use file-loader,
|
||||||
|
// so this package will resolve to the URL of the wasm file.
|
||||||
try {
|
const ruffleWasm = await import(
|
||||||
// If ruffleRuntimePath is defined then we are executing inside the extension
|
/* webpackMode: "eager" */
|
||||||
// closure. In that case, we configure our local Webpack instance.
|
"../pkg/ruffle_web_bg.wasm"
|
||||||
__webpack_public_path__ = ruffleRuntimePath + "dist/";
|
);
|
||||||
} catch (e) {
|
await init(ruffleWasm.default);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ruffle;
|
return Ruffle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,7 +346,7 @@ export class RufflePlayer extends HTMLElement {
|
||||||
// Serious duck typing. In error conditions, let's not make assumptions.
|
// Serious duck typing. In error conditions, let's not make assumptions.
|
||||||
if (window.location.protocol === "file:") {
|
if (window.location.protocol === "file:") {
|
||||||
e.ruffleIndexError = PanicError.FileProtocol;
|
e.ruffleIndexError = PanicError.FileProtocol;
|
||||||
} else if (!e.ruffleIsExtension) {
|
} else {
|
||||||
e.ruffleIndexError = PanicError.WasmNotFound;
|
e.ruffleIndexError = PanicError.WasmNotFound;
|
||||||
const message = String(e.message).toLowerCase();
|
const message = String(e.message).toLowerCase();
|
||||||
if (message.includes("mime")) {
|
if (message.includes("mime")) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"webextensions": true
|
"webextensions": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
|
"__webpack_public_path__": true,
|
||||||
"obfuscatedEventPrefix": true
|
"obfuscatedEventPrefix": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { PublicAPI, SourceAPI } from "ruffle-core";
|
import { PublicAPI, SourceAPI, publicPath } from "ruffle-core";
|
||||||
|
|
||||||
window.RufflePlayer = PublicAPI.negotiate(
|
window.RufflePlayer = PublicAPI.negotiate(
|
||||||
window.RufflePlayer,
|
window.RufflePlayer,
|
||||||
"extension",
|
"extension",
|
||||||
new SourceAPI("extension")
|
new SourceAPI("extension")
|
||||||
);
|
);
|
||||||
|
__webpack_public_path__ = publicPath(window.RufflePlayer.config, "extension");
|
||||||
|
|
||||||
if (obfuscatedEventPrefix) {
|
if (obfuscatedEventPrefix) {
|
||||||
document.addEventListener(obfuscatedEventPrefix + "_request", function (e) {
|
document.addEventListener(obfuscatedEventPrefix + "_request", function (e) {
|
||||||
|
|
|
@ -154,9 +154,7 @@ getSyncStorage(["ruffleEnable", "ignoreOptout"], function (data) {
|
||||||
let ruffleSrcResp = await fetch(extPath + "dist/ruffle.js");
|
let ruffleSrcResp = await fetch(extPath + "dist/ruffle.js");
|
||||||
if (ruffleSrcResp.ok) {
|
if (ruffleSrcResp.ok) {
|
||||||
let ruffleSource =
|
let ruffleSource =
|
||||||
'(function () { var ruffleRuntimePath = "' +
|
'(function () { var obfuscatedEventPrefix = "' +
|
||||||
extPath +
|
|
||||||
'";\nvar obfuscatedEventPrefix = "' +
|
|
||||||
obfuscatedEventPrefix +
|
obfuscatedEventPrefix +
|
||||||
'";\n' +
|
'";\n' +
|
||||||
(await ruffleSrcResp.text()) +
|
(await ruffleSrcResp.text()) +
|
||||||
|
|
Loading…
Reference in New Issue