[Update] Migrate to tauri-app(Web UI)
This commit is contained in:
81
src-ui/utils/logics/useMainFunction.js
Normal file
81
src-ui/utils/logics/useMainFunction.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import { getCurrent } from "@tauri-apps/api/window";
|
||||
|
||||
import {
|
||||
useState_Translation,
|
||||
useState_TranscriptionSend,
|
||||
useState_TranscriptionReceive,
|
||||
useState_Foreground,
|
||||
} from "@store";
|
||||
|
||||
import { useStdoutToPython } from "./useStdoutToPython";
|
||||
|
||||
export const useMainFunction = () => {
|
||||
const {
|
||||
currentState_Translation,
|
||||
updateState_Translation,
|
||||
asyncUpdateState_Translation,
|
||||
} = useState_Translation();
|
||||
const {
|
||||
currentState_TranscriptionSend,
|
||||
updateState_TranscriptionSend,
|
||||
asyncUpdateState_TranscriptionSend,
|
||||
} = useState_TranscriptionSend();
|
||||
const {
|
||||
currentState_TranscriptionReceive,
|
||||
updateState_TranscriptionReceive,
|
||||
asyncUpdateState_TranscriptionReceive,
|
||||
} = useState_TranscriptionReceive();
|
||||
const {
|
||||
currentState_Foreground,
|
||||
updateState_Foreground,
|
||||
} = useState_Foreground();
|
||||
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
|
||||
const asyncPending = () => new Promise(() => {});
|
||||
return {
|
||||
toggleTranslation: () => {
|
||||
asyncStdoutToPython({id: "/controller/callback_toggle_translation", data: !currentState_Translation.data});
|
||||
asyncUpdateState_Translation(asyncPending);
|
||||
},
|
||||
currentState_Translation: currentState_Translation,
|
||||
updateState_Translation: (payload) => {
|
||||
updateState_Translation(payload.data);
|
||||
},
|
||||
|
||||
toggleTranscriptionSend: () => {
|
||||
asyncStdoutToPython({id: "/controller/callback_toggle_transcription_send", data: !currentState_TranscriptionSend.data});
|
||||
asyncUpdateState_TranscriptionSend(asyncPending);
|
||||
},
|
||||
currentState_TranscriptionSend: currentState_TranscriptionSend,
|
||||
updateState_TranscriptionSend: (payload) => {
|
||||
updateState_TranscriptionSend(payload.data);
|
||||
},
|
||||
|
||||
toggleTranscriptionReceive: () => {
|
||||
asyncStdoutToPython({id: "/controller/callback_toggle_transcription_receive", data: !currentState_TranscriptionReceive.data});
|
||||
asyncUpdateState_TranscriptionReceive(asyncPending);
|
||||
},
|
||||
currentState_TranscriptionReceive: currentState_TranscriptionReceive,
|
||||
updateState_TranscriptionReceive: (payload) => {
|
||||
updateState_TranscriptionReceive(payload.data);
|
||||
},
|
||||
|
||||
toggleForeground: () => {
|
||||
const main_window = getCurrent();
|
||||
const is_foreground_enabled = !currentState_Foreground.data;
|
||||
main_window.setAlwaysOnTop(is_foreground_enabled);
|
||||
updateState_Foreground(is_foreground_enabled);
|
||||
|
||||
},
|
||||
currentState_Foreground: currentState_Foreground,
|
||||
};
|
||||
};
|
||||
|
||||
const asyncTestFunction = (...args) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(...args);
|
||||
}, 3000);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user