Giter Site home page Giter Site logo

felixrieseberg / electron-windows-interactive-notifications Goto Github PK

View Code? Open in Web Editor NEW
55.0 2.0 17.0 2.33 MB

:zap: Respond to interactive notifications on Windows, from Electron

License: MIT License

C++ 50.75% C 1.05% C# 14.84% Objective-C 1.38% Python 6.60% JavaScript 25.39%
electron notifications windows

electron-windows-interactive-notifications's Introduction

Respond to Interactive Notifications, from Node or Electron

This project allows you to respond to Windows interactive notifications. Interactive notifications allow the user to interact with the notification by entering data. In order to receive that data, your application will need to register a COM component with the operating system.

๐Ÿ“ To send notifications from Electron, take a look at electron-windows-notifications

Installation

โš ๏ธ Please read these instructions carefully.

A unique identifier for all apps

When a win32 desktop application sends an interactive toast notification, Windows checks if the start menu contains a shortcut to the sending binary. If that is the case, it will check the shortcut for the System.AppUserModel.ToastActivatorCLSID property. If that property is set, it will attempt to activate a COM component using the given CLSID. The CLSID needs to be defined at compile-time and needs to be unique. This property is in concept similar to the AppUserModelId.

For that reason, this module will either use a specified CLSID or generate a random CLSID during installation and print it to console. There are two ways to set the CLSID:

  • Using an environment variable TOAST_ACTIVATOR_CLSID
  • Using the package.json of your application
{
    "dependencies": { },
    "interactive-notifications": {
        "toast-activator-clsid": "B23D2B18-8DD7-403A-B9B7-152B40A1478C"
    }
}

For that reason, this module compiles either using a set environment variable, a property "windows-notifications": { "toastActivatorCLSID": "YOUR_ID" }, or will generate a unique CLSID during installation. In both cases it will print to the console which CLSID was used.

The protocol to launch

