添加判断是否可以升级到http协议的函数(未实际应用)
This commit is contained in:
parent
feeea1fe77
commit
6bec50bc32
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { game, get, lib, boot } from "../noname.js";
|
import { game, get, lib, boot } from "../noname.js";
|
||||||
|
// import { canUseHttpProtocol } from "../noname/init/index.js";
|
||||||
import { userAgent } from "../noname/util/index.js";
|
import { userAgent } from "../noname/util/index.js";
|
||||||
|
|
||||||
const coreAndVersion = get.coreInfo();
|
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');
|
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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ new Promise(resolve => {
|
||||||
if ('__core-js_shared__' in window) resolve(null);
|
if ('__core-js_shared__' in window) resolve(null);
|
||||||
else {
|
else {
|
||||||
const nonameInitialized = localStorage.getItem('noname_inited');
|
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');
|
const coreJSBundle = document.createElement('script');
|
||||||
coreJSBundle.onerror = coreJSBundle.onload = resolve;
|
coreJSBundle.onerror = coreJSBundle.onload = resolve;
|
||||||
coreJSBundle.src = `${assetURL}game/core-js-bundle.js`;
|
coreJSBundle.src = `${assetURL}game/core-js-bundle.js`;
|
||||||
|
@ -13,7 +13,7 @@ new Promise(resolve => {
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const nonameInitialized = localStorage.getItem('noname_inited');
|
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 userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
|
||||||
const exit = () => {
|
const exit = () => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { Game as game } from '../game/index.js';
|
||||||
import { status as _status } from '../status/index.js';
|
import { status as _status } from '../status/index.js';
|
||||||
import { UI as ui } from '../ui/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 * as config from '../util/config.js';
|
||||||
import { promiseErrorHandlerMap } from '../util/browser.js';
|
import { promiseErrorHandlerMap } from '../util/browser.js';
|
||||||
import { gnc } from '../gnc/index.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 { importCardPack, importCharacterPack, importExtension, importMode } from './import.js';
|
||||||
import { onload } from './onload.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() {
|
export async function boot() {
|
||||||
// 不想看,反正别动
|
// 不想看,反正别动
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export const nonameInitialized = localStorage.getItem('noname_inited');
|
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 GeneratorFunction = (function* () { }).constructor;
|
||||||
export const AsyncFunction = (async function () { }).constructor;
|
export const AsyncFunction = (async function () { }).constructor;
|
||||||
export const userAgent = navigator.userAgent.toLowerCase();
|
export const userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
|
Loading…
Reference in New Issue