From 012efb03ea8025cb210fc23c74bcab22f5ca1b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= <72692909+BTMuli@users.noreply.github.com> Date: Sat, 6 Jul 2024 00:26:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=B1=B3=E7=A4=BE=E7=AA=97=E5=8F=A3=E5=88=9B=E5=BB=BA=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E9=BB=98=E8=AE=A4=E5=8F=AA=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=AA=97=E5=8F=A3=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/client/mod.rs | 14 ++++++++------ src-tauri/src/commands.rs | 6 ------ src-tauri/tauri.conf.json | 18 ++---------------- src/utils/TGClient.ts | 13 ++++++++++--- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src-tauri/src/client/mod.rs b/src-tauri/src/client/mod.rs index be20414b..e6ed6b2d 100644 --- a/src-tauri/src/client/mod.rs +++ b/src-tauri/src/client/mod.rs @@ -8,7 +8,9 @@ use tauri_utils::config::WebviewUrl; #[tauri::command] pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { - let mut option = handle.config().app.windows.get(1).unwrap().clone(); + let mut win_width = 400.0; + let mut win_height = 800.0; + let win_ua = "Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/2.72.2"; let url_parse; if url != "" { url_parse = WebviewUrl::External(url.parse().unwrap()); @@ -19,8 +21,8 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { || func == "web_act" || url.starts_with("https://webstatic.mihoyo.com/ys/event/e20220303-birthday/index.html") { - option.width = 1280.0; - option.height = 720.0; + win_width = 1280.0; + win_height = 720.0; } let window_find = handle.get_webview_window("mhy_client"); if window_find.is_some() { @@ -28,10 +30,10 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { return; } WebviewWindowBuilder::new(&handle, "mhy_client", url_parse) - .inner_size(option.width, option.height) - .title(option.title) + .inner_size(win_width, win_height) + .title("米游社") .center() - .user_agent(option.user_agent.unwrap().as_str()) + .user_agent(win_ua) .menu(menu::create_mhy_menu(handle.clone())) .on_menu_event(move |app, event| menu::handle_menu_event(app, event)) .build() diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index b68ab0f3..bc2c4dc7 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -16,12 +16,6 @@ pub async fn init_app(app_handle: AppHandle) { return; } } - dbg!("init_app"); - let _mhy = app_handle.get_webview_window("mhy_client"); - if _mhy.is_some() { - // todo 这里应该延时,否则可能造成 macOS 平台的崩溃 - _mhy.unwrap().destroy().unwrap(); - } app_handle.emit("initApp", ()).unwrap(); unsafe { APP_INITIALIZED = true; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1a972189..92517907 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "productName": "TeyvatGuide", "identifier": "TeyvatGuide", - "version": "0.4.9", + "version": "0.5.0", "build": { "beforeDevCommand": "pnpm vite:dev", "beforeBuildCommand": "pnpm vite:build", @@ -46,20 +46,6 @@ "width": 1600, "height": 900, "center": true - }, - { - "fullscreen": false, - "resizable": false, - "title": "米游社", - "label": "mhy_client", - "url": "", - "userAgent": "Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/2.70.1", - "visible": false, - "width": 400, - "height": 800, - "center": true, - "decorations": true, - "closable": true } ], "security": { @@ -69,7 +55,7 @@ "plugins": { "deep-link": { "desktop": { - "schemes": ["teyvatguide"] + "schemes": ["teyvatguide", "teyvat"] }, "mobile": [] } diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index a0ba533e..4b1e3594 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -131,7 +131,7 @@ class TGClient { /** * @func getUrl - * @since Beta v0.3.8 + * @since Beta v0.5.0 * @desc 获取 url * @param {string} func - 方法名 * @returns {string} - url @@ -141,7 +141,7 @@ class TGClient { case "sign_in": return "https://act.mihoyo.com/bbs/event/signin/hk4e/index.html?act_id=e202311201442471&bbs_auth_required=true&bbs_presentation_style=fullscreen&mhy_presentation_style=fullscreen&utm_source=bbs&utm_medium=ys&utm_campaign=icon"; case "game_record": - return "https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen"; + return "https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen&game_id=2"; case "daily_note": return "https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen#/ys/daily/"; case "tavern": @@ -452,7 +452,14 @@ class TGClient { await TGLogger.Info(`[TGClient][open][${func}] ${url}`); const windowFind = webviewWindow.WebviewWindow.getByLabel("mhy_client"); if (windowFind !== null) { - await windowFind.destroy(); + try { + await windowFind.destroy(); + } catch (e) { + showSnackbar({ + text: `[TGClient][open] ${e}`, + color: "error", + }); + } } await core.invoke("create_mhy_client", { func, url }); await this.loadJSBridge();