[Update/bugfix] To get software version.(show it to the console for now.)

fix the error that was wrong amount arguments.
This commit is contained in:
Sakamoto Shiina
2024-08-08 16:36:40 +09:00
parent e9de5df8a5
commit e8fd6b724d
8 changed files with 66 additions and 8 deletions

View File

@@ -193,7 +193,7 @@ action_mapping = {
"/controller/callback_enable_check_mic_threshold": {"mic":"/action/check_mic_threshold_energy"},
}
def handleConfigRequest(endpoint):
def handleConfigRequest(endpoint, _data):
handler = config_mapping.get(endpoint)
if handler is None:
response = "Invalid endpoint"

View File

@@ -0,0 +1,22 @@
import {
useSoftwareVersion,
} from "@store";
import { useStdoutToPython } from "./useStdoutToPython";
export const useConfig = () => {
const {
updateSoftwareVersion,
} = useSoftwareVersion();
const { asyncStdoutToPython } = useStdoutToPython();
return {
getSoftwareVersion: () => {
asyncStdoutToPython({endpoint: "/config/version"});
},
updateSoftwareVersion: (payload) => {
updateSoftwareVersion(payload.data);
},
};
};

View File

@@ -1,4 +1,5 @@
import { useMainFunction } from "./useMainFunction";
import { useConfig } from "./useConfig";
export const useReceiveRoutes = () => {
const {
@@ -7,22 +8,28 @@ export const useReceiveRoutes = () => {
updateTranscriptionReceiveStatus,
} = useMainFunction();
const {
updateSoftwareVersion,
} = useConfig();
const routes = {
"/controller/callback_toggle_translation": updateTranslationStatus,
"/controller/callback_toggle_transcription_send": updateTranscriptionSendStatus,
"/controller/callback_toggle_transcription_receive": updateTranscriptionReceiveStatus,
"/config/version": updateSoftwareVersion,
};
const receiveRoutes = (parsed_data) => {
if (parsed_data.status === "ok") {
const route = routes[parsed_data.id];
if (parsed_data.status === 200) {
const route = routes[parsed_data.endpoint];
if (route) {
route({ data: parsed_data.data });
route({ data: parsed_data.result });
} else {
console.error(`Invalid path: ${parsed_data.id}`);
console.error(`Invalid path: ${parsed_data.endpoint}`);
}
} else {
console.log("Received data status is not 'ok'.", parsed_data);
console.log("Received data status is not '200'.", parsed_data);
}
};
return { receiveRoutes };

View File

@@ -11,12 +11,12 @@ export const useStartPython = () => {
let parsed_data = "";
try {
parsed_data = JSON.parse(line);
receiveRoutes(parsed_data);
} catch (error) {
console.log(error);
parsed_data = line;
}
console.log("from python:", parsed_data);
receiveRoutes(parsed_data);
});
command.stderr.on("data", line => console.error("stderr:", line));
const backend_subprocess = await command.spawn();

View File

@@ -95,6 +95,8 @@ const createAsyncAtomWithHook = (initialValue, base_ame) => {
return { atomInstance, useHook };
};
export const { atomInstance: Atom_SoftwareVersion, useHook: useSoftwareVersion } = createAtomWithHook("-", "SoftwareVersion");
export const { atomInstance: Atom_UiLanguageStatus, useHook: useUiLanguageStatus } = createAtomWithHook("en", "UiLanguageStatus");
export const { atomInstance: Atom_TranslationStatus, useHook: useTranslationStatus } = createAsyncAtomWithHook(false, "TranslationStatus");
export const { atomInstance: Atom_TranscriptionSendStatus, useHook: useTranscriptionSendStatus } = createAsyncAtomWithHook(false, "TranscriptionSendStatus");

View File

@@ -4,7 +4,14 @@ import { Topbar } from "./topbar/Topbar";
import { SidebarSection } from "./sidebar_section/SidebarSection";
import { SettingSection } from "./setting_section/SettingSection.jsx";
import { useSoftwareVersion } from "@store";
import { useTranslation } from "react-i18next";
// import { useConfig } from "@logics/useConfig";
export const ConfigWindow = () => {
const { currentSoftwareVersion, updateSoftwareVersion } = useSoftwareVersion();
const { t } = useTranslation();
return (
<div className={styles.container}>
<Topbar />
@@ -12,6 +19,11 @@ export const ConfigWindow = () => {
<SidebarSection />
<SettingSection />
</div>
<p className={styles.software_version}>
{
t("config_window.version", {version: currentSoftwareVersion})
}
</p>
</div>
);
};

View File

@@ -6,6 +6,7 @@
justify-content: space-between;
background-color: var(--dark_950_color);
overflow: hidden;
position: relative;
}
.main_container {
@@ -13,4 +14,11 @@
height: 100%;
display: flex;
padding-top: var(--config_window_topbar_height);
}
.software_version {
position: absolute;
bottom: 0.8rem;
left: 1.2rem;
font-size: 1.4rem;
}

View File

@@ -4,16 +4,23 @@ import styles from "./MainWindow.module.scss";
import { SidebarSection } from "./sidebar_section/SidebarSection";
import { MainSection } from "./main_section/MainSection";
import { useStartPython } from "@logics/useStartPython";
import { useConfig } from "@logics/useConfig";
export const MainWindow = () => {
const { asyncStartPython } = useStartPython();
const hasRunRef = useRef(false);
const main_window = getCurrent();
const { getSoftwareVersion } = useConfig();
useEffect(() => {
main_window.setDecorations(true);
if (!hasRunRef.current) {
asyncStartPython();
asyncStartPython().then((result) => {
getSoftwareVersion();
}).catch((err) => {
});
}
return () => hasRunRef.current = true;
}, []);