33 lines
941 B
TypeScript
33 lines
941 B
TypeScript
import { ipcMain } from 'electron';
|
|
import { isLoggedIn, login } from '../services/nhentai-crawler';
|
|
|
|
const ipcServer: IIpcServer = {
|
|
answer: (channel: IpcChannels, handler: (data?: any) => Promise<any>): void => {
|
|
ipcMain.on(channel, (event: IpcEvent, payload: IIpcPayload) => {
|
|
handler(payload.data)
|
|
.then((result: any) => {
|
|
const response: IIpcResponse = {
|
|
success: true,
|
|
data: result,
|
|
};
|
|
event.reply(channel, response);
|
|
})
|
|
.catch((reason: any) => {
|
|
const response: IIpcResponse = {
|
|
success: false,
|
|
error: reason.toString(),
|
|
};
|
|
event.reply(channel, response);
|
|
});
|
|
});
|
|
},
|
|
};
|
|
|
|
ipcServer.answer(IpcChannels.LOGIN, (credentials: ICredentials) => {
|
|
return login(credentials.name, credentials.password);
|
|
});
|
|
|
|
ipcServer.answer(IpcChannels.LOGGED_IN, () => {
|
|
return isLoggedIn();
|
|
});
|