-
Notifications
You must be signed in to change notification settings - Fork 54
How to send data back to container in electron-react-boilerplate? #25
Comments
notification.on('buttonClicked', (text, buttonIndex, options) => The text variable contains the text of the pressed button and buttonIndex contains its index (0, 1, etc) |
@cgerikj sorry, but I think you haven't understood my point. What I want is something like this: onPress() {
notifier('reminders', {
message: 'Event begins in 10 minutes',
icon: 'http://cl.ly/J49B/3951818241085781941.png',
buttons: ['Dismiss', 'Snooze'],
duration: 30000
})
.then((buttonIndex) => {
// Now container knows what button is.
});
} Thanks. |
Your container can call onPress() {
var notification = notifier('reminders', {
message: 'Event begins in 10 minutes',
icon: 'http://cl.ly/J49B/3951818241085781941.png',
buttons: ['Dismiss', 'Snooze'],
duration: 30000
})
notification.on('buttonClicked', (text, buttonIndex, options) => {
this.setState({ buttonIndex }) // setState so you can use `buttonIndex` in `render()`
})
} Does this answer your question? |
@blainesch No :( I'm using this example: https://github.com/Slapbox/electron-notification-demo Could anyone tag Slapbox into this thread ? |
Just an FYI that notifications currently do not work in a packaged version of electron-react-boilerplate. I'm hoping to find a solution for this, but it may be quite a while Edit: React-Electron-Boilerplate works just fine with this repo. You must add the dependency to your SECOND What you need to do is first:
You may already know this, in Electron there are two processes, the In short, what you need to do is communicate from the See the documentation for ipcRenderer and ipcMain Main.js
Renderer side - Sending a request to execute the code to create a notification (See above)
Renderer side - Receiving the button clicked and taking an action
I hope this helps. Let me know if anything is unclear, or possibly broken, as the above is a modified version of my code and not tested as written. |
@slapbox
I will really appreciate if you could make another example :( |
Sorry, missed an important point. At the beginning of your files you'll need to import the ipcRenderer or ipcMain as they are used. I also noticed I made a mistake in my code example: change: I think that should get you up and running! Let me know if it doesn't. |
In electron-react-boilerplate, I follow your code to this:
In my Container, I want to press a button, then showing the Notification, here is the code:
How can my container know which buttons I pressed ?
Thank you!
The text was updated successfully, but these errors were encountered: