95 lines
1.7 KiB
TypeScript
95 lines
1.7 KiB
TypeScript
|
|
import useIpc from "@/render/composables/useIpcRend";
|
|
import * as rendererListeners from "./listeners";
|
|
|
|
const { post, invoke } = useIpc();
|
|
|
|
/**
|
|
*
|
|
* Account and auth related endpoints
|
|
*
|
|
*/
|
|
|
|
|
|
export const invokeLogin = async (
|
|
payload: AccountCredentials
|
|
): Promise<Profile | Error> => (
|
|
await invoke('invoke-account-login', payload)
|
|
);
|
|
|
|
export const invokeLogout = async (): Promise<void> => (
|
|
await invoke("invoke-account-logout", null)
|
|
);
|
|
|
|
/**
|
|
*
|
|
* Audio endpoints
|
|
*
|
|
*/
|
|
|
|
export const postAudioChunk = (chunk: ArrayBuffer): void => (
|
|
post("post-audio-collect", chunk)
|
|
);
|
|
|
|
export const invokeReturnAudio = async (): Promise<ArrayBuffer[] | Error> => (
|
|
await invoke("invoke-audio-flush", null)
|
|
);
|
|
|
|
/**
|
|
*
|
|
* Crimata Platform (session) endpoints
|
|
*
|
|
*/
|
|
|
|
export const postMessage = (payload: Raw | PlatformRequest): void => (
|
|
post('post-session-send', payload)
|
|
);
|
|
|
|
export const postAppMount = (): void => (
|
|
post('post-app-mount', null)
|
|
);
|
|
|
|
/**
|
|
*
|
|
* Nav bar endpoints
|
|
*
|
|
*/
|
|
|
|
export const postNavBar = (payload: string): void => (
|
|
post('post-nav-bar', payload)
|
|
);
|
|
|
|
/**
|
|
*
|
|
* Window focus endpoint
|
|
*
|
|
*/
|
|
|
|
export const postWindowFocus = (payload: { isFocused: boolean }): void => (
|
|
post('post-window-focus', payload)
|
|
);
|
|
|
|
/**
|
|
*
|
|
* Ipc Renderer Listeners
|
|
*
|
|
*/
|
|
|
|
let ipcListeners: IPCListeners = {};
|
|
|
|
export const initIpcRendererListeners = () => {
|
|
for (const [key, listener] of Object.entries(rendererListeners)) {
|
|
if (!(key in ipcListeners)) {
|
|
ipcListeners[key] = listener;
|
|
listener.listen();
|
|
}
|
|
}
|
|
};
|
|
|
|
export const removeListeners = () => {
|
|
for (const [key, listener] of Object.entries(rendererListeners)) {
|
|
listener.remove();
|
|
}
|
|
ipcListeners = {};
|
|
};
|
|
|