refactor main and rendered ipc
This commit is contained in:
parent
17e4b06948
commit
ddb2f4df0f
28 changed files with 758 additions and 211 deletions
|
|
@ -4,6 +4,8 @@ import { useIpc } from '@/modules/ipc';
|
|||
import { onMounted, onUnmounted, ref, Ref } from "vue";
|
||||
import keyboardNameMap from "../keyBoardMaps/keyboardNameMap";
|
||||
import { renderMessage, clientMessage } from '@/modules/message';
|
||||
import { postMessage } from "@/ipcRend/session";
|
||||
import { invokeStopRecord } from "@/ipcRend/audio";
|
||||
|
||||
|
||||
function showRecIcon () {
|
||||
|
|
@ -13,7 +15,7 @@ function showRecIcon () {
|
|||
opacity: [0, 0.75],
|
||||
scale: [0.0, 1],
|
||||
duration: 250,
|
||||
easing: 'linear',
|
||||
easing: 'linear',
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -25,7 +27,7 @@ function hideRecIcon () {
|
|||
opacity: [0.75, 0],
|
||||
scale: [1, 0],
|
||||
duration: 250,
|
||||
easing: 'linear',
|
||||
easing: 'linear',
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -50,7 +52,7 @@ export default function useAudioInputController (typing: Ref) {
|
|||
if (cmd == "SPACE" && !recording.value && !typing.value) {
|
||||
|
||||
console.log("INPT:Starting record.")
|
||||
post("start-recording", "");
|
||||
post("start-recording", null);
|
||||
|
||||
showRecIcon()
|
||||
recording.value = true;
|
||||
|
|
@ -67,9 +69,9 @@ export default function useAudioInputController (typing: Ref) {
|
|||
|
||||
// Create a message.
|
||||
const message = renderMessage(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"sf"
|
||||
)
|
||||
|
||||
|
|
@ -78,14 +80,19 @@ export default function useAudioInputController (typing: Ref) {
|
|||
|
||||
// Stop recording and get audio from recorder.
|
||||
console.log("INPT:Stopping record.")
|
||||
const audio = await invoke("stop-recording", "");
|
||||
|
||||
// Send message to the backend for processing.
|
||||
const clientM = clientMessage("", audio, message.uid);
|
||||
post('client-message', clientM);
|
||||
try {
|
||||
const audio = await invokeStopRecord() as string;
|
||||
// Send message to the backend for processing.
|
||||
const clientM = clientMessage("", audio, message.uid);
|
||||
postMessage(clientM);
|
||||
} catch(e) {
|
||||
console.log('Failed to fetch audio.')
|
||||
} finally {
|
||||
hideRecIcon();
|
||||
recording.value = false;
|
||||
}
|
||||
|
||||
|
||||
hideRecIcon()
|
||||
recording.value = false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { useIpc } from '@/modules/ipc';
|
|||
import { Ref, ref, watch, onMounted, onUnmounted } from "vue";
|
||||
import keyboardNameMap from "../keyBoardMaps/keyboardNameMap";
|
||||
import { clientMessage, renderMessage } from '@/modules/message';
|
||||
import { postMessage } from "@/ipcRend/session";
|
||||
|
||||
|
||||
//---Animations-----------------------------------------------
|
||||
|
||||
|
|
@ -19,7 +21,7 @@ function showTextInput () {
|
|||
translateX: [t1, t2],
|
||||
scale: [0.3, 1],
|
||||
duration: 500,
|
||||
easing: 'easeOutExpo',
|
||||
easing: 'easeOutExpo',
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +35,7 @@ function hideTextInput() {
|
|||
translateX: t,
|
||||
scale: 0.3,
|
||||
duration: 500,
|
||||
easing: 'easeOutExpo',
|
||||
easing: 'easeOutExpo',
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -45,7 +47,7 @@ function switchSide(currentSide: string) {
|
|||
targets: '#textInput',
|
||||
translateX: t,
|
||||
duration: 500,
|
||||
easing: 'easeOutExpo',
|
||||
easing: 'easeOutExpo',
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -75,7 +77,7 @@ export default function useTextInputController(elementX: Ref) {
|
|||
textInput.value = "";
|
||||
textInput.blur();
|
||||
}
|
||||
|
||||
|
||||
hideTextInput()
|
||||
firstKey = true;
|
||||
typing.value = false;
|
||||
|
|
@ -87,9 +89,9 @@ export default function useTextInputController(elementX: Ref) {
|
|||
|
||||
// Create the message.
|
||||
const message = renderMessage(
|
||||
textInput.value,
|
||||
false,
|
||||
"",
|
||||
textInput.value,
|
||||
false,
|
||||
"",
|
||||
"sf"
|
||||
)
|
||||
|
||||
|
|
@ -97,7 +99,7 @@ export default function useTextInputController(elementX: Ref) {
|
|||
|
||||
// Send it to the backend for processing.
|
||||
const clientM = clientMessage(textInput.value, false, message.uid);
|
||||
post('client-message', clientM);
|
||||
postMessage(clientM);
|
||||
|
||||
clearInput()
|
||||
}
|
||||
|
|
@ -115,9 +117,9 @@ export default function useTextInputController(elementX: Ref) {
|
|||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
const key = keyboardNameMap[e.keyCode]
|
||||
|
||||
|
||||
if (textInput) {
|
||||
|
||||
|
||||
// Only runs on firstKey.
|
||||
if (firstKey) {
|
||||
|
||||
|
|
@ -165,7 +167,7 @@ export default function useTextInputController(elementX: Ref) {
|
|||
switchSide(side)
|
||||
side = "left"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
if (winW - elementX > 230) {
|
||||
|
|
@ -173,7 +175,7 @@ export default function useTextInputController(elementX: Ref) {
|
|||
side = "right"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<!-- submit button; position: fixed -->
|
||||
<button class="submitButton button" type="submit">Submit</button>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
<!-- back to login button: position: fixed -->
|
||||
|
|
@ -37,21 +37,34 @@
|
|||
import { defineComponent, ref } from "vue";
|
||||
import { useIpc } from "@/modules/ipc";
|
||||
import { authRequest } from '@/modules/message';
|
||||
import { useProfile } from '@/modules/auth';
|
||||
import { invokeLogin } from "@/ipcRend/account";
|
||||
import { Profile } from "@/types";
|
||||
|
||||
export default defineComponent({
|
||||
name: "Login",
|
||||
|
||||
setup() {
|
||||
|
||||
const { post } = useIpc();
|
||||
const { setProfile } = useProfile();
|
||||
|
||||
const usr = ref("");
|
||||
const pwd = ref("");
|
||||
|
||||
// Submit login credentials to the backend.
|
||||
const submitForm = () => {
|
||||
console.log(`Submitting login form: ${usr.value}, ${pwd.value}`)
|
||||
post("client-message", authRequest(false, usr.value, pwd.value))
|
||||
const submitForm = async () => {
|
||||
|
||||
try {
|
||||
const profile = await invokeLogin({
|
||||
email: usr.value,
|
||||
password: pwd.value
|
||||
}) as Profile;
|
||||
|
||||
setProfile(profile);
|
||||
|
||||
} catch(e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
<!-- List of message bubbles. -->
|
||||
<div id="messenger">
|
||||
<Message
|
||||
v-for="message in messages"
|
||||
:message="message[1]"
|
||||
<Message
|
||||
v-for="message in messages"
|
||||
:message="message[1]"
|
||||
:key="message[0]"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -48,25 +48,24 @@ export default defineComponent({
|
|||
|
||||
// Load the message history.
|
||||
if (crimataId === window.localStorage.getItem("last_usr")) {
|
||||
prepMessageView(props.newMessages)
|
||||
prepMessageView(props.newMessages);
|
||||
} else {
|
||||
messages.value.clear()
|
||||
messages.value.clear();
|
||||
}
|
||||
|
||||
// New content listeners.
|
||||
emitter.on('self-message', (message) => updateMessageView(message));
|
||||
window.ipcRenderer.on("render-message", (_e: any, payload: any) => {
|
||||
updateMessageView(payload.message)
|
||||
updateMessageView(payload.message);
|
||||
});
|
||||
|
||||
// Save the usr for next time.
|
||||
window.localStorage.setItem("last_usr", crimataId)
|
||||
window.localStorage.setItem("last_usr", crimataId);
|
||||
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.ipcRenderer.removeAllListeners("render-message");
|
||||
window.ipcRenderer.removeAllListeners("annotate-message");
|
||||
emitter.all.clear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@
|
|||
import { defineComponent, ref } from "vue";
|
||||
import { useIpc } from "@/modules/ipc";
|
||||
import { logoutRequest } from '@/modules/message';
|
||||
import { useProfile } from "@/modules/auth"
|
||||
import { invokeLogout } from "@/ipcRend/account";
|
||||
|
||||
export default defineComponent({
|
||||
name: "Settings",
|
||||
|
|
@ -37,7 +39,9 @@
|
|||
setup() {
|
||||
const toggleSettings = ref(false);
|
||||
|
||||
const { post } = useIpc();
|
||||
const { post, invoke } = useIpc();
|
||||
|
||||
const { clearProfile } = useProfile();
|
||||
|
||||
// Listen for escape key to close settings.
|
||||
const onEscape = (e: any) => {
|
||||
|
|
@ -54,9 +58,17 @@
|
|||
}
|
||||
|
||||
// We ask server to log us out.
|
||||
const onLogout = () => {
|
||||
console.log("Submitting logout request.")
|
||||
post("client-message", logoutRequest())
|
||||
const onLogout = async () => {
|
||||
|
||||
console.log("Submitting logout request.");
|
||||
|
||||
try {
|
||||
clearProfile();
|
||||
await invokeLogout();
|
||||
} catch(e) {
|
||||
console.log('error')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in a new issue