simplify ipc api
This commit is contained in:
parent
79a1847eda
commit
a9a0eb207f
@ -1,13 +1,12 @@
|
|||||||
import { app, BrowserWindow } from 'electron';
|
import { app, BrowserWindow } from 'electron';
|
||||||
|
|
||||||
import api from './main/services/api';
|
import './main/services/api';
|
||||||
import session from './main/services/session';
|
import session from './main/services/session';
|
||||||
|
|
||||||
let mainWindow: Electron.BrowserWindow;
|
let mainWindow: Electron.BrowserWindow;
|
||||||
|
|
||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
session.init();
|
session.init();
|
||||||
api.init();
|
|
||||||
|
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { ipcMain } from 'electron';
|
import { ipcMain } from 'electron';
|
||||||
|
import WebContents = Electron.WebContents;
|
||||||
|
|
||||||
function init() {
|
ipcMain.on(
|
||||||
ipcMain.on(
|
IpcChannels.Credentials,
|
||||||
IpcRendererMessages.Credentials,
|
(
|
||||||
(event: any, arg: ICredentials) => {
|
event: {
|
||||||
event.reply(IpcMainMessages.Pong, arg);
|
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';
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
function sendCredentials(credentials: ICredentials) {
|
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);
|
console.log(args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
const enum IpcRendererMessages {
|
const enum IpcChannels {
|
||||||
Credentials = 'CREDENTIALS',
|
Credentials = 'CREDENTIALS',
|
||||||
}
|
|
||||||
|
|
||||||
const enum IpcMainMessages {
|
|
||||||
Pong = 'PONG',
|
Pong = 'PONG',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user