add login, register, and auth
This commit is contained in:
parent
9d64ffcb41
commit
29f6b759f8
17 changed files with 436 additions and 55 deletions
54
src/modules/ipc.ts
Normal file
54
src/modules/ipc.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { ref, computed } from 'vue'
|
||||
|
||||
export const useIpc = (endpoint: string) => {
|
||||
const data = ref();
|
||||
const loading = ref(false);
|
||||
const error = ref();
|
||||
const listener = ref(false);
|
||||
|
||||
const errorMessage = computed(() => {
|
||||
console.log('ERROR', error.value);
|
||||
if (error.value) {
|
||||
return error.value.message
|
||||
}
|
||||
})
|
||||
|
||||
const send = (payload?: Record<string, any>, callback?: (arg: any) => void) => {
|
||||
loading.value = true;
|
||||
error.value = undefined;
|
||||
|
||||
window.ipcRenderer.on(endpoint + '-reply', (event: any, arg: any | Error) => {
|
||||
if (arg instanceof Error) {
|
||||
error.value = arg;
|
||||
throw arg;
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(arg);
|
||||
}
|
||||
data.value = arg;
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
window.ipcRenderer.send(endpoint, payload);
|
||||
};
|
||||
|
||||
const onEvent = (callback: (event: any, arg: any) => void) => {
|
||||
listener.value = true;
|
||||
window.ipcRenderer.on(endpoint, callback);
|
||||
};
|
||||
|
||||
const post = (payload?: Record<string, any>) => {
|
||||
window.postMessage({
|
||||
myTypeField: endpoint,
|
||||
message: payload
|
||||
}, '*')
|
||||
};
|
||||
|
||||
return {
|
||||
loading,
|
||||
data,
|
||||
error,
|
||||
errorMessage,
|
||||
send
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue