The Wayback Machine - https://web.archive.org/web/20200228142012/https://github.com/MatthieuLemoine/electron-push-receiver
Skip to content
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
JavaScript
Branch: master
Clone or download

Latest commit

MatthieuLemoine Merge pull request #52 from MatthieuLemoine/dependabot/npm_and_yarn/l…
…odash-4.17.15

⬆️ Bump lodash from 4.17.4 to 4.17.15
Latest commit 3a1bbdb Nov 4, 2019

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix object destroyed when darwin apps are on hold in memory Aug 19, 2019
.eslintignore 🎉 Init Oct 25, 2017
.eslintrc 🎉 Init Oct 25, 2017
.gitignore
.nvmrc 🎉 Init Oct 25, 2017
LICENSE 📄 Add LICENSE Nov 9, 2017
README.md 📝 Add link to an example project Dec 4, 2017
package.json 🔖 v2.1.3 Aug 23, 2019
yarn.lock ⬆️ Bump lodash from 4.17.4 to 4.17.15 Nov 2, 2019

README.md

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');

// Call it before 'did-finish-load' with mainWindow a reference to your window
setupPushReceiver(mainWindow.webContents);
  • In renderer process :
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';

// Listen for service successfully started
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) => // do something);
// Handle notification errors
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) => // do something);
// Send FCM token to backend
ipcRenderer.on(TOKEN_UPDATED, (_, token) => // Send token);
// Display notification
ipcRenderer.on(ON_NOTIFICATION_RECEIVED, (_, notification) => // display notification);
// Start service
ipcRenderer.send(START_NOTIFICATION_SERVICE, senderId);

Example

Thanks to CydeSwype, you can find an example project here.

You can’t perform that action at this time.