[Refactor] Organize logics files. and change import path as well.
This commit is contained in:
88
src-ui/logics/main/useMainFunction.js
Normal file
88
src-ui/logics/main/useMainFunction.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import { getCurrent } from "@tauri-apps/api/window";
|
||||
|
||||
import {
|
||||
useStore_TranslationStatus,
|
||||
useStore_TranscriptionSendStatus,
|
||||
useStore_TranscriptionReceiveStatus,
|
||||
useStore_ForegroundStatus,
|
||||
} from "@store";
|
||||
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
|
||||
export const useMainFunction = () => {
|
||||
const {
|
||||
currentTranslationStatus,
|
||||
updateTranslationStatus,
|
||||
asyncUpdateTranslationStatus,
|
||||
} = useStore_TranslationStatus();
|
||||
const {
|
||||
currentTranscriptionSendStatus,
|
||||
updateTranscriptionSendStatus,
|
||||
asyncUpdateTranscriptionSendStatus,
|
||||
} = useStore_TranscriptionSendStatus();
|
||||
const {
|
||||
currentTranscriptionReceiveStatus,
|
||||
updateTranscriptionReceiveStatus,
|
||||
asyncUpdateTranscriptionReceiveStatus,
|
||||
} = useStore_TranscriptionReceiveStatus();
|
||||
const {
|
||||
currentForegroundStatus,
|
||||
updateForegroundStatus,
|
||||
} = useStore_ForegroundStatus();
|
||||
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
|
||||
const asyncPending = () => new Promise(() => {});
|
||||
const toggleTranslation = () => {
|
||||
asyncUpdateTranslationStatus(asyncPending);
|
||||
if (currentTranslationStatus.data) {
|
||||
asyncStdoutToPython("/set/disable_translation");
|
||||
} else {
|
||||
asyncStdoutToPython("/set/enable_translation");
|
||||
}
|
||||
};
|
||||
|
||||
const toggleTranscriptionSend = () => {
|
||||
asyncUpdateTranscriptionSendStatus(asyncPending);
|
||||
if (currentTranscriptionSendStatus.data) {
|
||||
asyncStdoutToPython("/set/disable_transcription_send");
|
||||
} else {
|
||||
asyncStdoutToPython("/set/enable_transcription_send");
|
||||
}
|
||||
};
|
||||
|
||||
const toggleTranscriptionReceive = () => {
|
||||
asyncUpdateTranscriptionReceiveStatus(asyncPending);
|
||||
if (currentTranscriptionReceiveStatus.data) {
|
||||
asyncStdoutToPython("/set/disable_transcription_receive");
|
||||
} else {
|
||||
asyncStdoutToPython("/set/enable_transcription_receive");
|
||||
}
|
||||
};
|
||||
|
||||
const toggleForeground = () => {
|
||||
const main_page = getCurrent();
|
||||
const is_foreground_enabled = !currentForegroundStatus.data;
|
||||
main_page.setAlwaysOnTop(is_foreground_enabled);
|
||||
updateForegroundStatus(is_foreground_enabled);
|
||||
};
|
||||
|
||||
return {
|
||||
currentTranslationStatus,
|
||||
toggleTranslation,
|
||||
updateTranslationStatus,
|
||||
|
||||
currentTranscriptionSendStatus,
|
||||
toggleTranscriptionSend,
|
||||
updateTranscriptionSendStatus,
|
||||
|
||||
currentTranscriptionReceiveStatus,
|
||||
toggleTranscriptionReceive,
|
||||
updateTranscriptionReceiveStatus,
|
||||
|
||||
currentForegroundStatus,
|
||||
toggleForeground,
|
||||
updateForegroundStatus,
|
||||
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user