Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsenpeder authored Aug 28, 2018
1 parent 3314e1c commit aa316c1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
// To be sure that start is called only once
let started = false;

let listener = false;

// To be call from the main process
function setup(webContents) {
// Will be called by the renderer process
Expand Down Expand Up @@ -50,7 +52,7 @@ function setup(webContents) {
webContents.send(TOKEN_UPDATED, credentials.fcm.token);
}
// Listen for GCM/FCM notifications
await listen(Object.assign({}, credentials, { persistentIds }), onNotification(webContents));
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);
} catch (e) {
Expand All @@ -61,6 +63,15 @@ 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 }) => {
Expand Down

0 comments on commit aa316c1

Please sign in to comment.