diff --git a/game/entry.js b/game/entry.js index c450e7350..1c5249e6c 100644 --- a/game/entry.js +++ b/game/entry.js @@ -1,24 +1,5 @@ -/* - const module = import('../noname.js'); - - module.then(({ ai, game, get, lib, _status, ui, boot }) => { - const coreAndVersion = get.coreInfo(); - const core = coreAndVersion[0], version = coreAndVersion[1]; - if (core === 'chrome' && !isNaN(version) && version < 77) { - const tip = '检测到您的浏览器内核版本小于77,请及时升级浏览器或手机webview内核!'; - console.warn(tip); - game.print(tip); - const redirect_tip = '您使用的浏览器或无名杀客户端内核版本过低,将在未来的版本被废弃!\n点击“确认”以前往GitHub下载最新版无名杀客户端(可能需要科学上网)。'; - if (confirm(redirect_tip)) { - window.open('https://github.com/libccy/noname/releases/tag/chromium77-client'); - } - } - boot().then(lib.other.ignore); - }); - */ - import { game, get, lib, boot } from "../noname.js"; -// import { canUseHttpProtocol } from "../noname/init/index.js"; +import { canUseHttpProtocol } from "../noname/init/index.js"; import { userAgent } from "../noname/util/index.js"; const coreAndVersion = get.coreInfo(); @@ -34,20 +15,17 @@ if (core === 'chrome' && !isNaN(version) && version < 77) { } // 判断是否从file协议切换到http/s协议 -// if (canUseHttpProtocol()) { + if (canUseHttpProtocol()) { /* - 升级方法一: + 升级方法: 1. 导出数据,然后以http/s协议重启 2. 以http/s协议导入数据 3. 保存http/s协议的状态,以后不再以file协议启动 - 升级方法二: - 1. app默认以http/s协议启动,发现没有数据后,以file协议重启 - 2. 以file协议导出数据 - 3. 以http/s协议重启,导入数据 */ // 导出数据到根目录的noname.config.txt // 成功导入后应删除noname.config.txt -// } else { boot().then(lib.other.ignore); -// } + } else { + boot().then(lib.other.ignore); + } diff --git a/game/game.js b/game/game.js index 0e4a4181e..11484dfec 100644 --- a/game/game.js +++ b/game/game.js @@ -86,6 +86,23 @@ new Promise(resolve => { exit() } else { + // 在http环境下修改__dirname + if (location.protocol.startsWith('http') && + typeof window.require == 'function' && + typeof window.process == 'object' && + typeof window.__dirname == 'string' && + window.__dirname.endsWith('electron.asar\\renderer')) { + const path = require('path'); + window.__dirname = path.join(path.resolve(), 'resources/app'); + // @ts-ignore + window.require = function (moduleId) { + try { + return module.require(moduleId); + } catch { + return module.require(path.join(window.__dirname, moduleId)); + } + }; + } const script = document.createElement('script') script.type = "module"; script.src = `${assetURL}game/entry.js`; diff --git a/noname-server.exe b/noname-server.exe index 02b6d5629..b2c2b1f2a 100644 Binary files a/noname-server.exe and b/noname-server.exe differ diff --git a/noname/init/index.js b/noname/init/index.js index e380937c5..5de328619 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -30,11 +30,14 @@ export function canUseHttpProtocol() { } // 电脑端 else if (typeof window.require == 'function' && typeof window.process == 'object') { - try { - require('express'); - return true; - } catch { - return false; + // 从json判断版本号 + const fs = require('fs'); + const path = require('path'); + if (fs.existsSync(path.join(__dirname, 'package.json'))) { + // @ts-ignore + const json = require('./package.json'); + // 诗笺电脑版的判断 + return json && Number(json.installerVersion) >= 1.7; } } // 浏览器端