diff --git a/game/entry.js b/game/entry.js index 977122c0f..c450e7350 100644 --- a/game/entry.js +++ b/game/entry.js @@ -18,6 +18,7 @@ */ import { game, get, lib, boot } from "../noname.js"; +// import { canUseHttpProtocol } from "../noname/init/index.js"; import { userAgent } from "../noname/util/index.js"; const coreAndVersion = get.coreInfo(); @@ -31,5 +32,22 @@ if (core === 'chrome' && !isNaN(version) && version < 77) { window.open('https://github.com/libccy/noname/releases/tag/chromium77-client'); } } -boot().then(lib.other.ignore); + +// 判断是否从file协议切换到http/s协议 +// 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); +// } diff --git a/game/game.js b/game/game.js index 74670ccdc..0e4a4181e 100644 --- a/game/game.js +++ b/game/game.js @@ -5,7 +5,7 @@ new Promise(resolve => { if ('__core-js_shared__' in window) resolve(null); else { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); + const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; const coreJSBundle = document.createElement('script'); coreJSBundle.onerror = coreJSBundle.onload = resolve; coreJSBundle.src = `${assetURL}game/core-js-bundle.js`; @@ -13,7 +13,7 @@ new Promise(resolve => { } }).then(() => { const nonameInitialized = localStorage.getItem('noname_inited'); - const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); + const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; const userAgent = navigator.userAgent.toLowerCase(); const exit = () => { diff --git a/noname/init/index.js b/noname/init/index.js index 489fdf6be..a3f9d8888 100644 --- a/noname/init/index.js +++ b/noname/init/index.js @@ -6,7 +6,7 @@ import { Game as game } from '../game/index.js'; import { status as _status } from '../status/index.js'; import { UI as ui } from '../ui/index.js'; -import { userAgent } from '../util/index.js'; +import { userAgent, nonameInitialized } from '../util/index.js'; import * as config from '../util/config.js'; import { promiseErrorHandlerMap } from '../util/browser.js'; import { gnc } from '../gnc/index.js'; @@ -14,6 +14,37 @@ import { gnc } from '../gnc/index.js'; import { importCardPack, importCharacterPack, importExtension, importMode } from './import.js'; import { onload } from './onload.js'; +// 判断是否从file协议切换到http/s协议 +export function canUseHttpProtocol() { + // 如果是http了就不用 + if (location.protocol.startsWith('http')) return false; + if (typeof nonameInitialized == 'string') { + // 手机端 + if (window.cordova) { + // 直接确定包名 + if (nonameInitialized.includes('com.noname.shijian')) { + // 每个app自定义能升级的渠道,比如判断版本 + // @ts-ignore + window.noname_shijianInterfaces.getApkVersion() >= 16000; + } + } + // 电脑端 + else if (typeof window.require == 'function' && typeof window.process == 'object') { + try { + require('express'); + return true; + } catch { + return false; + } + } + // 浏览器端 + else { + return location.protocol.startsWith('http'); + } + } + return false; +} + // 无名杀,启动! export async function boot() { // 不想看,反正别动 diff --git a/noname/util/index.js b/noname/util/index.js index 724ec163f..875385419 100644 --- a/noname/util/index.js +++ b/noname/util/index.js @@ -1,5 +1,5 @@ export const nonameInitialized = localStorage.getItem('noname_inited'); -export const assetURL = location.protocol.startsWith('http') ? '' : (typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized); +export const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; export const GeneratorFunction = (function* () { }).constructor; export const AsyncFunction = (async function () { }).constructor; export const userAgent = navigator.userAgent.toLowerCase();