fix(window): 更改创建逻辑

Signed-off-by: BTMuli <BT-Muli@outlook.com>
This commit is contained in:
BTMuli
2023-04-05 14:21:05 +08:00
parent 1fafbd4612
commit e7d293f83b
8 changed files with 32 additions and 19 deletions

View File

@@ -2,12 +2,13 @@
* @file utils TGWindow.ts
* @description 用于创建TG窗口的工具
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { window as TauriWindow } from "@tauri-apps/api";
/**
* @description 创建TG窗口
* @since Alpha v0.1.2
* @param {string} url 窗口地址
* @param {string} label 窗口标签
* @param {string} title 窗口标题
@@ -27,20 +28,18 @@ export function createTGWindow(
// 计算窗口位置
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 {
// https://github.com/tauri-apps/tauri/issues/5380
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
x: left,
y: top,
resizable: resizable,
url: url,
title: title,
visible: false,
});
new TauriWindow.WindowManager(label).close().then(() => {
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
@@ -49,6 +48,7 @@ export function createTGWindow(
resizable: resizable,
url: url,
title: title,
visible: false,
});
}
});
}