diff --git a/src/index.js b/src/index.js index b3a43b5..40d4401 100644 --- a/src/index.js +++ b/src/index.js @@ -33,8 +33,8 @@ function setup(webContents) { let credentials = config.get('credentials'); // Retrieve saved senderId const savedSenderId = config.get('senderId'); - if (started) { - webContents.send(NOTIFICATION_SERVICE_STARTED, (credentials.fcm || {}).token); + if (started && listener) { + webContents.send(NOTIFICATION_SERVICE_STARTED, (credentials.fcm || {}).token, listener); return; } started = true; @@ -54,7 +54,7 @@ function setup(webContents) { // Listen for GCM/FCM notifications listener = await listen(Object.assign({}, credentials, { persistentIds }), onNotification(webContents)); // Notify the renderer process that we are listening for notifications - webContents.send(NOTIFICATION_SERVICE_STARTED, credentials.fcm.token); + webContents.send(NOTIFICATION_SERVICE_STARTED, credentials.fcm.token, listener); } catch (e) { console.error('PUSH_RECEIVER:::Error while starting the service', e); // Forward error to the renderer process @@ -63,15 +63,6 @@ function setup(webContents) { }); } -function destroy() { - if (started && listener) { - started = false; - listener.destroy(); - } - - return; -} - // Will be called on new notification function onNotification(webContents) { return ({ notification, persistentId }) => {