aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/todos/preload.js
blob: 6e38a2ef3a934fba8b99e5f4735f3a17f9afebdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { ipcRenderer } from 'electron';
import { IPC } from './constants';

const debug = require('debug')('Franz:feature:todos:preload');

debug('Preloading Todos Webview');

let hostMessageListener = () => {};

window.franz = {
  onInitialize(ipcHostMessageListener) {
    hostMessageListener = ipcHostMessageListener;
    ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, { action: 'todos:initialized' });
  },
  sendToHost(message) {
    ipcRenderer.sendToHost(IPC.TODOS_CLIENT_CHANNEL, message);
  },
};

ipcRenderer.on(IPC.TODOS_HOST_CHANNEL, (event, message) => {
  debug('Received host message', event, message);
  hostMessageListener(message);
});