为调试模式追加支持
This commit is contained in:
parent
b4a5dec0f1
commit
2ebcbb3a38
|
@ -125,9 +125,6 @@ export async function boot() {
|
||||||
// 加载polyfill内容
|
// 加载polyfill内容
|
||||||
await import("./polyfill.js");
|
await import("./polyfill.js");
|
||||||
|
|
||||||
// 初始化沙盒的Realms
|
|
||||||
await initializeSandboxRealms();
|
|
||||||
|
|
||||||
// 设定游戏加载时间,超过时间未加载就提醒
|
// 设定游戏加载时间,超过时间未加载就提醒
|
||||||
const configLoadTime = localStorage.getItem(lib.configprefix + "loadtime");
|
const configLoadTime = localStorage.getItem(lib.configprefix + "loadtime");
|
||||||
// 现在不暴露到全局变量里了,直接传给onload
|
// 现在不暴露到全局变量里了,直接传给onload
|
||||||
|
@ -248,13 +245,6 @@ export async function boot() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化security
|
|
||||||
const securityModule = await import("../util/security.js");
|
|
||||||
const security = securityModule.default;
|
|
||||||
security.initSecurity({
|
|
||||||
lib, game, ui, get, ai, _status, gnc,
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadCssPromise = loadCss();
|
const loadCssPromise = loadCss();
|
||||||
const loadConfigPromise = loadConfig();
|
const loadConfigPromise = loadConfig();
|
||||||
await loadCssPromise;
|
await loadCssPromise;
|
||||||
|
@ -303,6 +293,18 @@ export async function boot() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sandboxEnabled = !config.get("debug") && !get.is.safari();
|
||||||
|
|
||||||
|
// 初始化沙盒的Realms
|
||||||
|
await initializeSandboxRealms(sandboxEnabled);
|
||||||
|
|
||||||
|
// 初始化security
|
||||||
|
const securityModule = await import("../util/security.js");
|
||||||
|
const security = securityModule.default;
|
||||||
|
security.initSecurity({
|
||||||
|
lib, game, ui, get, ai, _status, gnc,
|
||||||
|
});
|
||||||
|
|
||||||
if (Reflect.get(window, "isNonameServer")) config.set("mode", "connect");
|
if (Reflect.get(window, "isNonameServer")) config.set("mode", "connect");
|
||||||
|
|
||||||
var pack = Reflect.get(window, "noname_package");
|
var pack = Reflect.get(window, "noname_package");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// 为了兼容无法使用顶级await的版本
|
// 方便开关确定沙盒的问题喵
|
||||||
const iframe = document.createElement("iframe");
|
// 当此处为true、debug模式为启用、设备非苹果时,沙盒生效
|
||||||
|
let SANDBOX_ENABLED = true;
|
||||||
|
|
||||||
// 执行上下文传递函数,请勿动喵
|
// 执行上下文传递函数,请勿动喵
|
||||||
// 用于传递顶级execute context
|
// 用于传递顶级execute context
|
||||||
|
@ -38,7 +39,12 @@ function replaceName(path, name) {
|
||||||
const TARGET_URL = replaceName(import.meta.url, "sandbox.js");
|
const TARGET_URL = replaceName(import.meta.url, "sandbox.js");
|
||||||
const SANDBOX_EXPORT = {};
|
const SANDBOX_EXPORT = {};
|
||||||
|
|
||||||
async function initializeSandboxRealms() {
|
async function initializeSandboxRealms(enabled) {
|
||||||
|
if (!enabled) {
|
||||||
|
SANDBOX_ENABLED = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const document = window.document;
|
const document = window.document;
|
||||||
const createElement = document.createElement.bind(document);
|
const createElement = document.createElement.bind(document);
|
||||||
const appendChild = document.body.appendChild.bind(document.body);
|
const appendChild = document.body.appendChild.bind(document.body);
|
||||||
|
@ -86,10 +92,6 @@ async function initializeSandboxRealms() {
|
||||||
script.src = TARGET_URL;
|
script.src = TARGET_URL;
|
||||||
script.type = "module";
|
script.type = "module";
|
||||||
|
|
||||||
// 无法同步载入
|
|
||||||
// script.async = false;
|
|
||||||
// script.defer = false;
|
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
script.onload = resolve;
|
script.onload = resolve;
|
||||||
script.onerror = reject;
|
script.onerror = reject;
|
||||||
|
@ -111,7 +113,12 @@ async function initializeSandboxRealms() {
|
||||||
iframe.remove();
|
iframe.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isSandboxEnabled() {
|
||||||
|
return SANDBOX_ENABLED;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
initializeSandboxRealms,
|
initializeSandboxRealms,
|
||||||
|
isSandboxEnabled,
|
||||||
SANDBOX_EXPORT,
|
SANDBOX_EXPORT,
|
||||||
};
|
};
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// 最后为安全考虑,请遵守规范,尽量不要使用 `eval` 函数而是使用 `security.exec2` 来替代
|
// 最后为安全考虑,请遵守规范,尽量不要使用 `eval` 函数而是使用 `security.exec2` 来替代
|
||||||
|
|
||||||
import { SANDBOX_EXPORT } from "./initRealms.js";
|
import { SANDBOX_EXPORT, isSandboxEnabled } from "./initRealms.js";
|
||||||
|
|
||||||
// 很重要的事情!
|
// 很重要的事情!
|
||||||
// 请不要在在其他文件中import sandbox.js!
|
// 请不要在在其他文件中import sandbox.js!
|
||||||
|
@ -16,8 +16,8 @@ import { SANDBOX_EXPORT } from "./initRealms.js";
|
||||||
|
|
||||||
/** @typedef {any} Window */
|
/** @typedef {any} Window */
|
||||||
|
|
||||||
// 方便开关确定沙盒的问题喵
|
// 新的开关放到了 "./initRealms.js" 里面,请不要改动此处!
|
||||||
const SANDBOX_ENABLED = true;
|
const SANDBOX_ENABLED = isSandboxEnabled();
|
||||||
|
|
||||||
// 暴露方法Symbol,用于类之间通信
|
// 暴露方法Symbol,用于类之间通信
|
||||||
const SandboxExposer = Symbol("Sandbox.Exposer"); // 实例暴露
|
const SandboxExposer = Symbol("Sandbox.Exposer"); // 实例暴露
|
||||||
|
|
Loading…
Reference in New Issue