添加酒馆、留影叙佳期入口

This commit is contained in:
BTMuli
2023-10-28 18:58:52 +08:00
parent 2a8b97abe9
commit 0b041a3f01
5 changed files with 75 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.4", features = [] } tauri-build = { version = "1.4", features = [] }
[dependencies] [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 = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
url = "2.4.1" url = "2.4.1"

View File

@@ -29,6 +29,11 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {
} else { } else {
mhy_window_config.url = get_mhy_client_url(func.clone()); 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(); let has_mhy_client = handle.get_window("mhy_client").is_some();
if has_mhy_client { if has_mhy_client {
dbg!("mhy_client exists"); dbg!("mhy_client exists");

View File

@@ -36,7 +36,8 @@
"dialog": { "dialog": {
"all": false, "all": false,
"open": true, "open": true,
"save": true "save": true,
"message": true
}, },
"clipboard": { "clipboard": {
"all": true "all": true
@@ -96,6 +97,11 @@
"windows": ["mhy_client"], "windows": ["mhy_client"],
"enableTauriAPI": true "enableTauriAPI": true
}, },
{
"domain": "m.miyoushe.com",
"windows": ["mhy_client"],
"enableTauriAPI": true
},
{ {
"domain": "webstatic.mihoyo.com", "domain": "webstatic.mihoyo.com",
"windows": ["mhy_client"], "windows": ["mhy_client"],
@@ -131,7 +137,7 @@
}, },
{ {
"fullscreen": false, "fullscreen": false,
"resizable": false, "resizable": true,
"title": "米游社", "title": "米游社",
"label": "mhy_client", "label": "mhy_client",
"url": "https://api-static.mihoyo.com/", "url": "https://api-static.mihoyo.com/",
@@ -140,7 +146,8 @@
"width": 400, "width": 400,
"height": 800, "height": 800,
"center": true, "center": true,
"decorations": false "decorations": true,
"closable": false
} }
] ]
} }

View File

@@ -112,6 +112,16 @@
<img src="/source/UI/userRecord.webp" class="side-icon-user" alt="game_record" /> <img src="/source/UI/userRecord.webp" class="side-icon-user" alt="game_record" />
</template> </template>
</v-list-item> </v-list-item>
<v-list-item class="side-item-user" title="酒馆" @click="openClient('tavern')">
<template #prepend>
<img src="/platforms/mhy/mys.webp" alt="酒馆" class="side-icon-user" />
</template>
</v-list-item>
<v-list-item class="side-item-user" title="生日" @click="openClient('birthday')">
<template #prepend>
<img src="/source/UI/paimon.webp" alt="生日" class="side-icon-user" />
</template>
</v-list-item>
<v-list-item <v-list-item
class="side-item-user" class="side-item-user"
title="登录" title="登录"
@@ -256,6 +266,7 @@ function login(): void {
.side-icon-user { .side-icon-user {
width: 20px; width: 20px;
height: 20px; height: 20px;
border-radius: 5px;
margin-right: 10px; margin-right: 10px;
} }
</style> </style>

View File

@@ -4,7 +4,7 @@
* @since Beta v0.3.4 * @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 type { Event } from "@tauri-apps/api/event";
import { WebviewWindow } from "@tauri-apps/api/window"; 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"; return "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501";
case "game_record": 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";
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: default:
return ""; return this.getUrl("daily_note");
} }
} }
@@ -191,6 +197,9 @@ class TGClient {
case "login": case "login":
await this.nullCallback(arg); await this.nullCallback(arg);
break; break;
case "onClickImg":
await this.onClickImg(payload);
break;
// getNotificationSettings // getNotificationSettings
default: default:
console.warn(`[${arg.windowLabel}] ${arg.payload}`); console.warn(`[${arg.windowLabel}] ${arg.payload}`);
@@ -371,7 +380,12 @@ class TGClient {
* @returns {void} - 无返回值 * @returns {void} - 无返回值
*/ */
async pushPage(payload: any): Promise<void> { async pushPage(payload: any): Promise<void> {
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); await this.open("pushPage", url);
} }
@@ -403,6 +417,37 @@ class TGClient {
const { callback } = <NormalArg>JSON.parse(arg.payload); const { callback } = <NormalArg>JSON.parse(arg.payload);
await this.callback(callback, {}); await this.callback(callback, {});
} }
/**
* @func onClickImg
* @since Beta v0.3.4
* @desc 点击图片,下载到本地
* @param {unknown} payload - 请求参数
* @returns {void} - 无返回值
*/
async onClickImg(payload: any): Promise<void> {
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(); const mhyClient = new TGClient();