Merge pull request #1265 from nonameShijian/PR-Branch

增加由理版升级逻辑判断
This commit is contained in:
Spmario233 2024-04-24 14:49:57 +08:00 committed by GitHub
commit cef13360a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 19 deletions

View File

@ -22,6 +22,23 @@ if (core === "chrome" && !isNaN(version) && version < 77) {
boot().then(() => { boot().then(() => {
// 判断是否从file协议切换到http/s协议 // 判断是否从file协议切换到http/s协议
if (canUseHttpProtocol()) { if (canUseHttpProtocol()) {
// 保存协议的切换状态
const saveProtocol = () => {
const url = sendUpdate();
if (typeof url == "string") {
if (
typeof window.require == "function" &&
typeof window.process == "object"
) {
// @ts-ignore
const remote = require("@electron/remote");
const thisWindow = remote.getCurrentWindow();
thisWindow.loadURL(url);
} else {
location.href = url;
}
}
};
/* /*
升级方法: 升级方法:
1. 游戏启动后导出数据然后以http/s协议重启 1. 游戏启动后导出数据然后以http/s协议重启
@ -61,23 +78,6 @@ boot().then(() => {
}); });
}); });
} }
// 保存协议的切换状态
function saveProtocol() {
const url = sendUpdate();
if (typeof url == "string") {
if (
typeof window.require == "function" &&
typeof window.process == "object"
) {
// @ts-ignore
const remote = require("@electron/remote");
const thisWindow = remote.getCurrentWindow();
thisWindow.loadURL(url);
} else {
location.href = url;
}
}
}
} else { } else {
// 成功导入后删除noname.config.txt // 成功导入后删除noname.config.txt
let searchParams = new URLSearchParams(location.search); let searchParams = new URLSearchParams(location.search);

View File

@ -21,11 +21,18 @@ export function canUseHttpProtocol() {
// 手机端 // 手机端
if (window.cordova) { if (window.cordova) {
// 直接确定包名 // 直接确定包名
if (nonameInitialized.endsWith("com.noname.shijian/")) { // 因为懒人包作者不一定会改成什么版本
// @ts-ignore
if (nonameInitialized.endsWith("com.noname.shijian/") && window.noname_shijianInterfaces && typeof window.noname_shijianInterfaces.sendUpdate === 'function') {
// 每个app自定义能升级的渠道比如判断版本 // 每个app自定义能升级的渠道比如判断版本
// @ts-ignore // @ts-ignore
return window.noname_shijianInterfaces.getApkVersion() >= 16000; return window.noname_shijianInterfaces.getApkVersion() >= 16000;
} }
// 由理版判断后续所有app都通过此接口来升级协议
// @ts-ignore
if (window.NonameAndroidBridge && typeof window.NonameAndroidBridge.sendUpdate === 'function') {
return true;
}
} }
// 电脑端 // 电脑端
else if (typeof window.require == "function" && typeof window.process == "object") { else if (typeof window.require == "function" && typeof window.process == "object") {
@ -55,11 +62,19 @@ export function sendUpdate() {
// 手机端 // 手机端
if (window.cordova) { if (window.cordova) {
// 直接确定包名 // 直接确定包名
if (nonameInitialized && nonameInitialized.includes("com.noname.shijian")) { // @ts-ignore
if (nonameInitialized && nonameInitialized.includes("com.noname.shijian") && window.noname_shijianInterfaces && typeof window.noname_shijianInterfaces.sendUpdate === 'function') {
// 给诗笺版apk的java层传递升级完成的信息 // 给诗笺版apk的java层传递升级完成的信息
// @ts-ignore // @ts-ignore
return window.noname_shijianInterfaces.sendUpdate() + "?sendUpdate=true"; return window.noname_shijianInterfaces.sendUpdate() + "?sendUpdate=true";
} }
// 由理版判断
// @ts-ignore
if (window.NonameAndroidBridge && typeof window.NonameAndroidBridge.sendUpdate === 'function') {
// 给由理版apk的java层传递升级完成的信息
// @ts-ignore
return window.NonameAndroidBridge.sendUpdate() + "?sendUpdate=true";
}
} }
// 电脑端 // 电脑端
else if (typeof window.require == "function" && typeof window.process == "object") { else if (typeof window.require == "function" && typeof window.process == "object") {