Use
electron-push-receiver
npm install electron-push-receiverconst PushReceiver = require('electron-push-receiver');
app.whenReady().then(() => {
createWindow();
PushReceiver.setup(webContents, null, true);
webContents.on('push-receiver-message', (event, message) => {
new Notification({ title: message.notification.title, body: message.notification.body }).show();
app.dock.setBadge('1'); // Update badge
});
});:info:
You must include your FCM credentials.json from Firebase.
If you control your backend, use WebSockets:
Use ws client inside Electron:
const WebSocket = require('ws');
const socket = new WebSocket('wss://your-server.com');
socket.onmessage = (msg) => {
const data = JSON.parse(msg.data);
new Notification({ title: 'New Message', body: data.text }).show();
app.dock.setBadge('1'); // Or increment
};Works offline and cross-platform.