Page MenuHomePhabricator

[desktop] Handle windows notifications
ClosedPublic

Authored by michal on Apr 3 2023, 4:57 AM.
Tags
None
Referenced Files
F3515811: D7287.id24940.diff
Sun, Dec 22, 10:16 AM
F3515752: D7287.id24786.diff
Sun, Dec 22, 10:04 AM
F3515739: D7287.id24571.diff
Sun, Dec 22, 9:57 AM
F3515587: D7287.id24695.diff
Sun, Dec 22, 9:16 AM
F3515338: D7287.id24938.diff
Sun, Dec 22, 8:33 AM
Unknown Object (File)
Fri, Dec 20, 12:41 AM
Unknown Object (File)
Sat, Dec 7, 8:31 PM
Unknown Object (File)
Sat, Dec 7, 8:31 PM
Subscribers

Details

Summary

This diff adds handling of the Windows (WNS) notifications to the desktop client. It uses the native windows node module, built in the previous diffs.

Depends on D7286, D7253

Test Plan

Check if the app is correctly installed. Run the app, connect to the keyserver and check if it correctly gets the notifications. Check if it redirects to the app after clicking on the notification.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

desktop/src/main.js
258–260 ↗(On Diff #24571)

This is needed because without this the app name in the notifications was displayed as electron.app.comm.

desktop/src/push-notifications.js
15–17 ↗(On Diff #24571)

We load the module conditionally because to load it correctly, the windows runtime installer has to be run on the user's machine. This was added in D7253.

In short, Comm is run two times: once during installation so we can do any needed setup (like creating shortcuts and running the windows runtime installer), and after the installation is complete, it's run normally. In the first case (before we run the runtime installer) the isNormalStartup call will return false and we will skip loading this module.

27–29 ↗(On Diff #24571)

We have to convert the object returned by the native module to a string. Unfortunately, it doesn't implement the iterator methods so we have to use this loop.

69 ↗(On Diff #24571)

This is going to be replaced by a Object ID created in ENG-3562 before landing.

101 ↗(On Diff #24571)

Without this the icon for the windows notifs isn't displayed.

desktop/flow-typed/windows-pushnotifications_vx.x.x.js
1–5 ↗(On Diff #24571)

I'm going to create a task to fill this in.

michal requested review of this revision.Apr 3 2023, 5:13 AM
tomek added inline comments.
desktop/src/main.js
258 ↗(On Diff #24571)

Is this value the same for all the Windows version, e.g. on 64bit?

258–260 ↗(On Diff #24571)

Can we set this also on iOS?

desktop/src/push-notifications.js
27–29 ↗(On Diff #24571)

What is the type of event.payload? Does this conversion method correctly handle e.g. emojis?

This revision is now accepted and ready to land.Apr 4 2023, 4:23 AM

Correctly handle all strings. Tested by sending emojis and non-ascii letters.

desktop/src/main.js
258 ↗(On Diff #24571)

According to the docs there are no other windows values.

258–260 ↗(On Diff #24571)
desktop/src/push-notifications.js
27–29 ↗(On Diff #24571)

event.payload is a wrapper around a Windows API type so it's not a standard node type. The underlying type is some sort of byte array but I couldn't figure it out exactly.

Renamed to @commapp/windowspush

tomek added inline comments.
desktop/src/push-notifications.js
24 ↗(On Diff #24695)

https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding it seems like encoding should provided when the first argument is a string. Is that the case? If it is a string, why do we convert it again to string?

I guess the intention was rather to convert an array of bytes into a string, assuming that the array is encoded using utf8. In that case the encoding should be set for toString method. https://nodejs.org/api/buffer.html#buftostringencoding-start-end

By the way, are we sure that endianess is the same on both ends?

This revision is now accepted and ready to land.Apr 7 2023, 1:53 AM

Updated the payload conversion to string. I've finally figured out the event.payload object. It's an array wrapper created by NodeRT. It has only length property and {[number]: number} index accessor (but it's not an array).

It was somehow working with just Buffer.from(event.payload) but it was unsafe, and according to the node documentation it shouldn't work. Creating a new array will be a bit slower, but it's safer and for now we are sending only small notifications. I'm going to create a followup task with a way of optimizing it (adding a method that adds a conversion to string on the c++ side).

Fill in the objectID for getting the WNS channel (device_token)