@@ -29,6 +29,23 @@ export interface TrayIconClickEvent {
29
29
button_state : MouseButtonState
30
30
}
31
31
32
+ /** A double click happened on the tray icon. **Windows Only** */
33
+ export interface TrayIconDoubleClickEvent {
34
+ /** Id of the tray icon which triggered this event. */
35
+ id : string
36
+ /** Physical X Position of the click the triggered this event. */
37
+ x : number
38
+ /** Physical Y Position of the click the triggered this event. */
39
+ y : number
40
+ /** Position and size of the tray icon. */
41
+ rect : {
42
+ position : PhysicalPosition
43
+ size : PhysicalSize
44
+ }
45
+ /** Mouse button that triggered this event. */
46
+ button : MouseButton
47
+ }
48
+
32
49
/** The mouse entered the tray icon region. */
33
50
export interface TrayIconEnterEvent {
34
51
/** Id of the tray icon which triggered this event. */
@@ -84,6 +101,7 @@ export interface TrayIconLeaveEvent {
84
101
*/
85
102
export type TrayIconEvent =
86
103
| { click : TrayIconClickEvent }
104
+ | { doubleClick : TrayIconDoubleClickEvent }
87
105
| { enter : TrayIconEnterEvent }
88
106
| { move : TrayIconMoveEvent }
89
107
| { leave : TrayIconLeaveEvent }
@@ -207,7 +225,36 @@ export class TrayIcon extends Resource {
207
225
208
226
const handler = new Channel < TrayIconEvent > ( )
209
227
if ( options ?. action ) {
210
- handler . onmessage = options . action
228
+ const action = options . action
229
+ handler . onmessage = ( e ) => {
230
+ if ( 'click' in e ) {
231
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
232
+ e . click . rect . position = mapPosition ( e . click . rect . position )
233
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
234
+ e . click . rect . size = mapSize ( e . click . rect . size )
235
+ } else if ( 'doubleClick' in e ) {
236
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
237
+ e . doubleClick . rect . position = mapPosition ( e . doubleClick . rect . position )
238
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
239
+ e . doubleClick . rect . size = mapSize ( e . doubleClick . rect . size )
240
+ } else if ( 'enter' in e ) {
241
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
242
+ e . enter . rect . position = mapPosition ( e . enter . rect . position )
243
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
244
+ e . enter . rect . size = mapSize ( e . enter . rect . size )
245
+ } else if ( 'move' in e ) {
246
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
247
+ e . move . rect . position = mapPosition ( e . move . rect . position )
248
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
249
+ e . move . rect . size = mapSize ( e . move . rect . size )
250
+ } else if ( 'leave' in e ) {
251
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
252
+ e . leave . rect . position = mapPosition ( e . leave . rect . position )
253
+ // @ts -expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
254
+ e . leave . rect . size = mapSize ( e . leave . rect . size )
255
+ }
256
+ action ( e )
257
+ }
211
258
delete options . action
212
259
}
213
260
@@ -310,3 +357,14 @@ export class TrayIcon extends Resource {
310
357
} )
311
358
}
312
359
}
360
+
361
+ function mapPosition ( pos : {
362
+ Physical : { x : number ; y : number }
363
+ } ) : PhysicalPosition {
364
+ return new PhysicalPosition ( pos . Physical . x , pos . Physical . y )
365
+ }
366
+ function mapSize ( pos : {
367
+ Physical : { width : number ; height : number }
368
+ } ) : PhysicalSize {
369
+ return new PhysicalSize ( pos . Physical . width , pos . Physical . height )
370
+ }
0 commit comments