To start your application, this module uses protocol links (like spotify:// or slack://). Define the protocol that will be compiled into the dll using one of the following two methods:

  • Using an environment variable TOAST_ACTIVATOR_PROTOCOL
  • Using the package.json of your application
{
    "dependencies": { },
    "interactive-notifications": {
        "protocol": "myapp://"
    }
}

Example Installation

$env:TOAST_ACTIVATOR_PROTOCOL="myapp://"
$env:TOAST_ACTIVATOR_CLSID="B23D2B18-8DD7-403A-B9B7-152B40A1478C"
npm install --save windows-interactive-notifications

Usage

This module contains only three methods relevant to you:

registerAppForNotificationSupport(shortcutPath, appId)

In order to receive interactive notification activations, your application must have a shortcut in the Start Menu. That shortcut needs to contain two values in its propertyStore: A System.AppUserModel.ToastActivatorCLSID and a System.AppUserModel.Id. You don't have to use this module to set the shortcut, but it is offered for your convenience. Since the CLSID needs to be hardcoded at compile-time, it is not a parameter (see installation for more details).

Example

const {registerAppForNotificationSupport} = require('windows-interactive-notifications')
const shortcutPath = 'Microsoft\\Windows\\Start Menu\\MyApp.lnk'
const appId = 'com.squirrel.mycompany.myapp'

registerAppForNotificationSupport(shortcutPath, appId)

registerComServer()

Before registering the activator, make sure to register the COM Server. Automatically called by registerAppForNotificationSupport(), you only have to call this method if you used Squirrel or a different program to manage your shortcut.

registerActivator()

Use this method to enable the activator. It registers the COM component with Windows. Call it before sending a notification. Calling it multiple times has no downside.

unregisterActivator()

Use this method to disable the activator. It unregisters the COM component with Windows.

Example Usage

Once you have registered your application for notification support (either using your own shortcut creation method or the one given in this module), register the activator.

This module will communicate with your application using protocol links. You might know about mailto: - and how you can tell an email application to create a new email draft by calling mailto:[email protected]?subject=This%20is%20the%20subject. Well, this module works the same way: During installation, you defined your applications protocol. It is up to you to ensure that your app can actually receive those links. To debug this behavior, feel free to just use Windows Run (open it with Windows + R).

The app will activate your app in the following format:

<Protocol><Toast Arguments>&userData=[{"key":"value"}]

So, for a notification that contains the following template, your app would be called with the following URI:

<actions>
  <input id="message" type="text" placeHolderContent="Type a reply" />
  <action hint-inputId="message" activationType="background" content="Reply" arguments="message/?user=123" />
</actions>
myapp://message/?user=123&userData=[{"key":"message","value":"Hello"}]

This module does super-basic escaping. Spaces are turned into %20, doublequotes (") are turned into %22. Ironically though, Unicode is supported.

License

MIT. Please see License for details.

electron-windows-interactive-notifications's People

Contributors

felixrieseberg avatar kwonoj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

electron-windows-interactive-notifications's Issues

Activator C++ code does not fire on clicking notification.

I've done the following things

  • Manually copied InteractiveNotifications.dll to resolve a runtime error
  • Fixed up calls to v8::String::Value compile error in notification_bindings.cc
  • Manually updated CLSID in two places in InteractiveNotifications.cpp to the correct value
  • Verified I have the correct CLSID by running lnk-parser on my Squirrel-generated shortcut.
  • Called registerComServer() and registerActivator() during startup.
  • Verified that a registry key is created under Computer\HKEY_CURRENT_USER\Software\Classes\CLSID\{d52b1d2e-f9cd-56b2-bd84-21a832557d71} - LocalServer32 has a default value of C:\Users\me\AppData\Local\MyApp\app-1.0.0\MyApp.exe
  • Send a notification via NodeRT ToastNotification, using the exact template from the readme, and sent after the registration. The notification shows just fine.
  • I've set up my app to accept protocol activations and enforce single-instance and validated that it's working by invoking from Start -> Run. (But I don't think it's making it that far)

But nothing happens when I hit the button. It hasn't worked in any other combination, like with a standalone button either. It doesn't seem to work at all when I specify activationType="foreground" so I've left it at activationType="background".

I dug into the code and can see that the Activate method in InteractiveNotifications.cpp is set up to handle the notification activation and launch the protocol URI with ShellExecuteW. I put some code at the top of the function to write a log message to a file, but the file is never written. So I don't think it's making it inside that method at all.

What else can I check here? Are there any debug logs for notification activations? Have I missed something?

module could not be found: notifications_bindings.node

Hello,

I have electron-windows-interactive-notifications as my dependency. When I use clean npm install and after that electron-rebuild I get:

App threw an error during load
Error: The specified module could not be found.
\\?\C:\Users\moro\projects\tw-en-ty\node_modules\electron-windows-interactive-notifications\build\Release\notifications_bindings.node
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at bindings (C:\Users\moro\projects\tw-en-ty\node_modules\bindings\bindings.js:76:44)

According to a NodeJS issue it seems to be a native dependency problem. When I examine notifications_bindings.node by dependencywalker I see following missing direct DLLs (among many missing nested):

image

Please, is it a problem with electron-windows-interactive-notifications or something else?

Also I found myself very confused resolving electron-windows-interactive-notifications issues as it is crossover of native and JS technologies which highly depends on the way an environment was set. Is there any OOTB-working sample for electron-windows-interactive-notifications that I could use as a reference?

Thank you!

Question was also asked here

how to verify CLSID and AUMID in start menu shortcut when calling registerAppForNotificationsSupport

Hi @felixrieseberg ,

I created a nsis installer with electron-builder and when using it, a shortcut is created in the start menu.

will calling registerAppForNotificationSupport method add the System.AppUserModel.ToastActivatorCLSID and System.AppUserModel.Id to the existing shortcut or will it remove the old shortcut and create a new one with these additional properties ?

either way i am not able to receive text reply from interactive notification input.

Any pointers on how to set System.AppUserModel.ToastActivatorCLSID and System.AppUserModel.Id property to the shortcut when using squirrel or nsis installer ( if that is causing the issue ) will help greatly.

Also how to verify whether the ids have been set properly to the start menu shortcut ?

Compilation error with v8::String::Value::Value

I installed the Windows 10 SDK 10.0.10586 and the MSVC v140 - VS 2015 C++ Build Tools from the Visual Studio installer. However, installing the package still gives this compilation error:

C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(29,50): error C2665: 'v8::String::Value::Value': none of the 2 overloads could convert all the argument types [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\Users\david\AppData\Local\node-gyp\Cache\18.12.1\include\node\v8-primitive.h(540,5): message : could be 'v8::String::Value::Value(const v8::String::Value &)' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(29,35): message : 'v8::String::Value::Value(const v8::String::Value &)': cannot convert argument 1 from 'v8::Localv8::String' to 'const v8::String::Value &' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(29,50): message : Reason: cannot convert from 'v8::Localv8::String' to 'const v8::String::Value' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(29,36): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\Users\david\AppData\Local\node-gyp\Cache\18.12.1\include\node\v8-primitive.h(540,5): message : see declaration of 'v8::String::Value::Value' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(29,50): message : while trying to match the argument list '(v8::Localv8::String)' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(30,44): error C2665: 'v8::String::Value::Value': none of the 2 overloads could convert all the argument types [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\Users\david\AppData\Local\node-gyp\Cache\18.12.1\include\node\v8-primitive.h(540,5): message : could be 'v8::String::Value::Value(const v8::String::Value &)' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(30,32): message : 'v8::String::Value::Value(const v8::String::Value &)': cannot convert argument 1 from 'v8::Localv8::String' to 'const v8::String::Value &' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(30,44): message : Reason: cannot convert from 'v8::Localv8::String' to 'const v8::String::Value' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(30,33): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\Users\david\AppData\Local\node-gyp\Cache\18.12.1\include\node\v8-primitive.h(540,5): message : see declaration of 'v8::String::Value::Value' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(30,44): message : while trying to match the argument list '(v8::Localv8::String)' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\lib\notifications_bindings.cc(36,27): error C2660: 'v8::String::Concat': function does not take 2 arguments [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]
C:\Users\david\AppData\Local\node-gyp\Cache\18.12.1\include\node\v8-primitive.h(444,24): message : see declaration of 'v8::String::Concat' [C:\git\Focalist\electron\node_modules\electron-windows-interactive-notifications\build\notifications_bindings.vcxproj]

"...\V110\Microsoft.Cpp.Default.props" was not found

EDITED

Hello,

today I wanted to try your library but couldn't manage to include it as a dependency:

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 11. 2. 2017 12:42:19.
Project "C:\Users\moro\projects\tw-en-ty\node_modules\.staging\electron-windows-interactive-notifications-c7f3dfff\InteractiveNotifications.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|x64".
ValidateProjects:
  The project "InteractiveManagedTest" is not selected for building in solution configuration "Release|x64".
Project "C:\Users\moro\projects\tw-en-ty\node_modules\.staging\electron-windows-interactive-notifications-c7f3dfff\InteractiveNotifications.sln" (1) is building "C:\Users\moro\projects\tw-en-ty\node_modules\.s taging\electron-windows-interactive-notifications-c7f3dfff\InteractiveNotifications\InteractiveNotifications.vcxproj" (2) on node 1 (default targets).
C:\Users\moro\projects\tw-en-ty\node_modules\.staging\electron-windows-interactive-notifications-c7f3dfff\InteractiveNotifications\InteractiveNotifications.vcxproj(27,3): error MSB4019: The imported project "C :\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "C:\Users\moro\projects\tw-en-ty\node_modules\.staging\electron-windows-interactive-notifications-c7f3dfff\InteractiveNotifications\InteractiveNotifications.vcxproj" (default targets) --
FAILED.

It seems that the library is dependent on a specific MSBuild version (110), however I have only version 140. Is there any way to make it work with it?

Thank you!

npm install failing on Windows 10

Hi,

I'm just getting started with this module, but I can't get it to install on my system. I've made sure that I'm running the VS Code Developer Command Prompt as admin, that my system can recognize the msbuild command, and other npm install(s) work fine.

Here's my error log:

1022 verbose stack Error: [email protected] preinstall: `node ./scripts/preinstall.js && npm run build`
1022 verbose stack Exit status 1
1022 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
1022 verbose stack     at emitTwo (events.js:126:13)
1022 verbose stack     at EventEmitter.emit (events.js:214:7)
1022 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
1022 verbose stack     at emitTwo (events.js:126:13)
1022 verbose stack     at ChildProcess.emit (events.js:214:7)
1022 verbose stack     at maybeClose (internal/child_process.js:925:16)
1022 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
1023 verbose pkgid [email protected]
1024 verbose cwd <myDirectory>
1025 verbose Windows_NT 10.0.14393
1026 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "electron-windows-interactive-notifications"
1027 verbose node v8.11.3
1028 verbose npm  v5.6.0
1029 error code ELIFECYCLE
1030 error errno 1
1031 error [email protected] preinstall: `node ./scripts/preinstall.js && npm run build`
1031 error Exit status 1
1032 error Failed at the [email protected] preinstall script.
1032 error This is probably not a problem with npm. There is likely additional logging output above.
1033 verbose exit [ 1, true ]

Activator not getting called

Hi @felixrieseberg

after some initial Problems with the setup I think I got it correctly so far but somehow the Activate Method never gets called.

  • I installed the package
  • checked that the CLSID is set to a unique GUID
  • checked that the protocol is set to in my case 'jukebox://'
  • validated that the shortcut is created correctly
  • validated that the ReqKey is created correctly

in my main.js I am calling

registerAppForNotificationSupport(shortcut, appId);
registerActivator();

and then at some point I create a Notification, which shows up and there is an input filed and a reply button but still the Activate Method never gets called. Any Clues ?

package.json config gets ignored

As stated in the Readme to install this package I have to specify a CLSID and a protocol. Specifying it in the package.json however results in this installation output:

ToastActivitorCLSID

DLLs will be compiled with the following ToastActivitorCLSID:
7d125530-fa07-4584-9fe7-dc1e7a589a7c
###########################################################

No protocol defined, please consult windows-interactive-notifications readme!

ToastActivator Protocol

DLLs will be compiled with the following launch protocol:
/myapp:///gi
###########################################################

package.json:

 {
... 
 "interactive-notifications": {
    "toast-activator-clsid": "F2633CBF-FAD4-4326-9FC5-11D7F118335B",
    "protocol": "jukebox://"
  },
...
}

Did I specify it incorrectly or is the installation not reading the package.json ?
It should be noted if I specify an Environment variable the installation uses the correct values.

ElectronWindowsInteractiveNotifications.log

Example?

Hoe can I read the input text from a notification in my code?

error MSB4086 on install

Hi, I'm running npm-install and seeing the following error...

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(94,27): error MSB4086: A numeric comparison was
attempted on "$(TargetPlatformVersion)" that evaluates to "10.0.10586.0" instead of a number, in condition "'$(UseOSWin
MdReferences)' == '' and ('$(TargetPlatformWinMDLocation)' == '' and '$(TargetPlatformIdentifier)' == 'Windows' and $(
TargetPlatformVersion)' > '7.0')". [C:\Users\Tom\Dev\app\node_modules\.staging\electron-
windows-interactive-notification-906feb04'InteractiveNotifications\InteractiveNotifications.vcxproj]

I was wondering if you could point me in the right direction. I have VSCode 2015 installed and build tools 2015. I've also set my VisualStudioVersion environment variable to 14.0 as was mentioned in #3 just in case this has any impact on what's happening.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.