Merge pull request #1362 from nonameShijian/PR-Branch

为新客户端的导入离线包/完整包功能提前做适配、优化升级协议时的观感、修改处理网页参数后重启的路径
This commit is contained in:
Spmario233 2024-05-17 15:52:14 +08:00 committed by GitHub
commit 0378fd7050
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 3 deletions

View File

@ -46,8 +46,14 @@ boot().then(() => {
3. 保存http/s协议的状态以后不再以file协议启动
*/
// 导出数据到根目录的noname.config.txt
if (navigator.notification) {
navigator.notification.activityStart("正在进行升级", "请稍候");
}
let data;
let export_data = function (data) {
if (navigator.notification) {
navigator.notification.activityStop();
}
game.promises
.writeFile(
lib.init.encode(JSON.stringify(data)),
@ -83,6 +89,9 @@ boot().then(() => {
for (let [key, value] of searchParams) {
// 成功导入后删除noname.config.txt
if (key === "sendUpdate" && value === "true") {
if (navigator.notification) {
navigator.notification.activityStart("正在导入旧版数据", "请稍候");
}
game.promises
.readFileAsText("noname.config.txt")
.then((data) => {
@ -112,7 +121,10 @@ boot().then(() => {
}
return;
}
alert("导入成功, 即将自动重启");
if (navigator.notification) {
navigator.notification.activityStop();
}
alert("升级前的配置导入成功, 即将自动重启");
// @ts-ignore
if (!lib.db) {
const noname_inited =
@ -163,7 +175,12 @@ boot().then(() => {
})
.then(() => {
const url = new URL(location.href);
location.href = url.origin + url.pathname;
url.searchParams.delete("sendUpdate");
location.href = url.toString();
}).catch(e => {
if (navigator.notification) {
navigator.notification.activityStop();
}
});
}
// 新客户端导入扩展
@ -173,7 +190,8 @@ boot().then(() => {
game.saveConfig(`extension_${value}_enable`, true);
alert(`扩展${value}已导入成功,点击确定重启游戏`);
const url = new URL(location.href);
location.href = url.origin + url.pathname;
url.searchParams.delete("importExtensionName");
location.href = url.toString();
}
}
}

View File

@ -55,6 +55,32 @@ interface Notification {
title?: string,
buttonLabels?: string[],
defaultText?: string): void;
/**
* open an activity dialog
*/
activityStart(title: string, message: string): void;
/**
* Close an activity dialog
*/
activityStop(): void;
/**
* Display a progress dialog with progress bar that goes from 0 to 100.
*
* @param title Title of the progress dialog.
* @param message Message to display in the dialog.
*/
progressStart(title: string, message: string): void;
/**
* Close the progress dialog.
*/
progressStop(): void;
/**
* Set the progress dialog value.
*
* @param value 0-100
*/
progressValue(value: number): void;
}
/** Object, passed to promptCallback */

View File

@ -18,6 +18,11 @@ export async function cordovaReady() {
game.reload();
}
}, false);
window.addEventListener("importPackage", () => {
if (confirm(`离线包/完整包已导入成功,是否重启游戏?`)) {
game.reload();
}
}, false);
document.addEventListener("pause", function () {
if (!_status.paused2 && typeof _status.event.isMine == "function" && !_status.event.isMine()) {
ui.click.pause();