A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
See this blog post.
npm i -S electron-push-receiver
- In
main.js/ in main process :
const{setup: setupPushReceiver}=require('electron-push-receiver');// Call it before 'did-finish-load' with mainWindow a reference to your windowsetupPushReceiver(mainWindow.webContents);- In renderer process :
import{ipcRenderer}from'electron';import{START_NOTIFICATION_SERVICE,NOTIFICATION_SERVICE_STARTED,NOTIFICATION_SERVICE_ERROR,NOTIFICATION_RECEIVEDasON_NOTIFICATION_RECEIVED,TOKEN_UPDATED,}from'electron-push-receiver/src/constants';// Listen for service successfully startedipcRenderer.on(NOTIFICATION_SERVICE_STARTED,(_,token)=>// do something);// Handle notification errorsipcRenderer.on(NOTIFICATION_SERVICE_ERROR,(_,error)=>// do something);// Send FCM token to backendipcRenderer.on(TOKEN_UPDATED,(_,token)=>// Send token);// Display notificationipcRenderer.on(ON_NOTIFICATION_RECEIVED,(_,notification)=>// display notification);// Start serviceipcRenderer.send(START_NOTIFICATION_SERVICE,senderId);