添加判断是否可以升级到http协议的函数(未实际应用)

This commit is contained in:
nonameShijian 2024-01-24 23:24:02 +08:00
parent feeea1fe77
commit 6bec50bc32
4 changed files with 54 additions and 5 deletions

View File

@ -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);
// }

View File

@ -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 = () => {

View File

@ -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() {
// 不想看,反正别动

View File

@ -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();