mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
✨ 完善 share 回调
This commit is contained in:
@@ -473,23 +473,36 @@ class TGClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @func onClickImg
|
* @func onClickImg
|
||||||
* @since Beta v0.3.6
|
* @since Beta v0.3.7
|
||||||
* @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 image = payload.image_list[0];
|
const image = payload.image_list[0];
|
||||||
const executeJS = `javascript:(async function() {
|
const executeJS = this.getSaveImgJS(image.url, image.format);
|
||||||
|
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @func getSaveImgJS
|
||||||
|
* @since Beta v0.3.7
|
||||||
|
* @desc 获取保存图片的 JS
|
||||||
|
* @param {string} url - 图片链接
|
||||||
|
* @param {string} format - 图片格式
|
||||||
|
* @returns {string} - JS
|
||||||
|
*/
|
||||||
|
getSaveImgJS(url: string, format: string): string {
|
||||||
|
return `javascript:(async function() {
|
||||||
const _t = window.__TAURI__;
|
const _t = window.__TAURI__;
|
||||||
const defaultPath = await _t.path.downloadDir() + Date.now() + '.${image.format}';
|
const defaultPath = await _t.path.downloadDir() + Date.now() + '.${format}';
|
||||||
const savePath = await _t.dialog.save({
|
const savePath = await _t.dialog.save({
|
||||||
title: '保存图片',
|
title: '保存图片',
|
||||||
filters: [{ name: '图片', extensions: ['png'] }],
|
filters: [{ name: '图片', extensions: ['png'] }],
|
||||||
defaultPath: defaultPath,
|
defaultPath: defaultPath,
|
||||||
});
|
});
|
||||||
if (savePath) {
|
if (savePath) {
|
||||||
const resBlob = await _t.http.fetch('${image.url}',{
|
const resBlob = await _t.http.fetch('${url}',{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: _t.http.ResponseType.Binary
|
responseType: _t.http.ResponseType.Binary
|
||||||
});
|
});
|
||||||
@@ -501,19 +514,26 @@ class TGClient {
|
|||||||
alert('保存成功');
|
alert('保存成功');
|
||||||
}
|
}
|
||||||
})();`;
|
})();`;
|
||||||
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @func share
|
* @func share
|
||||||
* @since Beta v0.3.5
|
* @since Beta v0.3.7
|
||||||
* @desc 分享
|
* @desc 分享
|
||||||
* @todo 实现图片获取
|
|
||||||
* @param {unknown} payload - 请求参数
|
* @param {unknown} payload - 请求参数
|
||||||
* @param {string} callback - 回调函数名
|
* @param {string} callback - 回调函数名
|
||||||
* @returns {void} - 无返回值
|
* @returns {void} - 无返回值
|
||||||
*/
|
*/
|
||||||
async share(payload: any, callback: string): Promise<void> {
|
async share(payload: any, callback: string): Promise<void> {
|
||||||
|
// 如果有数据
|
||||||
|
if (payload?.content.image_url !== undefined) {
|
||||||
|
const image = payload.content.image_url;
|
||||||
|
const format = image.split(".").pop();
|
||||||
|
const executeJS = this.getSaveImgJS(image, format);
|
||||||
|
await invoke("execute_js", { label: "mhy_client", js: executeJS });
|
||||||
|
await this.callback(callback, {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 延时 3s
|
// 延时 3s
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await this.callback(callback, {});
|
await this.callback(callback, {});
|
||||||
|
|||||||
Reference in New Issue
Block a user