diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index 41f418eb..f6957f81 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -91,12 +91,13 @@ class TGClient { /** * @func loadJSBridge - * @since Beta v0.3.7 + * @since Beta v0.3.8 * @desc 加载 JSBridge * @returns {void} - 无返回值 */ async loadJSBridge(): Promise { - const executeJS = `javascript:(function(){ + const executeJS = `javascript:(function() { + if(window.MiHoYoJSBridge) return; window.MiHoYoJSInterface = { postMessage: function(arg) { window.__TAURI__.event.emit('post_mhy_client', arg) }, closePage: function() { this.postMessage('{"method":"closePage"}') }, @@ -215,6 +216,9 @@ class TGClient { break; case "configure_share": break; + case "eventTrack": + await this.eventTrack(payload); + break; case "getStatusBarHeight": await this.getStatusBarHeight(callback); break; @@ -521,7 +525,6 @@ class TGClient { * @returns {void} - 无返回值 */ async nullCallback(arg: Event): Promise { - console.warn(`[${arg.windowLabel}] ${arg.payload}`); const { callback } = JSON.parse(arg.payload); await this.callback(callback, {}); } @@ -594,6 +597,18 @@ class TGClient { await this.callback(callback, {}); }, 3000); } + + /** + * @func eventTrack + * @since Beta v0.3.8 + * @desc 事件跟踪 + * @param {unknown} payload - 请求参数 + * @returns {void} - 无返回值 + */ + async eventTrack(payload: unknown): Promise { + console.log(`[eventTrack] ${JSON.stringify(payload)}`); + await this.loadJSBridge(); + } } const mhyClient = new TGClient();