From 386085f8c39985e8204a9a2d897e39ebf0c7dab0 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Fri, 1 Sep 2023 19:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E8=B0=83=E6=95=B4=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=83=8C=E6=99=AF=E8=89=B2=EF=BC=8C=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=BF=9D=E5=AD=98=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/TGShare.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/utils/TGShare.ts b/src/utils/TGShare.ts index 6d0cbe30..f6caa388 100644 --- a/src/utils/TGShare.ts +++ b/src/utils/TGShare.ts @@ -2,16 +2,17 @@ * @file utils TGShare.ts * @description 生成分享截图并保存到本地 * @author BTMuli - * @since Alpha v0.2.3 + * @since Beta v0.3.0 */ -// tauri -import { dialog, fs, http } from "@tauri-apps/api"; +// third party import html2canvas from "html2canvas"; +// tauri +import { dialog, fs, http, path } from "@tauri-apps/api"; /** * @description 保存图片-canvas - * @since Alpha v0.2.0 + * @since Beta v0.3.0 * @param {HTMLCanvasElement} canvas - canvas元素 * @param {string} filename - 文件名 * @returns {Promise} 无返回值 @@ -22,9 +23,10 @@ async function saveCanvasImg(canvas: HTMLCanvasElement, filename: string): Promi .split("") .map((item) => item.charCodeAt(0)), ); + const saveDir = await path.downloadDir(); await dialog .save({ - defaultPath: filename, + defaultPath: `${saveDir}${filename}.png`, filters: [{ name: "图片", extensions: ["png"] }], }) .then(async (res) => { @@ -57,7 +59,7 @@ export async function saveImgLocal(url: string): Promise { /** * @description 获取分享截图背景色 - * @since Alpha v0.2.3 + * @since Beta v0.3.0 * @returns {string} 背景色 */ function getShareImgBgColor(): string { @@ -66,9 +68,9 @@ function getShareImgBgColor(): string { theme = JSON.parse(theme).theme; } if (theme === "dark") { - return "#363433"; + return "#0d1117"; } else { - return "#f9e9cd"; + return "#ffffff"; } }