mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-16 09:58:13 +08:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
/**
|
|
* @file utils TGWindow.ts
|
|
* @description 用于创建TG窗口的工具
|
|
* @author BTMuli<bt-muli@outlook.com>
|
|
* @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 窗口标题
|
|
* @param {number} width 窗口宽度
|
|
* @param {number} height 窗口高度
|
|
* @param {boolean} resizable 是否可调整大小
|
|
* @param {boolean} visible 是否可见
|
|
* @returns {void}
|
|
*/
|
|
export function createTGWindow (
|
|
url: string,
|
|
label: string,
|
|
title: string,
|
|
width: number,
|
|
height: number,
|
|
resizable: boolean,
|
|
visible: boolean = true,
|
|
): void {
|
|
// 计算窗口位置
|
|
const left = (window.screen.width - width) / 2;
|
|
const top = (window.screen.height - height) / 2;
|
|
// https://github.com/tauri-apps/tauri/issues/5380
|
|
void new TauriWindow.WebviewWindow(label, {
|
|
height,
|
|
width,
|
|
x: left,
|
|
y: top,
|
|
resizable,
|
|
url,
|
|
title,
|
|
visible,
|
|
});
|
|
void new TauriWindow.WindowManager(label).close().then(() => {
|
|
void new TauriWindow.WebviewWindow(label, {
|
|
height,
|
|
width,
|
|
x: left,
|
|
y: top,
|
|
resizable,
|
|
url,
|
|
title,
|
|
visible,
|
|
});
|
|
});
|
|
}
|