Files
VRCT/src-ui/logics/useWindow.js
2024-09-10 21:11:15 +09:00

44 lines
1.4 KiB
JavaScript

import { WebviewWindow } from "@tauri-apps/api/window";
import { store, useStore_IsOpenedConfigPage } from "@store";
import { getCurrent } from "@tauri-apps/api/window";
export const useWindow = () => {
const { updateIsOpenedConfigPage } = useStore_IsOpenedConfigPage();
const createConfigPage = async () => {
const main_page = getCurrent();
if (store.config_page === null) {
const config_page = new WebviewWindow("vrct_config_page",{
url: "./src-ui/windows/config_page/index.html",
center: true,
width: 1080,
height: 700,
title: "Settings"
});
config_page.once("tauri://created", function () {
store.config_page = config_page;
updateIsOpenedConfigPage(true);
});
config_page.once("tauri://error", function (e) {
console.log(e);
});
const unlisten_d = config_page.once("tauri://destroyed", (event) => {
store.config_page = null;
updateIsOpenedConfigPage(false);
unlisten_d();
});
main_page.onCloseRequested((event) => {
config_page.close();
});
}
};
const closeConfigPage = () => {
store.config_page.close();
};
return { createConfigPage, closeConfigPage };
};