mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
♻️ 重构 pushPage、closePage 逻辑
This commit is contained in:
@@ -29,7 +29,7 @@ interface InvokeArg {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @class TGClient
|
* @class TGClient
|
||||||
* @since Beta v0.3.4
|
* @since Beta v0.3.7
|
||||||
* @description 米游社客户端
|
* @description 米游社客户端
|
||||||
*/
|
*/
|
||||||
class TGClient {
|
class TGClient {
|
||||||
@@ -87,6 +87,22 @@ class TGClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @func loadJSBridge
|
||||||
|
* @since Beta v0.3.7
|
||||||
|
* @desc 加载 JSBridge
|
||||||
|
* @returns {void} - 无返回值
|
||||||
|
*/
|
||||||
|
async loadJSBridge(): Promise<void> {
|
||||||
|
const executeJS = `javascript:(function(){
|
||||||
|
window.MiHoYoJSInterface = {
|
||||||
|
postMessage: function(arg) { window.__TAURI__.event.emit('post_mhy_client', arg) },
|
||||||
|
closePage: function() { this.postMessage('{"method":"closePage"}') },
|
||||||
|
};
|
||||||
|
})();`;
|
||||||
|
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @func hideSideBar
|
* @func hideSideBar
|
||||||
* @since Beta v0.3.5
|
* @since Beta v0.3.5
|
||||||
@@ -170,14 +186,8 @@ class TGClient {
|
|||||||
await this.open(func, url);
|
await this.open(func, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (url === undefined) {
|
if (url === undefined) url = this.getUrl(func);
|
||||||
url = this.getUrl(func);
|
|
||||||
this.route = [url];
|
this.route = [url];
|
||||||
} else if (func.startsWith("web_act")) {
|
|
||||||
this.route = [url];
|
|
||||||
} else if (func !== "closePage") {
|
|
||||||
this.route.push(url);
|
|
||||||
}
|
|
||||||
console.log(`[open] ${url}`);
|
console.log(`[open] ${url}`);
|
||||||
await invoke<InvokeArg>("create_mhy_client", { func, url });
|
await invoke<InvokeArg>("create_mhy_client", { func, url });
|
||||||
this.window = WebviewWindow.getByLabel("mhy_client");
|
this.window = WebviewWindow.getByLabel("mhy_client");
|
||||||
@@ -428,23 +438,29 @@ class TGClient {
|
|||||||
const url: string = payload.page;
|
const url: string = payload.page;
|
||||||
if (url.startsWith("mihoyobbs://article/")) {
|
if (url.startsWith("mihoyobbs://article/")) {
|
||||||
const urlBBS = url.replace("mihoyobbs://article/", "https://m.miyoushe.com/ys/#/article/");
|
const urlBBS = url.replace("mihoyobbs://article/", "https://m.miyoushe.com/ys/#/article/");
|
||||||
await this.open("pushPage", urlBBS);
|
await this.pushPage({ page: urlBBS });
|
||||||
return;
|
return;
|
||||||
} else if (url.startsWith("mihoyobbs://webview?link=")) {
|
} else if (url.startsWith("mihoyobbs://webview?link=")) {
|
||||||
const urlWv = url.replace("mihoyobbs://webview?link=", "");
|
const urlWv = url.replace("mihoyobbs://webview?link=", "");
|
||||||
// 解析经过编码作为参数的链接
|
// 解析经过编码作为参数的链接
|
||||||
const urlReal = decodeURIComponent(urlWv);
|
const urlReal = decodeURIComponent(urlWv);
|
||||||
await this.open("pushPage", urlReal);
|
await this.pushPage({ page: urlReal });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.open("pushPage", url);
|
this.route.push(url);
|
||||||
|
console.log(`[pushPage] ${url}`);
|
||||||
|
const executeJS = `javascript:(function(){
|
||||||
|
window.location.href = '${url}';
|
||||||
|
})();`;
|
||||||
|
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
||||||
|
await this.loadJSBridge();
|
||||||
await this.hideSideBar();
|
await this.hideSideBar();
|
||||||
await this.hideOverlay();
|
await this.hideOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @func closePage
|
* @func closePage
|
||||||
* @since Beta v0.3.6
|
* @since Beta v0.3.7
|
||||||
* @desc 关闭米游社客户端的页面
|
* @desc 关闭米游社客户端的页面
|
||||||
* @returns {void} - 无返回值
|
* @returns {void} - 无返回值
|
||||||
*/
|
*/
|
||||||
@@ -455,7 +471,11 @@ class TGClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const url = this.route[this.route.length - 1];
|
const url = this.route[this.route.length - 1];
|
||||||
await this.open("closePage", url);
|
const executeJS = `javascript:(function(){
|
||||||
|
window.location.href = '${url}';
|
||||||
|
})();`;
|
||||||
|
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
||||||
|
await this.loadJSBridge();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user