Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications on Windows #262

Closed
Subash opened this issue May 7, 2014 · 49 comments
Closed

Notifications on Windows #262

Subash opened this issue May 7, 2014 · 49 comments

Comments

@Subash
Copy link

Subash commented May 7, 2014

webkitNotifications api seems to be implemented in mac build but not in windows build.

@island205
Copy link

How about is this now?

@zcbenz zcbenz changed the title Notifications Notifications on Windows Jun 11, 2014
@zcbenz
Copy link
Member

zcbenz commented Jun 11, 2014

Since there is no standard notification API on Windows <= 7, the implementation will be much more complicated than on Linux and Mac, so it may not be finished recently.

@island205
Copy link

Get it, tks.

@Subash
Copy link
Author

Subash commented Jun 11, 2014

How about implementing skip taskbar and show inactive apis from node-webkit that would make creating notification windows easy.

@Subash
Copy link
Author

Subash commented Aug 5, 2014

@zcbenz
Implemented in node-webkit
nwjs/nw.js@39e0731

@FLasH3r
Copy link

FLasH3r commented May 2, 2015

+1

@shripathee
Copy link

Any roadmap for resolution of this issue? This is a pretty big deterrent for using Electron.

@JonathanPierce
Copy link

Agreed. Native notifications are a big deal, they are even advertised on the Electron homepage. The fact that they don't work on Windows is hugely disappointing.

@anaisbetts
Copy link
Contributor

I mean, it's hugely disappointing that Windows makes it a total PITA to implement notifications, sooooooooooo

@Glavin001
Copy link

What about using the Windows Toast Notifications support from Node-Notifier?

@anaisbetts
Copy link
Contributor

@Glavin001 You have to create a dummy shortcut in users' start menus to use that, it's a pretty big drawback

@Glavin001
Copy link

@paulcbetts Oh wow. Thanks for letting me know. Bummer.

I am usually not a Windows user, let alone Windows app developer, however I recently won a Microsoft Surface and realize I really miss not being able to receive SMS notifications on my Surface from my iPhone, like my Macbook does. I hope to develop this project with Electron, although this lack of Windows notification support puts a speed bump in that plan.

@hleumas
Copy link

hleumas commented Jun 23, 2015

Hi guys,

my app is using web notifications but it does not work on windows (because of this ticket). Can I shim notification API somehow, so it does tray bubble instead?

The thing is, I can't change the clientside code, cause I am loading it from public url. The app is just packaged webapp.

However, if I were able to shim Notification API from the main script, it would be awesome. Do you know whether something like that is possible?

Thanks a lot!

@iSuslov
Copy link

iSuslov commented Jun 29, 2015

+1 for this. Any workaround without end-user troubles?

@hleumas
Copy link

hleumas commented Jun 29, 2015

Ok, it works this way:

