feat(TGWindow): 精简代码,缓存可清除

This commit is contained in:
BTMuli
2023-03-11 23:27:48 +08:00
parent 54018f0a36
commit 049510c578
4 changed files with 89 additions and 71 deletions

54
src/utils/TGWindow.ts Normal file
View File

@@ -0,0 +1,54 @@
/**
* @file utils TGWindow.ts
* @description 用于创建TG窗口的工具
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { window as TauriWindow } from "@tauri-apps/api";
/**
* @description 创建TG窗口
* @param {string} url 窗口地址
* @param {string} label 窗口标签
* @param {string} title 窗口标题
* @param {number} width 窗口宽度
* @param {number} height 窗口高度
* @param {boolean} resizable 是否可调整大小
* @returns {void}
*/
export function createTGWindow(
url: string,
label: string,
title: string,
width: number,
height: number,
resizable: boolean
): void {
// 计算窗口位置
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
// 判断窗口是否存在
if (TauriWindow.WebviewWindow.getByLabel(label)) {
new TauriWindow.WindowManager(label).close().then(() => {
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
x: left,
y: top,
resizable: resizable,
url: url,
title: title,
});
});
} else {
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
x: left,
y: top,
resizable: resizable,
url: url,
title: title,
});
}
}