simplify ipc api

This commit is contained in:
Xymorot 2019-06-19 00:15:16 +02:00
parent 79a1847eda
commit a9a0eb207f
4 changed files with 19 additions and 20 deletions

View File

@ -1,13 +1,12 @@
import { app, BrowserWindow } from 'electron';
import api from './main/services/api';
import './main/services/api';
import session from './main/services/session';
let mainWindow: Electron.BrowserWindow;
async function createWindow() {
session.init();
api.init();
// Create the browser window.
mainWindow = new BrowserWindow({

View File

@ -1,14 +1,17 @@
import { ipcMain } from 'electron';
import WebContents = Electron.WebContents;
function init() {
ipcMain.on(
IpcRendererMessages.Credentials,
(event: any, arg: ICredentials) => {
event.reply(IpcMainMessages.Pong, arg);
}
);
}
export default {
init,
};
ipcMain.on(
IpcChannels.Credentials,
(
event: {
frameId: number;
preventDefault: () => void;
reply: (channel: string, ...args: any) => void;
sender: WebContents;
},
...args: any
) => {
event.reply(IpcChannels.Pong, args);
}
);

View File

@ -1,10 +1,10 @@
import { ipcRenderer } from 'electron';
function sendCredentials(credentials: ICredentials) {
ipcRenderer.send(IpcRendererMessages.Credentials, credentials);
ipcRenderer.send(IpcChannels.Credentials, credentials);
}
ipcRenderer.on(IpcMainMessages.Pong, (...args: any) => {
ipcRenderer.on(IpcChannels.Pong, (event, ...args: any) => {
console.log(args);
});

View File

@ -1,8 +1,5 @@
const enum IpcRendererMessages {
const enum IpcChannels {
Credentials = 'CREDENTIALS',
}
const enum IpcMainMessages {
Pong = 'PONG',
}