From 6bec50bc32beea7f6f3f9178ff3320f5961f8d8f Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Wed, 24 Jan 2024 23:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=8F=AF=E4=BB=A5=E5=8D=87=E7=BA=A7=E5=88=B0http?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E7=9A=84=E5=87=BD=E6=95=B0(=E6=9C=AA?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E5=BA=94=E7=94=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/entry.js | 20 +++++++++++++++++++- game/game.js | 4 ++-- noname/init/index.js | 33 ++++++++++++++++++++++++++++++++- noname/util/index.js | 2 +- 4 files changed, 54 insertions(+), 5 deletions(-) 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();