electron-push-receiver
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
Why and how ?
See this blog post.
Install
npm i -S electron-push-receiver
Usage
- In
main.js
/ in main process :
const { setup: setupPushReceiver } = require('electron-push-receiver');
setupPushReceiver(mainWindow.webContents);
import { ipcRenderer } from 'electron';
import {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED as ON_NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} from 'electron-push-receiver/src/constants';
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) =>
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) =>
ipcRenderer.on(TOKEN_UPDATED, (_, token) =>
ipcRenderer.on(ON_NOTIFICATION_RECEIVED, (_, notification) =>
ipcRenderer.send(START_NOTIFICATION_SERVICE, {
firebase: {
apiKey: "XXxxXxX0x0x-Xxxx0-X0Xxxxx_0xxXx_XX0xXxX",
appID: "1:000000000000:android:xxx0xxxx0000x000xxx000",
projectID: "the-app-name"
},
vapidKey: ''
});
Example
Thanks to CydeSwype, you can find an example project here.