electron-push-receiver icon indicating copy to clipboard operation
electron-push-receiver copied to clipboard

Initializing electron-push-receiver component without a main window

Open arun-nfactorial opened this issue 7 years ago • 17 comments

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

arun-nfactorial avatar Feb 26 '18 08:02 arun-nfactorial

@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 directly. electron-push-receiver is just a convenient wrapper around push-receiver. You'll have to handle the credentials storage yourself.

MatthieuLemoine avatar Feb 26 '18 09:02 MatthieuLemoine

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 [email protected] 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: [email protected] 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 avatar Feb 26 '18 10:02 arun-nfactorial

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

MatthieuLemoine avatar Feb 26 '18 10:02 MatthieuLemoine

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" [email protected] 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 .

arun-nfactorial avatar Feb 26 '18 11:02 arun-nfactorial

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

MatthieuLemoine avatar Feb 26 '18 11:02 MatthieuLemoine

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" [email protected] 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 avatar Feb 26 '18 11:02 arun-nfactorial

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 <[email protected]

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" [email protected] 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: [email protected] 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 avatar Feb 26 '18 16:02 arun-nfactorial

@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.

MatthieuLemoine avatar Feb 26 '18 17:02 MatthieuLemoine

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 <[email protected]

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: [email protected] 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 avatar Feb 26 '18 17:02 arun-nfactorial

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 < [email protected]> 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 < [email protected]> 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: [email protected] 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: [email protected] 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 avatar Feb 27 '18 06:02 arun-nfactorial

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 [email protected] 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: [email protected] 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 avatar Feb 27 '18 09:02 arun-nfactorial

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 <[email protected]

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 < [email protected]> 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: [email protected] 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: [email protected] 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 avatar Feb 27 '18 09:02 arun-nfactorial

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

rajeevverma076 avatar Mar 21 '18 16:03 rajeevverma076

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.

bvallier avatar Nov 30 '18 14:11 bvallier

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

MatthieuLemoine avatar Nov 30 '18 14:11 MatthieuLemoine

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

bvallier avatar Nov 30 '18 14:11 bvallier

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

MatthieuLemoine avatar Nov 30 '18 14:11 MatthieuLemoine