Skip to content

Commit

Permalink
✨ 添加酒馆、留影叙佳期入口
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 28, 2023
1 parent 2a8b97a commit 0b041a3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 10 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"dialog": {
"all": false,
"open": true,
"save": true
"save": true,
"message": true
},
"clipboard": {
"all": true
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -131,7 +137,7 @@
},
{
"fullscreen": false,
"resizable": false,
"resizable": true,
"title": "米游社",
"label": "mhy_client",
"url": "https://api-static.mihoyo.com/",
Expand All @@ -140,7 +146,8 @@
"width": 400,
"height": 800,
"center": true,
"decorations": false
"decorations": true,
"closable": false
}
]
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/app/t-sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
<img src="/source/UI/userRecord.webp" class="side-icon-user" alt="game_record" />
</template>
</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
class="side-item-user"
title="登录"
Expand Down Expand Up @@ -256,6 +266,7 @@ function login(): void {
.side-icon-user {
width: 20px;
height: 20px;
border-radius: 5px;
margin-right: 10px;
}
</style>
51 changes: 48 additions & 3 deletions src/utils/TGClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -371,7 +380,12 @@ class TGClient {
* @returns {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);
}

Expand Down Expand Up @@ -403,6 +417,37 @@ class TGClient {
const { callback } = <NormalArg>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<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();
Expand Down

0 comments on commit 0b041a3

Please sign in to comment.