simplify ipc api
This commit is contained in:
parent
79a1847eda
commit
a9a0eb207f
@ -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({
|
||||
|
@ -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);
|
||||
ipcMain.on(
|
||||
IpcChannels.Credentials,
|
||||
(
|
||||
event: {
|
||||
frameId: number;
|
||||
preventDefault: () => void;
|
||||
reply: (channel: string, ...args: any) => void;
|
||||
sender: WebContents;
|
||||
},
|
||||
...args: any
|
||||
) => {
|
||||
event.reply(IpcChannels.Pong, args);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
init,
|
||||
};
|
||||
);
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
const enum IpcRendererMessages {
|
||||
const enum IpcChannels {
|
||||
Credentials = 'CREDENTIALS',
|
||||
}
|
||||
|
||||
const enum IpcMainMessages {
|
||||
Pong = 'PONG',
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user