-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add more control over notifications #13
Conversation
Delegate on clients to hold a callback map
package.json
Outdated
"version": "0.1.7", | ||
"version": "0.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will revert this before merging and manage the release separately. I also want to enable CI for macOS before doing the release, of course, but in a separate PR 😳
auto userInfoString = Utils::JSONStringify(env, userInfoObject); | ||
userInfo = Utils::utf8ToWideChar(userInfoString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using JavaScript's JSON.stringify
function to serialize the userInfo
object, which will be later stored in the launchArgs
string (yup no way of storing it in a structured way…), to then be deserialized with JavaScript's JSON.parse
function before sending it back with the notification callback.
Not very happy about this, but I couldn't think of a better way other than exposing all the Windows notifications API we need to JS and do most of the work from there, but it was a ton of work and didn't want to make this PR bigger than it already is 😂 I might tackle it in a different PR.
// Formats the launch args like this: <notificationID>;<userInfo JSON string> | ||
std::wstring formatLaunchArgs(const std::wstring ¬ificationID, const std::wstring &userInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another thing I'm not super proud of, and another good reason to move logic to JS where it's easier to serialize/deserialize and have some compiler-time help for this data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ I appreciated you breaking things down into smaller functions - much easier to digest syntax I wasn't familiar with when I knew what it was supposed to be doing. :D
Notes on testing:
- attempted to test via the sample-app but seems it was blocked from notifying on mac. (Discussed this in slack).
- tested with the draft pr in Desktop and was able to still show the notification and when I disabled/enabled permissions it did as expected. :D But, I am not terribly sure how to test the requesting permission part.
- I was thinking that if I opened desktop dev, hit show notification, closed desktop dev, opened desktop dev, clicked on notification that it might show it in the new instance. It did nothing. (But, maybe I misunderstood and that is not part of this.) :/
That is correct: the Later, when you close the app and reopen it again, if you click the notification, Desktop will recover the Alive event from the notification's The notification from |
This PR introduces more control over notifications:
The changes require to support all that on macOS require us to invoke all the notifications code from the main process on an Electron app. That's why this PR also replaces the previous sample script with an Electron sample app, because it eases testing for us in a more similar environment to the GitHub Desktop app.