MatthieuLemoine / electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
191 stars 62 forks source link

Initializing electron-push-receiver component without a main window #14

Open arun-nfactorial opened 6 years ago

arun-nfactorial commented 6 years ago

Hi Matthieu,

I have an app that sits in the background and pops up windows at random intervals. I have it running in the system tray as well. However, there is no persistent window for the app.

In such a case, am struggling to figure out how to use this:

// Initialize electron-push-receiver component. Should be called before 'did-finish-load' setupPushReceiver(mainWindow.webContents);

I would like to push notifications even without a mainWindow being open. Can that be done?

Regards, Arun

MatthieuLemoine commented 6 years ago

@arun-nfactorial well you have two ways of doing that :

arun-nfactorial commented 6 years ago

Thanks for the quick response.

I am trying with creating a defaultWindow initially to see whether this works. I first tried out the demo code provided on a linux machine and that worked perfectly.

When I try it using my code on a Windows machine the service is started successfully. I also have the token, but when I hit that with Postman, the notification window never pops up. Is there any known issue on a Windows machine?

By the way, I went through your full blog post and what you did was incredible. The patience to do all that!:) So a big thanks to you!

Regards, Arun

On Mon, Feb 26, 2018 at 2:50 PM, Matthieu Lemoine notifications@github.com wrote:

@arun-nfactorial https://github.com/arun-nfactorial well you have two ways of doing that :

  • Easy: Pass a fake webContents in setupPushReceiver : you just need a object with a send function which will receive the notifications
  • Harder: Use push-receiver https://github.com/MatthieuLemoine/push-receiver directly. electron-push-receiver is just a convenient wrapper around push-receiver. You'll have to handle the credentials storage yourself.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368437196, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpkLHDp9NSQOKWgiN1W_zMfroo-tlks5tYndbgaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

MatthieuLemoine commented 6 years ago

@arun-nfactorial Never tried on Windows. Did you receive the notification and it's just a display issue or the notification is never received ?

arun-nfactorial commented 6 years ago

Thon Postman I get a success response. It's just that I don't see it on the windows machine.

A couple of other questions:

A) when you said an empty Webcontents, would I still need to create a dummy window or just a Webcontents object is sufficient?

B) I see that the service is started in the renderer. Since I have multiple pop-ups in my app coming up at random times, I am assuming the service will get started each time a new window pops up. How can I limit that to just one service being started. Can I start the service in main.js itself?

Thanks, Arun

On 26-Feb-2018 16:15, "Matthieu Lemoine" notifications@github.com wrote:

@arun-nfactorial https://github.com/arun-nfactorial Never tried on Windows. Did you receive the notification and it's just a display issue or the notification is never received ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368460603, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpnshmr_tWN9IRAgH2jXAxKMCwT-vks5tYosygaJpZM4SS0ME .

MatthieuLemoine commented 6 years ago

A) Yes. Something like :

const webContents = { send : (event, data) => doSomething(event, data) }

B) You can start from the main process using ipcMain.send(START_NOTIFICATION_SERVICE, senderId);. You dont' have to start the service for each windows. You can start it only once in the main process

arun-nfactorial commented 6 years ago

Awesome. Thanks a lot. Shall try that and let you know. Shall also run the demo on the windows machine and let you know if it works since that will tell us whether it is a windows issue that needs resolving or a quirk of my implementation.

Regards, Arun

On 26-Feb-2018 16:57, "Matthieu Lemoine" notifications@github.com wrote:

A) Yes. Something like :

const webContents = { send : (event, data) => doSomething(event, data) }

B) You can start from the main process using ipcMain.send(START_NOTIFICATION_SERVICE, senderId);. You dont' have to start the service for each windows. You can start it only once in the main process

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368470869, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpggmxR_ga5z3WBshgUZ8lS5NbhUiks5tYpUngaJpZM4SS0ME .

arun-nfactorial commented 6 years ago

Hi Matthieu,

I tried the demo code on a Windows machine. The popup never comes up, even though I get a Status 200 using Postman.

Regards, Arun

On Mon, Feb 26, 2018 at 4:59 PM, Arun Krishnan <arun@nfactorialanalytics.com

wrote:

Awesome. Thanks a lot. Shall try that and let you know. Shall also run the demo on the windows machine and let you know if it works since that will tell us whether it is a windows issue that needs resolving or a quirk of my implementation.

Regards, Arun

On 26-Feb-2018 16:57, "Matthieu Lemoine" notifications@github.com wrote:

A) Yes. Something like :

const webContents = { send : (event, data) => doSomething(event, data) }

B) You can start from the main process using ipcMain.send(START_NOTIFICATION_SERVICE, senderId);. You dont' have to start the service for each windows. You can start it only once in the main process

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368470869, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpggmxR_ga5z3WBshgUZ8lS5NbhUiks5tYpUngaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

MatthieuLemoine commented 6 years ago

@arun-nfactorial A 200 doesn't mean that the notification was delivered. It's an async operation. A 200 only means that the device token & the server key is valid.

arun-nfactorial commented 6 years ago

Got it. I am on Windows 8.1.

