@@ -179,7 +179,7 @@ class App {
179
179
return authenticated_user ;
180
180
}
181
181
182
- async sendFromRenderer ( event , { messageid, data} ) {
182
+ async sendFromRenderer ( event : Electron . IpcMessageEvent , { messageid, data} ) {
183
183
if ( this . client . connection ) {
184
184
if ( data . type === 'list-accessories' ) {
185
185
return event . sender . send ( 'r' , {
@@ -201,6 +201,44 @@ class App {
201
201
messageid,
202
202
response : this . client . home_settings ,
203
203
} ) ;
204
+ } else if ( data . type === 'subscribe-characteristics' ) {
205
+ console . log ( data ) ;
206
+
207
+ try {
208
+ return event . sender . send ( 'r' , {
209
+ messageid,
210
+ response : await Promise . all ( data . ids . map ( ( [ accessory_uuid , service_id , characteristic_uuid ] ) => {
211
+ const accessory = this . client . accessories [ accessory_uuid ] ;
212
+ const service = accessory . services [ service_id ] ;
213
+ const characteristic = service . characteristics [ characteristic_uuid ] ;
214
+
215
+ return characteristic . subscribe ( event . sender ) ;
216
+ } ) ) ,
217
+ } ) ;
218
+ } catch ( err ) {
219
+ return event . sender . send ( 'r' , {
220
+ messageid,
221
+ } ) ;
222
+ }
223
+ } else if ( data . type === 'unsubscribe-characteristics' ) {
224
+ console . log ( data ) ;
225
+
226
+ try {
227
+ return event . sender . send ( 'r' , {
228
+ messageid,
229
+ response : await Promise . all ( data . ids . map ( ( [ accessory_uuid , service_id , characteristic_uuid ] ) => {
230
+ const accessory = this . client . accessories [ accessory_uuid ] ;
231
+ const service = accessory . services [ service_id ] ;
232
+ const characteristic = service . characteristics [ characteristic_uuid ] ;
233
+
234
+ return characteristic . unsubscribe ( event . sender ) ;
235
+ } ) ) ,
236
+ } ) ;
237
+ } catch ( err ) {
238
+ return event . sender . send ( 'r' , {
239
+ messageid,
240
+ } ) ;
241
+ }
204
242
}
205
243
206
244
const response = await this . client . connection . send ( data ) ;
@@ -473,6 +511,21 @@ electron_app.on('browser-window-created', (event, window) => {
473
511
window . connected = app . client . connected ;
474
512
} ) ;
475
513
514
+ electron_app . on ( 'web-contents-created' , ( event , webContents ) => {
515
+ webContents . on ( 'destroyed' , event => {
516
+ // Remove this window's characteristic subscriptions
517
+ Characteristic . unsubscribeAll ( webContents ) ;
518
+ } ) ;
519
+ webContents . on ( 'crashed' , event => {
520
+ // Remove this window's characteristic subscriptions
521
+ Characteristic . unsubscribeAll ( webContents ) ;
522
+ } ) ;
523
+ webContents . on ( 'did-navigate' , event => {
524
+ // Remove this window's characteristic subscriptions
525
+ Characteristic . unsubscribeAll ( webContents ) ;
526
+ } ) ;
527
+ } ) ;
528
+
476
529
electron_app . on ( 'window-all-closed' , ( ) => {
477
530
// Don't quit as we want to stay connected to the server to show notifications
478
531
} ) ;
0 commit comments