Files
VRCT/src-ui/logics/main/useMessageInputBoxRatio.js
Sakamoto Shiina 0f599ce679 [bugfix] 1: To do not restore and save the data x,y_pos and its size when the window is minimized.
2: To do not restore and save the message box ratio data when the window is minimized either.
2024-11-05 21:26:13 +09:00

27 lines
1.1 KiB
JavaScript

import { appWindow } from "@tauri-apps/api/window";
import { useStore_MessageInputBoxRatio } from "@store";
import { useStdoutToPython } from "@logics/useStdoutToPython";
import { clampMinMax } from "@utils/clampMinMax";
export const useMessageInputBoxRatio = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentMessageInputBoxRatio, updateMessageInputBoxRatio } = useStore_MessageInputBoxRatio();
const getMessageInputBoxRatio = () => {
asyncStdoutToPython("/get/data/message_box_ratio");
};
const asyncSetMessageInputBoxRatio = async (ratio) => {
const minimized = await appWindow.isMinimized();
if (minimized === true) return; // don't save while the window is minimized.
const parsed = parseFloat(ratio.toFixed(2));
const valid_ratio = clampMinMax(parsed, 1, 99);
asyncStdoutToPython("/set/data/message_box_ratio", valid_ratio);
};
return {
currentMessageInputBoxRatio,
getMessageInputBoxRatio,
updateMessageInputBoxRatio,
asyncSetMessageInputBoxRatio,
};
};