From 0b041a3f0161a61d1ada56629a1ac59c1f4d503a Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 28 Oct 2023 18:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=E9=85=92?= =?UTF-8?q?=E9=A6=86=E3=80=81=E7=95=99=E5=BD=B1=E5=8F=99=E4=BD=B3=E6=9C=9F?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.toml | 2 +- src-tauri/src/client.rs | 5 ++++ src-tauri/tauri.conf.json | 13 ++++++-- src/components/app/t-sidebar.vue | 11 +++++++ src/utils/TGClient.ts | 51 ++++++++++++++++++++++++++++++-- 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d7aedc5b..f9a15380 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" tauri-build = { version = "1.4", features = [] } [dependencies] -tauri = { version = "1.4", features = [ "process-exit", "fs-read-dir", "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request", "shell-open"] } +tauri = { version = "1.4", features = [ "dialog-message", "process-exit", "fs-read-dir", "window-hide", "os-all", "clipboard-all", "dialog-open", "dialog-save", "fs-create-dir", "fs-remove-dir", "fs-write-file", "fs-remove-file", "fs-read-file", "path-all", "fs-exists", "window-close", "window-set-title", "window-unminimize", "window-show", "window-set-focus", "http-request", "shell-open"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" url = "2.4.1" diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs index f0d028c8..9b0cf8bb 100644 --- a/src-tauri/src/client.rs +++ b/src-tauri/src/client.rs @@ -29,6 +29,11 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) { } else { mhy_window_config.url = get_mhy_client_url(func.clone()); } + if func == "birthday" { + mhy_window_config.width = 1280.0; + mhy_window_config.height = 720.0; + mhy_window_config.resizable = false; + } let has_mhy_client = handle.get_window("mhy_client").is_some(); if has_mhy_client { dbg!("mhy_client exists"); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 8d60bb7f..faed09b4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -36,7 +36,8 @@ "dialog": { "all": false, "open": true, - "save": true + "save": true, + "message": true }, "clipboard": { "all": true @@ -96,6 +97,11 @@ "windows": ["mhy_client"], "enableTauriAPI": true }, + { + "domain": "m.miyoushe.com", + "windows": ["mhy_client"], + "enableTauriAPI": true + }, { "domain": "webstatic.mihoyo.com", "windows": ["mhy_client"], @@ -131,7 +137,7 @@ }, { "fullscreen": false, - "resizable": false, + "resizable": true, "title": "米游社", "label": "mhy_client", "url": "https://api-static.mihoyo.com/", @@ -140,7 +146,8 @@ "width": 400, "height": 800, "center": true, - "decorations": false + "decorations": true, + "closable": false } ] } diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 59bf0079..405657b2 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -112,6 +112,16 @@ game_record + + + + + + diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index a06ee991..b47bad85 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -4,7 +4,7 @@ * @since Beta v0.3.4 */ -import { event, invoke } from "@tauri-apps/api"; +import { event, invoke, path } from "@tauri-apps/api"; import type { Event } from "@tauri-apps/api/event"; import { WebviewWindow } from "@tauri-apps/api/window"; @@ -115,8 +115,14 @@ class TGClient { return "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501"; case "game_record": return "https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen"; + case "daily_note": + return "https://webstatic.mihoyo.com/app/community-game-records/index.html?bbs_presentation_style=fullscreen#/ys/daily/"; + case "tavern": + return "https://m.miyoushe.com/ys/#/home/26"; + case "birthday": + return "https://webstatic.mihoyo.com/ys/event/e20220303-birthday/index.html?game_biz=hk4e_cn&bbs_presentation_style=fullscreen&bbs_auth_required=true&bbs_landscape=true&activity_id=20220301153521&mhy_hide_status_bar=true&utm_source=bbs&utm_medium=mys&utm_campaign=arti"; default: - return ""; + return this.getUrl("daily_note"); } } @@ -191,6 +197,9 @@ class TGClient { case "login": await this.nullCallback(arg); break; + case "onClickImg": + await this.onClickImg(payload); + break; // getNotificationSettings default: console.warn(`[${arg.windowLabel}] ${arg.payload}`); @@ -371,7 +380,12 @@ class TGClient { * @returns {void} - 无返回值 */ async pushPage(payload: any): Promise { - const url = payload.page; + const url: string = payload.page; + if (url.startsWith("mihoyobbs://article/")) { + const urlBBS = url.replace("mihoyobbs://article/", "https://m.miyoushe.com/ys/#/article/"); + await this.open("pushPage", urlBBS); + return; + } await this.open("pushPage", url); } @@ -403,6 +417,37 @@ class TGClient { const { callback } = JSON.parse(arg.payload); await this.callback(callback, {}); } + + /** + * @func onClickImg + * @since Beta v0.3.4 + * @desc 点击图片,下载到本地 + * @param {unknown} payload - 请求参数 + * @returns {void} - 无返回值 + */ + async onClickImg(payload: any): Promise { + const url = payload.image_list[0].url; + const savePath = `${await path.downloadDir()}${path.sep}${Date.now().toString()}.png`; + const executeJS = + "javascript:(function(){" + + " window.__TAURI__.dialog.save({" + + " title: '保存图片'," + + " filters: [{ name: '图片', extensions: ['png'] }]," + + ` defaultPath: '${savePath}',` + + " }).then((res) => {" + + " fetch('" + + url + + "')" + + " .then((response) => response.blob())" + + " .then((blob) => {" + + " window.__TAURI__.fs.writeBinaryFile(res, blob).then(() => {" + + " alert('保存成功');" + + " });" + + " });" + + " });" + + "})();"; + await invoke("execute_js", { label: "mhy_client", js: executeJS }); + } } const mhyClient = new TGClient();