windows-installer icon indicating copy to clipboard operation
windows-installer copied to clipboard

3.0.4 breaks notification.onclick. Working on 2.7.0, full reproduction

Open Thomas101 opened this issue 6 years ago • 11 comments

  • Electron Version:
    • 4.0.8
  • windows-installer Version:
    • 3.0.4
  • Last Known Working windows-installer version:
    • 2.7.0

Expected Behavior

The following code should produce a notification and when clicked present an alert

const n = new Notification(1)
n.onclick = function () { alert('click') }

Actual Behavior

Works as expected when using 2.7.0, in 3.0.4 the notification presents, but the click event is never fired

To Reproduce

The following repo has a Notification example and takes care of creating a installer, start menu shortcuts etc. It basically a merge of electron-quick-start and the Handling Squirrel Events section in README

git clone https://github.com/wavebox/electron-quick-start.git -b winstaller-304-shortcut
cd electron-quick-start
npm install
npm run installer

Run the generated installer under electron-quick-start-installer. The app will present a notification and when clicked does nothing.

The same example works with 2.7.0. To try this...

  • Manually uninstall electron-quick-start (this is important)
  • Downgrade electron-winstaller to 2.7.0
  • npm run installer
  • Install and try again

Additional Information

I've been digging around what's going on here, and it's definately down to the start menu shortcut that gets generated in 3.0.4. Install with 3.0.4 and replace the shortcut with the 2.7.0 version and it works!

Using lnk-parser the only discernable difference that I can find is the value type is different for System.AppUserModel.ID. Here's the entry for both...

2.7.0

(full 270 output.pdf)

  • Property set GUID 9f4c2855-9f79-4b39-a8d0-e1d42de1d5f3
  • ID 26
  • Value 0x001f (VT_LPWSTR)
    • b2b6457d-4173-5767-b785-be9d6904b546
  • ID System.AppUserModel.ID
  • Value 0x001f (VT_LPWSTR)
    • com.squirrel.electron-quick-start.electron-quick-start

3.0.4

(full 304 output.pdf)

  • Property set GUID 9f4c2855-9f79-4b39-a8d0-e1d42de1d5f3
  • ID 26
  • Value 0x0048 (VT_CLSID)
    • CLSID:b2b6457d-4173-5767-b785-be9d6904b546
  • ID System.AppUserModel.ID Value 0x001f (VT_LPWSTR)
    • com.squirrel.electron-quick-start.electron-quick-start

I could be off the mark here, it could be something different. If you need any more info let me know!

Thomas101 avatar Mar 13 '19 13:03 Thomas101

same issue here. 4.0 still has this bug. 'click' event works on DEV mode, but not work on RELEASE mode.

roytan883 avatar Oct 16 '19 08:10 roytan883

i'm able to make a workaround : create shortcuts and setAppUserModelId manually

let WindowsShortcuts = require('windows-shortcuts');
 WindowsShortcuts.create('%APPDATA%/Microsoft/Windows/Start Menu/Programs/myapp.lnk', process.execPath);
  app.setAppUserModelId(process.execPath);

roytan883 avatar Oct 16 '19 08:10 roytan883

same issue here. 4.0 still has this bug. 'click' event works on DEV mode, but not work on RELEASE mode.

I met this issue also.

zquancai avatar Dec 24 '19 03:12 zquancai

I also experienced this issue, 2.7.0 working fine

qubicle avatar Feb 19 '20 12:02 qubicle

I also encountered this bug, but only on Windows 10, on Windows 8 the event is emitted. The latest version that works is 2.7.0. Unfortunately, 2.7.0 is affected by this bug.

dragosnicolae avatar Jul 02 '20 13:07 dragosnicolae

Original: https://github.com/electron/windows-installer/issues/296#issuecomment-542586319

Solution but not recommended: make appUserModelID not match to id from Squirrel. For example, if appUserModelID of your app set by squirrel is 'com.squirrel.slack.slack', then use app.setAppUserModelId to make id as something different, like 'com.squirrel.slack.slack.com'. This make notification clickable with electron-winstaller@latest.

But this solution change app name on notification like 'Slack' to 'com.squirrel.slack.slack.com'. And also it makes your app not to respect windows notification settings. so be careful.

jwoo0122 avatar Oct 12 '20 08:10 jwoo0122

This issue is still not resolved? This is a pretty critical issue for any modern desktop application.

Galkon avatar Oct 20 '20 05:10 Galkon

Is there any update on resolving this issue for Wire desktop?

kartagina avatar Apr 08 '21 02:04 kartagina

This is still not resolved with 4.0.1 and 5.0.0.

i'm able to make a workaround : create shortcuts and setAppUserModelId manually

let WindowsShortcuts = require('windows-shortcuts');
 WindowsShortcuts.create('%APPDATA%/Microsoft/Windows/Start Menu/Programs/myapp.lnk', process.execPath);
  app.setAppUserModelId(process.execPath);

Thanks @roytan883 - this helped me! This is how I fixed it: https://github.com/wireapp/wire-desktop/pull/4965

Update: It seems like clicking the first notification opens the app, but if there are two notifications clicking the second notification won't open the app :thinking:

ffflorian avatar Apr 26 '21 12:04 ffflorian

fwiw, I'm using electron-forge with squirrel installers (@electron-forge/maker-squirrel:6.0.0-beta.54) and only needed to set app.setAppUserModelId

src/index.ts

if(process.platform === "win32") {
  app.setAppUserModelId(process.execPath)
}

app.on('ready', () => {
...
});
`

ainesophaur avatar Jul 16 '21 18:07 ainesophaur

This is still not resolved with 4.0.1 and 5.0.0.

i'm able to make a workaround : create shortcuts and setAppUserModelId manually

let WindowsShortcuts = require('windows-shortcuts');
 WindowsShortcuts.create('%APPDATA%/Microsoft/Windows/Start Menu/Programs/myapp.lnk', process.execPath);
  app.setAppUserModelId(process.execPath);

Thanks @roytan883 - this helped me! This is how I fixed it: wireapp/wire-desktop#4965

Update: It seems like clicking the first notification opens the app, but if there are two notifications clicking the second notification won't open the app 🤔

Thanks so much for the example in the wire-desktop soucre @ffflorian. This helped me fix a long running issue with windows toast click events. I can't believe this still isn't fixed in electron-winstaller.


fwiw, I'm using electron-forge with squirrel installers (@electron-forge/maker-squirrel:6.0.0-beta.54) and only needed to set app.setAppUserModelId

src/index.ts

if(process.platform === "win32") {
  app.setAppUserModelId(process.execPath)
}

app.on('ready', () => {
...
});
`

Be careful @ainesophaur, while this fixes the click events it also makes every notification appear with the absolute path of the exe in the title: image

The best solution can be found in @ffflorian's example.


Note to anyone reading -- I spent hours trying to get toasts in Action Center to emit events with no luck. I stumbled across this stackoverflow thread which describes how you need to register a COM server in order to support that functionality. Apparently this module supports that, but I've not tested it.

I even went so far down the rabbit hole trying to get this to work before I found that stackoverflow thread that I ported the createGuidFromHash functionality from Squirrel.Windows to javascript in an attempt to comply with the standards defined for ToastActivatorCLSID. Maybe some day someone will find a use for this.

Galkon avatar Mar 15 '23 03:03 Galkon