电子推收器
一个将 Web Push 支持带入的模块 电子 允许它从Firebase Cloud Massaging(FCM)接收通知.
此特定的分叉用途 阿拉克纳FCM 用于支持 FCM 新的 HTTP v1 API
安装
npm i -S @cuj1559/electron-push-receiver
点击 这里 查看 npm 页面.
使用量
- 单位
main.js/ 在主要过程中:
const { setup: setupPushReceiver } = require('@cuj1559/electron-push-receiver');
// Call it before 'did-finish-load' with mainWindow a reference to your window
setupPushReceiver(mainWindow.webContents);
- 在渲染工艺中:
import { ipcRenderer } from 'electron';
import {
START_NOTIFICATION_SERVICE,
NOTIFICATION_SERVICE_STARTED,
NOTIFICATION_SERVICE_RESTARTED,
NOTIFICATION_SERVICE_ERROR,
NOTIFICATION_RECEIVED as ON_NOTIFICATION_RECEIVED,
TOKEN_UPDATED,
} from '@cuj1559/electron-push-receiver/src/constants';
// Listen for service successfully started
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) => { /* do something */ });
// Listen for service restart due to server connection failure
ipcRenderer.on(NOTIFICATION_SERVICE_RESTARTED, (_, token) => { /* do something */ });
// Handle notification errors
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) => { /* handle error */ });
// Send FCM token to backend
ipcRenderer.on(TOKEN_UPDATED, (_, token) => { /* check or save token */ });
// Display notification
ipcRenderer.on(ON_NOTIFICATION_RECEIVED, (_, notification) => { /* notification data received */ });
// Start service
ipcRenderer.send(START_NOTIFICATION_SERVICE, appID, projectID, apiKey, vapidKey);