diff --git a/game/game.js b/game/game.js index d0f6d0515..6852cca3c 100644 --- a/game/game.js +++ b/game/game.js @@ -11,36 +11,41 @@ new Promise(resolve => { } }).then(() => { const userAgent = navigator.userAgent.toLowerCase(); + + const exit = () => { + const ios = userAgent.includes('iphone') || userAgent.includes('ipad') || userAgent.includes('macintosh'); + //electron + if (typeof window.process == 'object' && typeof window.require == 'function') { + const versions = window.process.versions; + // @ts-ignore + const electronVersion = parseFloat(versions.electron); + let remote; + if (electronVersion >= 14) { + // @ts-ignore + remote = require('@electron/remote'); + } else { + // @ts-ignore + remote = require('electron').remote; + } + const thisWindow = remote.getCurrentWindow(); + thisWindow.destroy(); + window.process.exit(); + } + //android-cordova环境 + //ios-cordova环境或ios浏览器环境 + //非ios的网页版 + else if (!ios) { + window.close(); + } + }; + if (!localStorage.getItem('gplv3_noname_alerted')) { if (confirm('①无名杀是一款基于GPLv3协议的开源软件!\n你可以在遵守GPLv3协议的基础上任意使用,修改并转发《无名杀》,以及所有基于《无名杀》开发的拓展。\n点击“确定”即代表您认可并接受GPLv3协议↓️\nhttps://www.gnu.org/licenses/gpl-3.0.html\n②无名杀官方发布地址仅有GitHub仓库!\n其他所有的所谓“无名杀”社群(包括但不限于绝大多数“官方”QQ群、QQ频道等)均为玩家自发组织,与无名杀官方无关!')) { // @ts-ignore localStorage.setItem('gplv3_noname_alerted', true); } else { - const ios = userAgent.includes('iphone') || userAgent.includes('ipad') || userAgent.includes('macintosh'); - //electron - if (typeof window.process == 'object' && typeof window.require == 'function') { - const versions = window.process.versions; - // @ts-ignore - const electronVersion = parseFloat(versions.electron); - let remote; - if (electronVersion >= 14) { - // @ts-ignore - remote = require('@electron/remote'); - } else { - // @ts-ignore - remote = require('electron').remote; - } - const thisWindow = remote.getCurrentWindow(); - thisWindow.destroy(); - window.process.exit(); - } - //android-cordova环境 - //ios-cordova环境或ios浏览器环境 - //非ios的网页版 - else if (!ios) { - window.close(); - } + exit(); } } window['b' + 'ann' + 'e' + 'dE' + 'x' + 'ten' + 's' + 'i' + 'o' + 'ns'] = ['\u4fa0\u4e49', '\u5168\u6559\u7a0b']; diff --git a/noname/init/index.js b/noname/init/index.js index f5049f3b8..95f1017dc 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -83,11 +83,12 @@ export async function boot() { } // 在dom加载完后执行相应的操作 - if (document.readyState !== 'complete') { - window.onload = onWindowReady; - } else { - onWindowReady.call(window); - } + const waitDomLoad = new Promise((resolve) => { + if (document.readyState !== 'complete') { + window.onload = resolve; + } else resolve(void 0) + }).then(onWindowReady.bind(window)); + // 闭源客户端检测并提醒 if (lib.assetURL.includes('com.widget.noname.qingyao') || lib.assetURL.includes('online.nonamekill.android')) { @@ -555,11 +556,8 @@ export async function boot() { delete _status.importing; } - if (_status.windowLoaded) { - delete _status.windowLoaded; - lib.init.onload(); - } - else _status.packLoaded = true; + await waitDomLoad; + lib.init.onload(); } /** @@ -744,16 +742,21 @@ async function loadCss() { }); } -function onWindowReady() { +async function onWindowReady() { if (Reflect.has(lib, 'device')) { var script = document.createElement('script'); script.src = 'cordova.js'; document.body.appendChild(script); + // @ts-ignore + const { promise, resolve } = Promise.withResolvers(); document.addEventListener('deviceready', async () => { const { cordovaReady } = await import('./cordova.js'); await cordovaReady(); + resolve() }); + await promise; } + /* if (_status.packLoaded) { delete _status.packLoaded; lib.init.onload(); @@ -761,6 +764,7 @@ function onWindowReady() { else { _status.windowLoaded = true; } + */ } function setBackground() { diff --git a/noname/init/node.js b/noname/init/node.js index 58e32ad1f..f365661c6 100644 --- a/noname/init/node.js +++ b/noname/init/node.js @@ -9,8 +9,16 @@ export function nodeReady() { lib.node = { fs: require('fs'), path: require("path"), - debug: function () { - require('electron').remote.getCurrentWindow().toggleDevTools(); + debug() { + let remote; + if (electronVersion >= 14) { + // @ts-ignore + remote = require('@electron/remote'); + } else { + // @ts-ignore + remote = require('electron').remote; + } + remote.getCurrentWindow().toggleDevTools(); } }; lib.path = lib.node.path;