[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.
This commit is contained in:
@@ -8,7 +8,7 @@ import { useMessageInputBoxRatio } from "@logics_main";
|
|||||||
import { useUiScaling } from "@logics_configs";
|
import { useUiScaling } from "@logics_configs";
|
||||||
|
|
||||||
export const MessageContainer = () => {
|
export const MessageContainer = () => {
|
||||||
const { currentMessageInputBoxRatio, setMessageInputBoxRatio } = useMessageInputBoxRatio();
|
const { currentMessageInputBoxRatio, asyncSetMessageInputBoxRatio } = useMessageInputBoxRatio();
|
||||||
const { currentUiScaling } = useUiScaling();
|
const { currentUiScaling } = useUiScaling();
|
||||||
const [message_box_height_in_rem, setMessageBoxHeightInRem] = useState(10);
|
const [message_box_height_in_rem, setMessageBoxHeightInRem] = useState(10);
|
||||||
const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem
|
const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem
|
||||||
@@ -17,6 +17,12 @@ export const MessageContainer = () => {
|
|||||||
const log_box_ref = useRef(null);
|
const log_box_ref = useRef(null);
|
||||||
const message_box_wrapper_ref = useRef(null);
|
const message_box_wrapper_ref = useRef(null);
|
||||||
|
|
||||||
|
const asyncSetMessageBoxHeightInRem = async (data) => {
|
||||||
|
const minimized = await appWindow.isMinimized();
|
||||||
|
if (minimized === true) return; // don't save while the window is minimized.
|
||||||
|
setMessageBoxHeightInRem(data);
|
||||||
|
};
|
||||||
|
|
||||||
const calculateMessageBoxRatioAndHeight = () => {
|
const calculateMessageBoxRatioAndHeight = () => {
|
||||||
if (log_box_ref.current && message_box_wrapper_ref.current) {
|
if (log_box_ref.current && message_box_wrapper_ref.current) {
|
||||||
const container_height = container_ref.current.offsetHeight;
|
const container_height = container_ref.current.offsetHeight;
|
||||||
@@ -26,10 +32,10 @@ export const MessageContainer = () => {
|
|||||||
const message_box_height = message_box_wrapper_ref.current.offsetHeight;
|
const message_box_height = message_box_wrapper_ref.current.offsetHeight;
|
||||||
const message_box_ratio = (message_box_height / total_height) * 100;
|
const message_box_ratio = (message_box_height / total_height) * 100;
|
||||||
|
|
||||||
setMessageInputBoxRatio(message_box_ratio);
|
asyncSetMessageInputBoxRatio(message_box_ratio);
|
||||||
|
|
||||||
const height_in_rem = convertRatioToRem(message_box_ratio);
|
const height_in_rem = convertRatioToRem(message_box_ratio);
|
||||||
setMessageBoxHeightInRem(height_in_rem);
|
asyncSetMessageBoxHeightInRem(height_in_rem);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,12 +48,12 @@ export const MessageContainer = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Note: I thought the part "1.4" is message box bottom padding + (message box separator height/2)
|
// Note: I thought the part "1.4" is message box bottom padding + (message box separator height/2)
|
||||||
// but it should be fixed at 1.4. Idk why, tho.
|
// but it should be fixed at 1.4. Idk why, tho.
|
||||||
setMessageBoxHeightInRem((position / FONT_SIZE_STANDARD) - 1.4);
|
asyncSetMessageBoxHeightInRem((position / FONT_SIZE_STANDARD) - 1.4);
|
||||||
}, [position]);
|
}, [position]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data));
|
asyncSetMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data));
|
||||||
}, [currentMessageInputBoxRatio.data]);
|
}, [currentMessageInputBoxRatio.data]);
|
||||||
|
|
||||||
const convertRatioToRem = (ratio) => {
|
const convertRatioToRem = (ratio) => {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { appWindow, currentMonitor, LogicalPosition, LogicalSize } from "@tauri-apps/api/window";
|
import { appWindow, currentMonitor, availableMonitors, LogicalPosition, LogicalSize } from "@tauri-apps/api/window";
|
||||||
|
|
||||||
export const useWindow = () => {
|
export const useWindow = () => {
|
||||||
const { asyncStdoutToPython } = useStdoutToPython();
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
const asyncGetWindowGeometry = async () => {
|
const asyncGetWindowGeometry = async () => {
|
||||||
@@ -24,25 +23,57 @@ export const useWindow = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const asyncSaveWindowGeometry = async () => {
|
const asyncSaveWindowGeometry = async () => {
|
||||||
|
const minimized = await appWindow.isMinimized();
|
||||||
|
if (minimized === true) return; // don't save while the window is minimized.
|
||||||
const data = await asyncGetWindowGeometry();
|
const data = await asyncGetWindowGeometry();
|
||||||
asyncStdoutToPython("/set/data/main_window_geometry", data);
|
asyncStdoutToPython("/set/data/main_window_geometry", data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreWindowGeometry = async (data) => {
|
const restoreWindowGeometry = async (data) => {
|
||||||
try {
|
try {
|
||||||
const monitor = await currentMonitor();
|
const monitors = await availableMonitors();
|
||||||
|
const { x_pos, y_pos, width, height } = data;
|
||||||
|
|
||||||
if (monitor) {
|
// ウィンドウが属するモニターを特定
|
||||||
const { width: monitorWidth, height: monitorHeight } = monitor.size;
|
const targetMonitor = monitors.find(monitor =>
|
||||||
|
x_pos >= monitor.position.x &&
|
||||||
|
y_pos >= monitor.position.y &&
|
||||||
|
x_pos < monitor.position.x + monitor.size.width &&
|
||||||
|
y_pos < monitor.position.y + monitor.size.height
|
||||||
|
) || await currentMonitor();
|
||||||
|
|
||||||
let width = Math.min(parseInt(data.width), monitorWidth);
|
if (targetMonitor) {
|
||||||
let height = Math.min(parseInt(data.height), monitorHeight);
|
const { width: monitorWidth, height: monitorHeight } = targetMonitor.size;
|
||||||
|
const { x: monitorX, y: monitorY } = targetMonitor.position;
|
||||||
|
|
||||||
const x = parseInt(data.x_pos);
|
// ウィンドウのサイズをモニターサイズ内に収める
|
||||||
const y = parseInt(data.y_pos);
|
let adjustedWidth = Math.min(parseInt(width), monitorWidth);
|
||||||
|
let adjustedHeight = Math.min(parseInt(height), monitorHeight);
|
||||||
|
|
||||||
await appWindow.setPosition(new LogicalPosition(x, y));
|
// ウィンドウの位置をモニターの範囲内に収める
|
||||||
await appWindow.setSize(new LogicalSize(width, height));
|
let adjustedX = parseInt(x_pos);
|
||||||
|
let adjustedY = parseInt(y_pos);
|
||||||
|
|
||||||
|
// X座標がモニター左にはみ出ている場合
|
||||||
|
if (adjustedX < monitorX) {
|
||||||
|
adjustedX = monitorX;
|
||||||
|
}
|
||||||
|
// X座標がモニター右にはみ出ている場合
|
||||||
|
else if (adjustedX + adjustedWidth > monitorX + monitorWidth) {
|
||||||
|
adjustedX = monitorX + monitorWidth - adjustedWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Y座標がモニター上にはみ出ている場合
|
||||||
|
if (adjustedY < monitorY) {
|
||||||
|
adjustedY = monitorY;
|
||||||
|
}
|
||||||
|
// Y座標がモニター下にはみ出ている場合
|
||||||
|
else if (adjustedY + adjustedHeight > monitorY + monitorHeight) {
|
||||||
|
adjustedY = monitorY + monitorHeight - adjustedHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
await appWindow.setPosition(new LogicalPosition(adjustedX, adjustedY));
|
||||||
|
await appWindow.setSize(new LogicalSize(adjustedWidth, adjustedHeight));
|
||||||
} else {
|
} else {
|
||||||
console.error("Monitor information could not be retrieved.");
|
console.error("Monitor information could not be retrieved.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
import { useStore_MessageInputBoxRatio } from "@store";
|
import { useStore_MessageInputBoxRatio } from "@store";
|
||||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||||
import { clampMinMax } from "@utils/clampMinMax";
|
import { clampMinMax } from "@utils/clampMinMax";
|
||||||
@@ -9,7 +10,9 @@ export const useMessageInputBoxRatio = () => {
|
|||||||
asyncStdoutToPython("/get/data/message_box_ratio");
|
asyncStdoutToPython("/get/data/message_box_ratio");
|
||||||
};
|
};
|
||||||
|
|
||||||
const setMessageInputBoxRatio = (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 parsed = parseFloat(ratio.toFixed(2));
|
||||||
const valid_ratio = clampMinMax(parsed, 1, 99);
|
const valid_ratio = clampMinMax(parsed, 1, 99);
|
||||||
asyncStdoutToPython("/set/data/message_box_ratio", valid_ratio);
|
asyncStdoutToPython("/set/data/message_box_ratio", valid_ratio);
|
||||||
@@ -19,6 +22,6 @@ export const useMessageInputBoxRatio = () => {
|
|||||||
currentMessageInputBoxRatio,
|
currentMessageInputBoxRatio,
|
||||||
getMessageInputBoxRatio,
|
getMessageInputBoxRatio,
|
||||||
updateMessageInputBoxRatio,
|
updateMessageInputBoxRatio,
|
||||||
setMessageInputBoxRatio,
|
asyncSetMessageInputBoxRatio,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user