diff --git a/package.json b/package.json index b76347a..1e51015 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "MIT", "types": "src/electron-push-receiver.d.ts", "dependencies": { - "electron-config": "^1.0.0", + "electron-store": "^2.0.0", "push-receiver": "^2.0.2" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index 251fb34..6e79a71 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ const { register, listen } = require('push-receiver'); const { ipcMain } = require('electron'); -const Config = require('electron-config'); +const Store = require('electron-store'); const { START_NOTIFICATION_SERVICE, NOTIFICATION_SERVICE_STARTED, @@ -9,7 +9,7 @@ const { TOKEN_UPDATED, } = require('./constants'); -const config = new Config(); +const store = new Store(); module.exports = { START_NOTIFICATION_SERVICE, @@ -28,9 +28,9 @@ function setup(webContents) { // Will be called by the renderer process ipcMain.on(START_NOTIFICATION_SERVICE, async (_, senderId) => { // Retrieve saved credentials - let credentials = config.get('credentials'); + let credentials = store.get('credentials'); // Retrieve saved senderId - const savedSenderId = config.get('senderId'); + const savedSenderId = store.get('senderId'); if (started) { webContents.send(NOTIFICATION_SERVICE_STARTED, (credentials.fcm || {}).token); return; @@ -38,14 +38,14 @@ function setup(webContents) { started = true; try { // Retrieve saved persistentId : avoid receiving all already received notifications on start - const persistentIds = config.get('persistentIds') || []; + const persistentIds = store.get('persistentIds') || []; // Register if no credentials or if senderId has changed if (!credentials || savedSenderId !== senderId) { credentials = await register(senderId); // Save credentials for later use - config.set('credentials', credentials); + store.set('credentials', credentials); // Save senderId - config.set('senderId', senderId); + store.set('senderId', senderId); // Notify the renderer process that the FCM token has changed webContents.send(TOKEN_UPDATED, credentials.fcm.token); } @@ -64,9 +64,9 @@ function setup(webContents) { // Will be called on new notification function onNotification(webContents) { return ({ notification, persistentId }) => { - const persistentIds = config.get('persistentIds') || []; + const persistentIds = store.get('persistentIds') || []; // Update persistentId - config.set('persistentIds', [...persistentIds, persistentId]); + store.set('persistentIds', [...persistentIds, persistentId]); // Notify the renderer process that a new notification has been received webContents.send(NOTIFICATION_RECEIVED, notification); };