What I noticed is, it never receives the notification, that is never does a console.log from within ipcRenderer.on(NOTIFICATION_RECEIVED, ...

Any ideas as to why that might be?

Regards, Arun

On Mon, Feb 26, 2018 at 10:38 PM, Matthieu Lemoine <notifications@github.com

wrote:

@arun-nfactorial https://github.com/arun-nfactorial A 200 doesn't mean that the notification was delivered. It's an async operation. A 200 only means that the device token & the server key is valid.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368574534, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpnlRKVdwQcpsiQIXzCUpqHj19dEpks5tYuUMgaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

arun-nfactorial commented 6 years ago

A quick update.

The push notification is received on a Windows 10 machine. So looks like a Windows 8 issue.

Regards, Arun

On Mon, Feb 26, 2018 at 10:48 PM, Arun Krishnan < arun@nfactorialanalytics.com> wrote:

Got it. I am on Windows 8.1.

What I noticed is, it never receives the notification, that is never does a console.log from within ipcRenderer.on(NOTIFICATION_RECEIVED, ...

Any ideas as to why that might be?

Regards, Arun

On Mon, Feb 26, 2018 at 10:38 PM, Matthieu Lemoine < notifications@github.com> wrote:

@arun-nfactorial https://github.com/arun-nfactorial A 200 doesn't mean that the notification was delivered. It's an async operation. A 200 only means that the device token & the server key is valid.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368574534, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpnlRKVdwQcpsiQIXzCUpqHj19dEpks5tYuUMgaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

arun-nfactorial commented 6 years ago

Hi Mathieu,

I tried to do this in the main process but get an ipcMain.send is not a function error.

I tried Webcontents.send but I am not getting a service registered message with the token.

Your thoughts would be very helpful.

Thanks, Arun

On Mon, Feb 26, 2018 at 4:57 PM, Matthieu Lemoine notifications@github.com wrote:

A) Yes. Something like :

const webContents = { send : (event, data) => doSomething(event, data) }

B) You can start from the main process using ipcMain.send(START_NOTIFICATION_SERVICE, senderId);. You dont' have to start the service for each windows. You can start it only once in the main process

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368470869, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpggmxR_ga5z3WBshgUZ8lS5NbhUiks5tYpUngaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

arun-nfactorial commented 6 years ago

Also,

Once I start the service in the main process, should the listeners for the different notifications still be in renderer.js? Or can they also be moved to main.js.

If they can be moved, would that be ipcMain.on(NOTIFICATION_RECEIVED etc?

Regards, Arun

On Tue, Feb 27, 2018 at 2:45 PM, Arun Krishnan <arun@nfactorialanalytics.com

wrote:

Hi Mathieu,

I tried to do this in the main process but get an ipcMain.send is not a function error.

I tried Webcontents.send but I am not getting a service registered message with the token.

Your thoughts would be very helpful.

Thanks, Arun

On Mon, Feb 26, 2018 at 4:57 PM, Matthieu Lemoine < notifications@github.com> wrote:

A) Yes. Something like :

const webContents = { send : (event, data) => doSomething(event, data) }

B) You can start from the main process using ipcMain.send(START_NOTIFICATION_SERVICE, senderId);. You dont' have to start the service for each windows. You can start it only once in the main process

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MatthieuLemoine/electron-push-receiver/issues/14#issuecomment-368470869, or mute the thread https://github.com/notifications/unsubscribe-auth/AJvnpggmxR_ga5z3WBshgUZ8lS5NbhUiks5tYpUngaJpZM4SS0ME .

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

-- Arun Krishnan, Ph.D Founder & CEO, nFactorial Analytical Sciences,

Email: arun@nfactorialanalytics.com Phone: +91 9880007615 URL: http://www.nfactorialanalytics.com

n!Gage, n!Factorial’s real-time employee engagement feedback platform http://bit.ly/Intro2nGage, helps managers listen, understand and act upon employee feedback that leads to great employee experiences and ultimately, deeper engagement. This first-of-its-kind-in-India-platform uses analytics to provide real-time intervention analysis, trends, predictive analysis and much more. Winner of TechHR’s 2016 Spotlight award https://www.peoplematters.in/article/hr-technology/spotlight-award-winners-2016-13817, the platform is in use in several large corporations across multiple industries.

rajeevverma076 commented 6 years ago

Hello @MatthieuLemoine,

I'm using electron-push-receiver plugin for fcm push notification in react js with electron js. Sometime push notification working with release build with windows 7 and sometime it's not working. Windows 10 its not working but i'm getting token in all platform but not receiving notification.

Please suggest me what i need to do in this cases.

I truly appreciate your time and effort

Thanks Rajeev

bvallier commented 5 years ago

I can confirm that the push notification is received but the notification doesn't flash.

As a workaround, within the ipcRenderer.on(NOTIFICATION_RECEIVED, (__, serverNotificationPayload) function, I send the serverNotificationPayload to the main.js process via ipcRenderer.send('notification_received', serverNotificationPayload) which is picked up by ipcMain.on("notification_received", (event, arg)

I then determine the OS and pass in the arg to node-notifier, another library. 😬

This isn't ideal, but handled my issue for the time-being.

MatthieuLemoine commented 5 years ago

So it's an issue with electron's Notification API ?

bvallier commented 5 years ago

I tried to use their API directly, but it didn't work for me, so yes, i think so. My understanding is that it's experimental:

https://electronjs.org/docs/api/notification#new-notificationoptions-experimental

There's also this:

https://electronjs.org/docs/tutorial/notifications

MatthieuLemoine commented 5 years ago

There are requirements depending on the Windows version https://electronjs.org/docs/tutorial/notifications#windows