pref: change init logic.

This commit is contained in:
Rintim 2023-12-25 21:05:19 +08:00
parent c9a8f3d6a3
commit 01c23586cf
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
3 changed files with 54 additions and 37 deletions

View File

@ -11,36 +11,41 @@ new Promise(resolve => {
} }
}).then(() => { }).then(() => {
const userAgent = navigator.userAgent.toLowerCase(); 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 (!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频道等均为玩家自发组织与无名杀官方无关')) { if (confirm('①无名杀是一款基于GPLv3协议的开源软件\n你可以在遵守GPLv3协议的基础上任意使用修改并转发《无名杀》以及所有基于《无名杀》开发的拓展。\n点击“确定”即代表您认可并接受GPLv3协议↓\nhttps://www.gnu.org/licenses/gpl-3.0.html\n②无名杀官方发布地址仅有GitHub仓库\n其他所有的所谓“无名杀”社群包括但不限于绝大多数“官方”QQ群、QQ频道等均为玩家自发组织与无名杀官方无关')) {
// @ts-ignore // @ts-ignore
localStorage.setItem('gplv3_noname_alerted', true); localStorage.setItem('gplv3_noname_alerted', true);
} }
else { else {
const ios = userAgent.includes('iphone') || userAgent.includes('ipad') || userAgent.includes('macintosh'); exit();
//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();
}
} }
} }
window['b' + 'ann' + 'e' + 'dE' + 'x' + 'ten' + 's' + 'i' + 'o' + 'ns'] = ['\u4fa0\u4e49', '\u5168\u6559\u7a0b']; window['b' + 'ann' + 'e' + 'dE' + 'x' + 'ten' + 's' + 'i' + 'o' + 'ns'] = ['\u4fa0\u4e49', '\u5168\u6559\u7a0b'];

View File

@ -83,11 +83,12 @@ export async function boot() {
} }
// 在dom加载完后执行相应的操作 // 在dom加载完后执行相应的操作
if (document.readyState !== 'complete') { const waitDomLoad = new Promise((resolve) => {
window.onload = onWindowReady; if (document.readyState !== 'complete') {
} else { window.onload = resolve;
onWindowReady.call(window); } else resolve(void 0)
} }).then(onWindowReady.bind(window));
// 闭源客户端检测并提醒 // 闭源客户端检测并提醒
if (lib.assetURL.includes('com.widget.noname.qingyao') || lib.assetURL.includes('online.nonamekill.android')) { 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; delete _status.importing;
} }
if (_status.windowLoaded) { await waitDomLoad;
delete _status.windowLoaded; lib.init.onload();
lib.init.onload();
}
else _status.packLoaded = true;
} }
/** /**
@ -744,16 +742,21 @@ async function loadCss() {
}); });
} }
function onWindowReady() { async function onWindowReady() {
if (Reflect.has(lib, 'device')) { if (Reflect.has(lib, 'device')) {
var script = document.createElement('script'); var script = document.createElement('script');
script.src = 'cordova.js'; script.src = 'cordova.js';
document.body.appendChild(script); document.body.appendChild(script);
// @ts-ignore
const { promise, resolve } = Promise.withResolvers();
document.addEventListener('deviceready', async () => { document.addEventListener('deviceready', async () => {
const { cordovaReady } = await import('./cordova.js'); const { cordovaReady } = await import('./cordova.js');
await cordovaReady(); await cordovaReady();
resolve()
}); });
await promise;
} }
/*
if (_status.packLoaded) { if (_status.packLoaded) {
delete _status.packLoaded; delete _status.packLoaded;
lib.init.onload(); lib.init.onload();
@ -761,6 +764,7 @@ function onWindowReady() {
else { else {
_status.windowLoaded = true; _status.windowLoaded = true;
} }
*/
} }
function setBackground() { function setBackground() {

View File

@ -9,8 +9,16 @@ export function nodeReady() {
lib.node = { lib.node = {
fs: require('fs'), fs: require('fs'),
path: require("path"), path: require("path"),
debug: function () { debug() {
require('electron').remote.getCurrentWindow().toggleDevTools(); 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; lib.path = lib.node.path;