mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🐛 修复一些 bug
* 米社子窗口关闭后无法再次创建 * 保存图片回调默认路径错误 * 调整 closePage 逻辑
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
* @since Beta v0.3.6
|
* @since Beta v0.3.6
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { event, invoke, path } from "@tauri-apps/api";
|
import { event, invoke } 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";
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class TGClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @func getUrl
|
* @func getUrl
|
||||||
* @since Beta v0.3.5
|
* @since Beta v0.3.6
|
||||||
* @desc 获取 url
|
* @desc 获取 url
|
||||||
* @param {string} func - 方法名
|
* @param {string} func - 方法名
|
||||||
* @returns {string} - url
|
* @returns {string} - url
|
||||||
@@ -129,13 +129,13 @@ class TGClient {
|
|||||||
case "toolbox":
|
case "toolbox":
|
||||||
return "https://webstatic.mihoyo.com/bbs/event/e20200511toolbox/index.html?game_biz=ys_cn";
|
return "https://webstatic.mihoyo.com/bbs/event/e20200511toolbox/index.html?game_biz=ys_cn";
|
||||||
default:
|
default:
|
||||||
return this.getUrl("daily_note");
|
return "https://api-static.mihoyo.com/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @func open
|
* @func open
|
||||||
* @since Beta v0.3.4
|
* @since Beta v0.3.6
|
||||||
* @desc 打开米游社客户端
|
* @desc 打开米游社客户端
|
||||||
* @param {string} func - 方法名
|
* @param {string} func - 方法名
|
||||||
* @param {string} url - url
|
* @param {string} url - url
|
||||||
@@ -143,7 +143,15 @@ class TGClient {
|
|||||||
*/
|
*/
|
||||||
async open(func: string, url?: string): Promise<void> {
|
async open(func: string, url?: string): Promise<void> {
|
||||||
if (this.window !== null) {
|
if (this.window !== null) {
|
||||||
await this.window.close();
|
try {
|
||||||
|
await this.window.close();
|
||||||
|
} catch (e) {
|
||||||
|
await invoke<InvokeArg>("create_mhy_client", {
|
||||||
|
func: "default",
|
||||||
|
url: "https://api-static.mihoyo.com/",
|
||||||
|
});
|
||||||
|
await this.open(func, url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (url === undefined) {
|
if (url === undefined) {
|
||||||
url = this.getUrl(func);
|
url = this.getUrl(func);
|
||||||
@@ -414,13 +422,14 @@ class TGClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @func closePage
|
* @func closePage
|
||||||
* @since Beta v0.3.4
|
* @since Beta v0.3.6
|
||||||
* @desc 关闭米游社客户端的页面
|
* @desc 关闭米游社客户端的页面
|
||||||
* @returns {void} - 无返回值
|
* @returns {void} - 无返回值
|
||||||
*/
|
*/
|
||||||
async closePage(): Promise<void> {
|
async closePage(): Promise<void> {
|
||||||
this.route.pop();
|
this.route.pop();
|
||||||
if (this.route.length === 0) {
|
if (this.route.length === 0) {
|
||||||
|
await this.open("");
|
||||||
await this.window?.hide();
|
await this.window?.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -443,24 +452,23 @@ class TGClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @func onClickImg
|
* @func onClickImg
|
||||||
* @since Beta v0.3.5
|
* @since Beta v0.3.6
|
||||||
* @desc 点击图片,下载到本地
|
* @desc 点击图片,下载到本地
|
||||||
* @param {unknown} payload - 请求参数
|
* @param {unknown} payload - 请求参数
|
||||||
* @returns {void} - 无返回值
|
* @returns {void} - 无返回值
|
||||||
*/
|
*/
|
||||||
async onClickImg(payload: any): Promise<void> {
|
async onClickImg(payload: any): Promise<void> {
|
||||||
const url = payload.image_list[0].url;
|
const image = payload.image_list[0];
|
||||||
const imageType = url.endsWith(".png") ? "png" : url.endsWith(".jpg") ? "jpg" : "png";
|
|
||||||
const savePath = `${await path.downloadDir()}${path.sep}${Date.now().toString()}.${imageType}`;
|
|
||||||
const executeJS = `javascript:(async function() {
|
const executeJS = `javascript:(async function() {
|
||||||
const _t = window.__TAURI__;
|
const _t = window.__TAURI__;
|
||||||
|
const defaultPath = await _t.path.downloadDir() + Date.now() + '.${image.format}';
|
||||||
const savePath = await _t.dialog.save({
|
const savePath = await _t.dialog.save({
|
||||||
title: '保存图片',
|
title: '保存图片',
|
||||||
filters: [{ name: '图片', extensions: ['png'] }],
|
filters: [{ name: '图片', extensions: ['png'] }],
|
||||||
defaultPath: '${savePath}',
|
defaultPath: defaultPath,
|
||||||
});
|
});
|
||||||
if (savePath) {
|
if (savePath) {
|
||||||
const resBlob = await _t.http.fetch('${url}',{
|
const resBlob = await _t.http.fetch('${image.url}',{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: _t.http.ResponseType.Binary
|
responseType: _t.http.ResponseType.Binary
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user