webContents.executeJavascript(`
  ipc = require('ipc');
  Notification = function(title, options) {
    ipc.send('notify', {title: title, options: options});
  }
  Notification.permission = 'granted'
`

This way I can listen in main thread on notify messages and do whatever I want with them.

@xenyou
Copy link

xenyou commented Jul 10, 2015

+1

@s-a
Copy link

s-a commented Aug 5, 2015

Hi,
I am experimenting with a toaster at https://github.com/s-a/electron-toaster.
It aims to work with electron tools and to have an identical look across different platforms.

I tried to design it close the chrome rich text notifications, but i' am not the best designer 😄 Regardless to restrictions and features of different native notification systems we could build something that mimics chrome rich text notifications.

image

So far it fits my needs. If any one is interested. Would be cool to hear your thoughts about this.

@clay-morgan
Copy link

I'm interested in where that is going for sure. This is a definite roadblock to us using Electron at the moment.

@jmesquita
Copy link

@s-a that's nice! but... I am not a windows user but I am assuming it is not able to detect that other notifications are in place and therefore it would be placed on top of other notifications creating a kinda weird user experience? Just asking...

@s-a
Copy link

s-a commented Aug 18, 2015

@jmesquita ty for your feedback. When I remember back I cannot remember such a situation, but in fact you are absolutely right.

@zhenchaoli
Copy link

Not seeing anything with electron.exe

I'm interested to knowing how notification is implemented on Windows 8.1, since it doesn't have a notification center as Win 10..

@zhenchaoli
Copy link

Oh I do see a Notifications section in Settings, they are all enabled though..

@felixrieseberg
Copy link
Member

Hold on, we might have a regression here.

@felixrieseberg
Copy link
Member

Upon inspection, we don't have a regression, but getting 8.1 setup to accept notifications is a bit tricky and the documentation I wrote is not nearly as detailed as it has to be. I'll add some docs there, but in the meantime, here are the important steps:

  • Your app needs a shortcut in the start menu
  • The shortcut needs a the property system.appusermodel.id set to your AppId
  • Your appId needs to be set

The good news: Squirrel handles that all for you.

@zhenchaoli
Copy link

That's weird, I think I'm doing these correctly. My update.exe file verison is '1.2.5.0', I think it's pretty new..

@zhenchaoli
Copy link

Is it possible to test things out with electron.exe?

Here's my attempt at getting notification to work for it:

  1. I downloaded electron from https://github.com/atom/electron/releases
  2. I created a shortcut by 'right click on electron.exe -> create shortcut'
  3. I edited the app UserModelId to com.squirrel.electron.electron (I used the trick here to edit the property: http://winaero.com/blog/how-to-show-more-details-for-shortcuts-in-windows-8-1-windows-8-and-windows-7/)
  4. I dragged the shortcut to windows start menu (literally dragged the shortcut on to the windows start icon at bottom left..)
  5. I clicked open the shortcut from start screen to launch electron.exe
  6. I opened devtool and typed in this:
    electron = require('electron'); electron.remote.app.setAppUserModelId('com.squirrel.electron.electron');
  7. I typed in
    var n = new window.Notification('hi');
  8. I wasn't able to see notification : - |

Is it because by the time I setAppUserModelId it was too late? Does it matter?

@anaisbetts
Copy link
Contributor

@fantasticsid You can't set the app user model ID via remote, you need to call it before you open a window

@felixrieseberg
Copy link
Member

And the shortcut has to be inside the Start Menu folder inside the user's appdir. It's a horrible system (which is why it's no longer in Windows 10), and my documentation isn't great.

Once //build is over, I'll make another pass at the docs and make this stuff more clear.

@zhenchaoli
Copy link

I rebuilt my app to call app.setAppUserModelId before a window is created.

I'm using squirrel.windows to generate installer (noMsi, it generates a Setup.exe).

I did find a shortcut to my app under %APPDATA%/Roaming/Microsoft/Windows/Start Menu/Programs/Myapp/Myapp.lnk, which points to Update.exe

Notification still does not show from my app, I also used dev console to confirm this.

I'm running Windows 8.1 in vmware, if that matters.

At this point just a screenshot of notification working on Windows 8 would make me so much better..

Seriously though does it matter that the lnk file points to squirrel binary?

@zhenchaoli
Copy link

Also according to this https://msdn.microsoft.com/en-us/library/dn449300(v=winembedded.82).aspx

I did not see my app's Application User Model ID listed, perhaps it needs to register during installation, and squirrel somehow did not do that?

@felixrieseberg
Copy link
Member

In addition to all this mess: #4973

@zhenchaoli
Copy link

I'm gonna try 0.35.0 where notification support is first implemented..
Remember the bug where if notification fails brightray crashes? I think there must be something wrong/missing that makes the OS to deny the notification request.

Unfortunately I only have a VM for windows 8 so it's gonna be a PITA to build brightray & electron in the VM.

@rubencodes
Copy link

rubencodes commented Apr 14, 2016

To everyone who might be looking to do notifications in Windows 7:
I had good success using electron-notification-shim in conjunction with electron-toaster.
In my main file, I had:

import { app, BrowserWindow, ipcMain } from 'electron';
import Toaster from 'electron-toaster';
const toaster = new Toaster();

app.on('ready', function () {
    var mainWindow = new BrowserWindow({
        width: 1000,
        height: 600 
    });
    toaster.init(mainWindow);

    // Listen for notification events.
    ipcMain.on('notification-shim', (e, msg) => {
        mainWindow.webContents.executeJavaScript(`
            ipc.send('electron-toaster-message', {
                title: '${msg.title}',
                message: '${msg.options.body}',
                width: 440
            });
        `);
    });
});

And in the browser, I ran:

require('electron-notification-shim')();
ipc = require('electron').ipcRenderer;

(FWIW: I also tried this all using node-notifier with success)
And voila! Thanks for all your hard work guys/gals.
(Note: this doesn't only run when the app is on Windows <= 7; for that you'll need to check the windows version and wrap some of this stuff in an if-statement).

@hsz
Copy link

hsz commented May 11, 2016

I have created a notification on Windows 10 and it works correctly except one thing - when it disapears after a few seconds it's not available in the notifications list.
When notification is still visible - icon next to the system clock is fully white - after it hides - icon is again transparent...

When notification is visible and I click the system notifications icon - it's on the list. But after I close the list and open again - it's gone.

@rubencodes
Copy link

Update on Windows <=7 notifications: The above code works, but we're currently having issues with it causing a change of the active window (e.g. if the Electron app is in the background and I'm in a different app, receiving a custom notification on Windows <= 7 seems to make the Electron app active without any user input). Wondering if it's something with mainWindow.webContents.executeJavaScript making the window active... Will update if I find out anything.

@seriema
Copy link

seriema commented Jul 8, 2016

@rubencodes is the solution you're trying related to electron-notification-shim? Feel free to log an issue there and I'll take a look.

@akashnimare
Copy link

akashnimare commented Aug 2, 2016

Does anyone know how to override the default native notifications with node-notifier or electron-notification-shim? I am using electron-notification-shim with electron-notify and both works perfectly. The only problem is I am not able to hide/override the native notifications.

@MarshallOfSound
Copy link
Member

@akashnimare If you want to disable the built in Notification implementation simply doing something like

class NullNotification {

}
window.Notification = NullNotification

Will make it not work (just override the Notification constructor)

@lbenitez3000
Copy link

@MarshallOfSound I'm assuming that's in the renderer process?

@alkuzad
Copy link

alkuzad commented Feb 16, 2017

@akashnimare maybe this will shed light on this problem ? RocketChat/Rocket.Chat.Electron#199

We switched to Rocket.Chat and it's working in there with some custom notification layout.

kevinsawicki added a commit that referenced this issue May 9, 2017
persist media device id salt across sessions
kevinsawicki added a commit that referenced this issue May 9, 2017
persist media device id salt across sessions
kevinsawicki added a commit that referenced this issue Jul 6, 2017
@moeinrahimi
Copy link

moeinrahimi commented Aug 2, 2017

if you tried all the ways and still notifications not working on windows 10 make sure quiet hours is turned off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests