Page MenuHomePhabricator

[desktop] Type windows notifs module
ClosedPublic

Authored by michal on Apr 6 2023, 6:14 AM.
Tags
None
Referenced Files
F3514338: D7326.id24720.diff
Sun, Dec 22, 4:16 AM
F3513239: D7326.diff
Sat, Dec 21, 11:18 PM
Unknown Object (File)
Sun, Dec 8, 6:33 PM
Unknown Object (File)
Sat, Dec 7, 8:35 PM
Unknown Object (File)
Sat, Dec 7, 8:35 PM
Unknown Object (File)
Sat, Dec 7, 8:34 PM
Unknown Object (File)
Sat, Dec 7, 8:34 PM
Unknown Object (File)
Sat, Dec 7, 8:34 PM
Subscribers

Details

Summary

Added types to the native notifs module based on the typescript types generated by NodeRT and on the Windows API documentation.

Test Plan

Run flow in desktop

Diff Detail

Repository
rCOMM Comm
Branch
michal/windows-notifs
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

desktop/flow-typed/@commapp/windowspush_vx.x.x.js
82 ↗(On Diff #24721)

This is typed as an Array<number> in typescript and the underlying Windows API is byte[] but it doesn't behave like an array during runtime. I've tried Array.isArray and checking if it was a TypedArray but couldn't get a definite answer. It isn't an iterator, but it has length and can be indexed with numbers.

michal requested review of this revision.Apr 6 2023, 6:33 AM
desktop/flow-typed/@commapp/windowspush_vx.x.x.js
82 ↗(On Diff #24721)

Perhaps it should be typed this way?

+payload: {
  +[number]: number,
  +length: number,
},

Note that an alternative to a flow-typed library would be to type the library directly. If the code instead the library has // @flow annotations, the libdef would not be necessary. Not sure if that's easier or harder though... could be harder to do if the library is largely codegenned code

Some questions about types, and please update the declaration of payload.

desktop/flow-typed/@commapp/windowspush_vx.x.x.js
51–78 ↗(On Diff #24721)

What is the meaning of these methods? Add and remove listener are quite obvious, but then on sounds like something which should work just as addListener... and off is maybe removeListener? What is the purpose of on and off?

86–95 ↗(On Diff #24721)

It is surprising to see these methods, as this type is an argument of listener methods from PushNotificationManager. So it seems like that listeners will be called with something that can be listened on, which is strange.

This revision is now accepted and ready to land.Apr 7 2023, 2:18 AM
desktop/flow-typed/@commapp/windowspush_vx.x.x.js
51–78 ↗(On Diff #24721)

There are just standard aliases for node's EventEmitter

86–95 ↗(On Diff #24721)

This is used when handling notifications when the app isn't running (docs). This doesn't apply to our app, but I've left them because they were generated by NodeRT.