[Update] Add feature Restore Main Window Geometry.
Note: the toggle-able setting, to restore or don't, has removed for now.
This commit is contained in:
@@ -445,7 +445,7 @@ class Config:
|
|||||||
def MAIN_WINDOW_GEOMETRY(self, value):
|
def MAIN_WINDOW_GEOMETRY(self, value):
|
||||||
if isinstance(value, dict) and set(value.keys()) == set(self.MAIN_WINDOW_GEOMETRY.keys()):
|
if isinstance(value, dict) and set(value.keys()) == set(self.MAIN_WINDOW_GEOMETRY.keys()):
|
||||||
for key, value in value.items():
|
for key, value in value.items():
|
||||||
if isinstance(value, str):
|
if isinstance(value, int):
|
||||||
self._MAIN_WINDOW_GEOMETRY[key] = value
|
self._MAIN_WINDOW_GEOMETRY[key] = value
|
||||||
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.MAIN_WINDOW_GEOMETRY)
|
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.MAIN_WINDOW_GEOMETRY)
|
||||||
|
|
||||||
@@ -1106,10 +1106,10 @@ class Config:
|
|||||||
self._UI_LANGUAGE = "en"
|
self._UI_LANGUAGE = "en"
|
||||||
self._RESTORE_MAIN_WINDOW_GEOMETRY = True
|
self._RESTORE_MAIN_WINDOW_GEOMETRY = True
|
||||||
self._MAIN_WINDOW_GEOMETRY = {
|
self._MAIN_WINDOW_GEOMETRY = {
|
||||||
"x_pos": "0",
|
"x_pos": 0,
|
||||||
"y_pos": "0",
|
"y_pos": 0,
|
||||||
"width": "870",
|
"width": 870,
|
||||||
"height": "654",
|
"height": 654,
|
||||||
}
|
}
|
||||||
self._AUTO_MIC_SELECT = True
|
self._AUTO_MIC_SELECT = True
|
||||||
self._SELECTED_MIC_HOST = device_manager.getDefaultMicDevice()["host"]["name"]
|
self._SELECTED_MIC_HOST = device_manager.getDefaultMicDevice()["host"]["name"]
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ edition = "2021"
|
|||||||
tauri-build = { version = "1", features = [] }
|
tauri-build = { version = "1", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "1", features = [ "window-unmaximize", "window-close", "window-maximize", "window-minimize", "window-unminimize", "window-start-dragging", "window-set-decorations", "window-set-always-on-top", "shell-sidecar", "shell-open", "devtools"] }
|
tauri = { version = "1", features = [ "window-set-size", "window-set-position", "window-unmaximize", "window-close", "window-maximize", "window-minimize", "window-unminimize", "window-start-dragging", "window-set-decorations", "window-set-always-on-top", "shell-sidecar", "shell-open", "devtools"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
font-kit = "0.14.2"
|
font-kit = "0.14.2"
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
"setAlwaysOnTop": true,
|
"setAlwaysOnTop": true,
|
||||||
"setDecorations": true,
|
"setDecorations": true,
|
||||||
"close": true,
|
"close": true,
|
||||||
|
"setPosition": true,
|
||||||
|
"setSize": true,
|
||||||
"maximize": true,
|
"maximize": true,
|
||||||
"minimize": true,
|
"minimize": true,
|
||||||
"unmaximize": true,
|
"unmaximize": true,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ConfigPage } from "./config_page/ConfigPage";
|
|||||||
import styles from "./App.module.scss";
|
import styles from "./App.module.scss";
|
||||||
|
|
||||||
export const App = () => {
|
export const App = () => {
|
||||||
|
const { WindowGeometryController } = useWindow();
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<StartPythonFacadeComponent />
|
<StartPythonFacadeComponent />
|
||||||
@@ -14,6 +15,7 @@ export const App = () => {
|
|||||||
<UiSizeController />
|
<UiSizeController />
|
||||||
<FontFamilyController />
|
<FontFamilyController />
|
||||||
<TransparencyController />
|
<TransparencyController />
|
||||||
|
<WindowGeometryController />
|
||||||
|
|
||||||
<WindowTitleBar />
|
<WindowTitleBar />
|
||||||
<div className={styles.pages_wrapper}>
|
<div className={styles.pages_wrapper}>
|
||||||
@@ -24,6 +26,11 @@ export const App = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
import {
|
||||||
|
useWindow,
|
||||||
|
useVolume,
|
||||||
|
useIsOpenedConfigPage,
|
||||||
|
} from "@logics_common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
useSoftwareVersion,
|
useSoftwareVersion,
|
||||||
@@ -59,6 +66,8 @@ const StartPythonFacadeComponent = () => {
|
|||||||
const hasRunRef = useRef(false);
|
const hasRunRef = useRef(false);
|
||||||
const { asyncFetchFonts } = useAsyncFetchFonts();
|
const { asyncFetchFonts } = useAsyncFetchFonts();
|
||||||
|
|
||||||
|
const { fetchAndUpdateWindowGeometry } = useWindow();
|
||||||
|
|
||||||
const { getMicHostList } = useMicHostList();
|
const { getMicHostList } = useMicHostList();
|
||||||
const { getMicDeviceList } = useMicDeviceList();
|
const { getMicDeviceList } = useMicDeviceList();
|
||||||
const { getSpeakerDeviceList } = useSpeakerDeviceList();
|
const { getSpeakerDeviceList } = useSpeakerDeviceList();
|
||||||
@@ -97,6 +106,8 @@ const StartPythonFacadeComponent = () => {
|
|||||||
asyncStartPython().then(() => {
|
asyncStartPython().then(() => {
|
||||||
startFeedingToWatchDog();
|
startFeedingToWatchDog();
|
||||||
|
|
||||||
|
fetchAndUpdateWindowGeometry();
|
||||||
|
|
||||||
getUiLanguage();
|
getUiLanguage();
|
||||||
getUiScaling();
|
getUiScaling();
|
||||||
getMessageLogUiScaling();
|
getMessageLogUiScaling();
|
||||||
@@ -156,10 +167,6 @@ const UiLanguageController = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
import { useStore_MainFunctionsStateMemory } from "@store";
|
import { useStore_MainFunctionsStateMemory } from "@store";
|
||||||
import {
|
|
||||||
useVolume,
|
|
||||||
useIsOpenedConfigPage,
|
|
||||||
} from "@logics_common";
|
|
||||||
|
|
||||||
const ConfigPageCloseTrigger = () => {
|
const ConfigPageCloseTrigger = () => {
|
||||||
const { currentIsOpenedConfigPage } = useIsOpenedConfigPage();
|
const { currentIsOpenedConfigPage } = useIsOpenedConfigPage();
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import {
|
|||||||
useMessageLogUiScaling,
|
useMessageLogUiScaling,
|
||||||
useSelectedFontFamily,
|
useSelectedFontFamily,
|
||||||
useTransparency,
|
useTransparency,
|
||||||
|
// useRestoreWindowGeometry,
|
||||||
} from "@logics_configs";
|
} from "@logics_configs";
|
||||||
|
|
||||||
export const Appearance = () => {
|
export const Appearance = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const {
|
const {
|
||||||
DropdownMenuContainer,
|
// DropdownMenuContainer,
|
||||||
// SliderContainer,
|
// SliderContainer,
|
||||||
// CheckboxContainer,
|
// CheckboxContainer,
|
||||||
// SwitchboxContainer,
|
// SwitchboxContainer,
|
||||||
@@ -33,6 +34,7 @@ export const Appearance = () => {
|
|||||||
<MessageLogUiScalingContainer />
|
<MessageLogUiScalingContainer />
|
||||||
<FontFamilyContainer />
|
<FontFamilyContainer />
|
||||||
<TransparencyContainer />
|
<TransparencyContainer />
|
||||||
|
{/* <RestoreWindowGeometryContainer /> */}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -254,3 +256,19 @@ const TransparencyContainer = () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// import { CheckboxContainer } from "../components/useSettingBox";
|
||||||
|
|
||||||
|
// const RestoreWindowGeometryContainer = () => {
|
||||||
|
// const { t } = useTranslation();
|
||||||
|
// const { currentRestoreWindowGeometry, toggleRestoreWindowGeometry } = useRestoreWindowGeometry();
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <CheckboxContainer
|
||||||
|
// label={t("config_page.to_restore_main_page_geometry.label")}
|
||||||
|
// desc={t("config_page.to_restore_main_page_geometry.desc")}
|
||||||
|
// variable={currentRestoreWindowGeometry}
|
||||||
|
// toggleFunction={toggleRestoreWindowGeometry}
|
||||||
|
// />
|
||||||
|
// );
|
||||||
|
// };
|
||||||
@@ -45,17 +45,16 @@ export const SliderContainer = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CheckboxContainer = (props) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<LabelComponent label={props.label} desc={props.desc} />
|
||||||
|
<Checkbox {...props}/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const useSettingBox = () => {
|
export const useSettingBox = () => {
|
||||||
|
|
||||||
const CheckboxContainer = (props) => {
|
|
||||||
return (
|
|
||||||
<div className={styles.container}>
|
|
||||||
<LabelComponent label={props.label} desc={props.desc} />
|
|
||||||
<Checkbox {...props}/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const SwitchboxContainer = (props) => {
|
const SwitchboxContainer = (props) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export { useWindow } from "./useWindow";
|
||||||
export { useIsOpenedConfigPage } from "./useIsOpenedConfigPage";
|
export { useIsOpenedConfigPage } from "./useIsOpenedConfigPage";
|
||||||
export { useMessage } from "./useMessage";
|
export { useMessage } from "./useMessage";
|
||||||
export { useVolume } from "./useVolume";
|
export { useVolume } from "./useVolume";
|
||||||
92
src-ui/logics/common/useWindow.js
Normal file
92
src-ui/logics/common/useWindow.js
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { appWindow, currentMonitor, LogicalPosition, LogicalSize } from "@tauri-apps/api/window";
|
||||||
|
|
||||||
|
export const useWindow = () => {
|
||||||
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
|
const asyncGetWindowGeometry = async () => {
|
||||||
|
try {
|
||||||
|
const position = await appWindow.outerPosition();
|
||||||
|
const { x, y } = position;
|
||||||
|
|
||||||
|
const size = await appWindow.outerSize();
|
||||||
|
const { width, height } = size;
|
||||||
|
|
||||||
|
return {
|
||||||
|
x_pos: x,
|
||||||
|
y_pos: y,
|
||||||
|
width: width,
|
||||||
|
height: height
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error getting window position and size:", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const asyncSaveWindowGeometry = async () => {
|
||||||
|
const data = await asyncGetWindowGeometry();
|
||||||
|
asyncStdoutToPython("/set/data/main_window_geometry", data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreWindowGeometry = async (data) => {
|
||||||
|
try {
|
||||||
|
const monitor = await currentMonitor();
|
||||||
|
|
||||||
|
if (monitor) {
|
||||||
|
const { width: monitorWidth, height: monitorHeight } = monitor.size;
|
||||||
|
|
||||||
|
let width = Math.min(parseInt(data.width), monitorWidth);
|
||||||
|
let height = Math.min(parseInt(data.height), monitorHeight);
|
||||||
|
|
||||||
|
const x = parseInt(data.x_pos);
|
||||||
|
const y = parseInt(data.y_pos);
|
||||||
|
|
||||||
|
await appWindow.setPosition(new LogicalPosition(x, y));
|
||||||
|
await appWindow.setSize(new LogicalSize(width, height));
|
||||||
|
} else {
|
||||||
|
console.error("Monitor information could not be retrieved.");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error setting window position and size:", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchAndUpdateWindowGeometry = () => {
|
||||||
|
asyncStdoutToPython("/get/data/main_window_geometry");
|
||||||
|
};
|
||||||
|
|
||||||
|
const WindowGeometryController = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
let resizeTimeout;
|
||||||
|
const unlistenResize = appWindow.onResized(() => {
|
||||||
|
clearTimeout(resizeTimeout);
|
||||||
|
resizeTimeout = setTimeout(asyncSaveWindowGeometry, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unlistenResize.then((dispose) => dispose());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let moveTimeout;
|
||||||
|
const unlistenMove = appWindow.onMoved(() => {
|
||||||
|
clearTimeout(moveTimeout);
|
||||||
|
moveTimeout = setTimeout(asyncSaveWindowGeometry, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unlistenMove.then((dispose) => dispose());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
WindowGeometryController,
|
||||||
|
asyncSaveWindowGeometry,
|
||||||
|
fetchAndUpdateWindowGeometry,
|
||||||
|
restoreWindowGeometry,
|
||||||
|
};
|
||||||
|
};
|
||||||
28
src-ui/logics/configs/appearance/useRestoreWindowGeometry.js
Normal file
28
src-ui/logics/configs/appearance/useRestoreWindowGeometry.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// import { useStore_RestoreWindowGeometry } from "@store";
|
||||||
|
// import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||||
|
|
||||||
|
// export const useRestoreWindowGeometry = () => {
|
||||||
|
// const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
|
// const { currentRestoreWindowGeometry, updateRestoreWindowGeometry, pendingRestoreWindowGeometry } = useStore_RestoreWindowGeometry();
|
||||||
|
|
||||||
|
// const getRestoreWindowGeometry = () => {
|
||||||
|
// pendingRestoreWindowGeometry();
|
||||||
|
// asyncStdoutToPython("/get/data/restore_main_window_geometry");
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const toggleRestoreWindowGeometry = () => {
|
||||||
|
// pendingRestoreWindowGeometry();
|
||||||
|
// if (currentRestoreWindowGeometry.data) {
|
||||||
|
// asyncStdoutToPython("/set/disable/restore_main_window_geometry");
|
||||||
|
// } else {
|
||||||
|
// asyncStdoutToPython("/set/enable/restore_main_window_geometry");
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// currentRestoreWindowGeometry,
|
||||||
|
// getRestoreWindowGeometry,
|
||||||
|
// toggleRestoreWindowGeometry,
|
||||||
|
// updateRestoreWindowGeometry,
|
||||||
|
// };
|
||||||
|
// };
|
||||||
@@ -10,6 +10,7 @@ export { useSpeakerDeviceList } from "./device/useSpeakerDeviceList";
|
|||||||
export { useSpeakerThreshold } from "./device/useSpeakerThreshold";
|
export { useSpeakerThreshold } from "./device/useSpeakerThreshold";
|
||||||
|
|
||||||
export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling";
|
export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling";
|
||||||
|
// export { useRestoreWindowGeometry } from "./appearance/useRestoreWindowGeometry";
|
||||||
export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily";
|
export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily";
|
||||||
export { useSendMessageButtonType } from "./appearance/useSendMessageButtonType";
|
export { useSendMessageButtonType } from "./appearance/useSendMessageButtonType";
|
||||||
export { useTransparency } from "./appearance/useTransparency";
|
export { useTransparency } from "./appearance/useTransparency";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { translator_status } from "@data";
|
|||||||
import { arrayToObject } from "@utils/arrayToObject";
|
import { arrayToObject } from "@utils/arrayToObject";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
useWindow,
|
||||||
useMessage,
|
useMessage,
|
||||||
useVolume,
|
useVolume,
|
||||||
} from "@logics_common";
|
} from "@logics_common";
|
||||||
@@ -33,9 +34,11 @@ import {
|
|||||||
useUiScaling,
|
useUiScaling,
|
||||||
useMessageLogUiScaling,
|
useMessageLogUiScaling,
|
||||||
useTransparency,
|
useTransparency,
|
||||||
|
// useRestoreWindowGeometry,
|
||||||
} from "@logics_configs";
|
} from "@logics_configs";
|
||||||
|
|
||||||
export const useReceiveRoutes = () => {
|
export const useReceiveRoutes = () => {
|
||||||
|
const { restoreWindowGeometry } = useWindow();
|
||||||
const { updateIsMainPageCompactMode } = useIsMainPageCompactMode();
|
const { updateIsMainPageCompactMode } = useIsMainPageCompactMode();
|
||||||
const {
|
const {
|
||||||
updateTranslationStatus,
|
updateTranslationStatus,
|
||||||
@@ -82,10 +85,15 @@ export const useReceiveRoutes = () => {
|
|||||||
const { updateMessageInputBoxRatio } = useMessageInputBoxRatio();
|
const { updateMessageInputBoxRatio } = useMessageInputBoxRatio();
|
||||||
const { updateSelectedFontFamily } = useSelectedFontFamily();
|
const { updateSelectedFontFamily } = useSelectedFontFamily();
|
||||||
const { updateTransparency } = useTransparency();
|
const { updateTransparency } = useTransparency();
|
||||||
|
// const { updateRestoreWindowGeometry } = useRestoreWindowGeometry();
|
||||||
|
|
||||||
|
|
||||||
const routes = {
|
const routes = {
|
||||||
|
// Common
|
||||||
"/run/feed_watchdog": () => {},
|
"/run/feed_watchdog": () => {},
|
||||||
|
"/get/data/main_window_geometry": restoreWindowGeometry,
|
||||||
|
"/set/data/main_window_geometry": () => {},
|
||||||
|
|
||||||
// Main Page
|
// Main Page
|
||||||
// Page Controls
|
// Page Controls
|
||||||
"/get/data/main_window_sidebar_compact_mode": updateIsMainPageCompactMode,
|
"/get/data/main_window_sidebar_compact_mode": updateIsMainPageCompactMode,
|
||||||
@@ -222,6 +230,10 @@ export const useReceiveRoutes = () => {
|
|||||||
"/get/data/transparency": updateTransparency,
|
"/get/data/transparency": updateTransparency,
|
||||||
"/set/data/transparency": updateTransparency,
|
"/set/data/transparency": updateTransparency,
|
||||||
|
|
||||||
|
// "/get/data/restore_main_window_geometry": updateRestoreWindowGeometry,
|
||||||
|
// "/set/enable/restore_main_window_geometry": updateRestoreWindowGeometry,
|
||||||
|
// "/set/disable/restore_main_window_geometry": updateRestoreWindowGeometry,
|
||||||
|
|
||||||
// Others Tab
|
// Others Tab
|
||||||
"/get/data/auto_clear_message_box": updateEnableAutoClearMessageBox,
|
"/get/data/auto_clear_message_box": updateEnableAutoClearMessageBox,
|
||||||
"/set/enable/auto_clear_message_box": updateEnableAutoClearMessageBox,
|
"/set/enable/auto_clear_message_box": updateEnableAutoClearMessageBox,
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ const createAtomWithHook = (initialValue, base_name, options) => {
|
|||||||
|
|
||||||
|
|
||||||
// Common
|
// Common
|
||||||
|
// export const { atomInstance: Atom_RestoreWindowGeometry, useHook: useStore_RestoreWindowGeometry } = createAtomWithHook(true, "RestoreWindowGeometry");
|
||||||
export const { atomInstance: Atom_IsOpenedConfigPage, useHook: useStore_IsOpenedConfigPage } = createAtomWithHook(false, "IsOpenedConfigPage");
|
export const { atomInstance: Atom_IsOpenedConfigPage, useHook: useStore_IsOpenedConfigPage } = createAtomWithHook(false, "IsOpenedConfigPage");
|
||||||
export const { atomInstance: Atom_MainFunctionsStateMemory, useHook: useStore_MainFunctionsStateMemory } = createAtomWithHook({
|
export const { atomInstance: Atom_MainFunctionsStateMemory, useHook: useStore_MainFunctionsStateMemory } = createAtomWithHook({
|
||||||
transcription_send: false,
|
transcription_send: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user