diff --git a/game/entry.js b/game/entry.js index 064b668f8..1f88a5976 100644 --- a/game/entry.js +++ b/game/entry.js @@ -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(); } } } diff --git a/node_modules/@types/noname-typings/cordova-plugin-dialogs.d.ts b/node_modules/@types/noname-typings/cordova-plugin-dialogs.d.ts index 8d22f886e..1b7a276f9 100644 --- a/node_modules/@types/noname-typings/cordova-plugin-dialogs.d.ts +++ b/node_modules/@types/noname-typings/cordova-plugin-dialogs.d.ts @@ -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 */ diff --git a/noname/init/cordova.js b/noname/init/cordova.js index 4ec1823f0..c900ae8ed 100644 --- a/noname/init/cordova.js +++ b/noname/init/cordova.js @@ -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();