@@ -161,10 +161,6 @@ export type UpdateStateRequest<S, A extends Action<string>> =
161
161
| SerializedActionMessage
162
162
| SerializedStateMessage < S , A > ;
163
163
164
- export interface EmptyUpdateStateAction {
165
- readonly type : typeof UPDATE_STATE ;
166
- }
167
-
168
164
interface UpdateStateAction < S , A extends Action < string > > {
169
165
readonly type : typeof UPDATE_STATE ;
170
166
request : UpdateStateRequest < S , A > ;
@@ -213,11 +209,6 @@ export type PanelMessage<S, A extends Action<string>> =
213
209
export type PanelMessageWithSplitAction < S , A extends Action < string > > =
214
210
| PanelMessage < S , A >
215
211
| SplitUpdateStateAction < S , A > ;
216
- export type MonitorMessage =
217
- | NAAction
218
- | ErrorMessage
219
- | EmptyUpdateStateAction
220
- | SetPersistAction ;
221
212
222
213
type TabPort = Omit < chrome . runtime . Port , 'postMessage' > & {
223
214
postMessage : ( message : TabMessage ) => void ;
@@ -227,20 +218,15 @@ type PanelPort = Omit<chrome.runtime.Port, 'postMessage'> & {
227
218
message : PanelMessageWithSplitAction < S , A > ,
228
219
) => void ;
229
220
} ;
230
- type MonitorPort = Omit < chrome . runtime . Port , 'postMessage' > & {
231
- postMessage : ( message : MonitorMessage ) => void ;
232
- } ;
233
221
234
222
export const CONNECTED = 'socket/CONNECTED' ;
235
223
export const DISCONNECTED = 'socket/DISCONNECTED' ;
236
224
const connections : {
237
225
readonly tab : { [ K in number | string ] : TabPort } ;
238
226
readonly panel : { [ K in number | string ] : PanelPort } ;
239
- readonly monitor : { [ K in number | string ] : MonitorPort } ;
240
227
} = {
241
228
tab : { } ,
242
229
panel : { } ,
243
- monitor : { } ,
244
230
} ;
245
231
const chunks : {
246
232
[ instanceId : string ] : PageScriptToContentScriptMessageForwardedToMonitors <
@@ -249,7 +235,6 @@ const chunks: {
249
235
> ;
250
236
} = { } ;
251
237
let monitors = 0 ;
252
- let isMonitored = false ;
253
238
254
239
const getId = ( sender : chrome . runtime . MessageSender , name ?: string ) =>
255
240
sender . tab ? sender . tab . id ! : name || sender . id ! ;
@@ -264,10 +249,7 @@ type MonitorAction<S, A extends Action<string>> =
264
249
const maxChromeMsgSize = 32 * 1024 * 1024 ;
265
250
266
251
function toMonitors < S , A extends Action < string > > ( action : MonitorAction < S , A > ) {
267
- for ( const port of [
268
- ...Object . values ( connections . monitor ) ,
269
- ...Object . values ( connections . panel ) ,
270
- ] ) {
252
+ for ( const port of Object . values ( connections . panel ) ) {
271
253
try {
272
254
port . postMessage ( action ) ;
273
255
} catch ( err ) {
@@ -412,19 +394,6 @@ function toAllTabs(msg: TabMessage) {
412
394
}
413
395
}
414
396
415
- function monitorInstances ( shouldMonitor : boolean , id ?: string ) {
416
- if ( ! id && isMonitored === shouldMonitor ) return ;
417
- const action = {
418
- type : shouldMonitor ? ( 'START' as const ) : ( 'STOP' as const ) ,
419
- } ;
420
- if ( id ) {
421
- if ( connections . tab [ id ] ) connections . tab [ id ] . postMessage ( action ) ;
422
- } else {
423
- toAllTabs ( action ) ;
424
- }
425
- isMonitored = shouldMonitor ;
426
- }
427
-
428
397
function getReducerError ( ) {
429
398
const instancesState = store . getState ( ) . instances ;
430
399
const payload = instancesState . states [ instancesState . current ] ;
@@ -436,11 +405,11 @@ function getReducerError() {
436
405
function togglePersist ( ) {
437
406
const state = store . getState ( ) ;
438
407
if ( state . instances . persisted ) {
439
- Object . keys ( state . instances . connections ) . forEach ( ( id ) => {
408
+ for ( const id of Object . keys ( state . instances . connections ) ) {
440
409
if ( connections . tab [ id ] ) return ;
441
410
store . dispatch ( { type : REMOVE_INSTANCE , id } ) ;
442
411
toMonitors ( { type : 'NA' , id } ) ;
443
- } ) ;
412
+ }
444
413
}
445
414
}
446
415
@@ -543,9 +512,9 @@ function messaging<S, A extends Action<string>>(
543
512
}
544
513
545
514
function disconnect (
546
- type : 'tab' | 'monitor' | ' panel',
515
+ type : 'tab' | 'panel' ,
547
516
id : number | string ,
548
- listener ? : ( message : any , port : chrome . runtime . Port ) => void ,
517
+ listener : ( message : any , port : chrome . runtime . Port ) => void ,
549
518
) {
550
519
return function disconnectListener ( ) {
551
520
const p = connections [ type ] [ id ] ;
@@ -559,7 +528,7 @@ function disconnect(
559
528
}
560
529
} else {
561
530
monitors -- ;
562
- if ( ! monitors ) monitorInstances ( false ) ;
531
+ if ( monitors === 0 ) toAllTabs ( { type : 'STOP' } ) ;
563
532
}
564
533
} ;
565
534
}
@@ -581,7 +550,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
581
550
chrome . action . enable ( id ) ;
582
551
chrome . action . setIcon ( { tabId : id , path : 'img/logo/38x38.png' } ) ;
583
552
}
584
- if ( isMonitored ) port . postMessage ( { type : 'START' } ) ;
553
+ if ( monitors > 0 ) port . postMessage ( { type : 'START' } ) ;
585
554
586
555
const state = store . getState ( ) ;
587
556
if ( state . instances . persisted ) {
@@ -607,22 +576,11 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
607
576
port . onMessage . addListener ( listener ) ;
608
577
port . onDisconnect . addListener ( disconnect ( 'tab' , id , listener ) ) ;
609
578
} else if ( port . name && port . name . indexOf ( 'monitor' ) === 0 ) {
610
- id = getId ( port . sender ! , port . name ) ;
611
- connections . monitor [ id ] = port ;
612
- monitorInstances ( true ) ;
613
- listener = ( msg : BackgroundAction | 'heartbeat' ) => {
614
- if ( msg === 'heartbeat' ) return ;
615
- store . dispatch ( msg ) ;
616
- } ;
617
- port . onMessage . addListener ( listener ) ;
618
- monitors ++ ;
619
- port . onDisconnect . addListener ( disconnect ( 'monitor' , id ) ) ;
620
- } else {
621
579
// devpanel
622
- id = port . name || port . sender ! . frameId ! ;
580
+ id = getId ( port . sender ! , port . name ) ;
623
581
connections . panel [ id ] = port ;
624
- monitorInstances ( true , port . name ) ;
625
582
monitors ++ ;
583
+ toAllTabs ( { type : 'START' } ) ;
626
584
listener = ( msg : BackgroundAction | 'heartbeat' ) => {
627
585
if ( msg === 'heartbeat' ) return ;
628
586
store . dispatch ( msg ) ;
0 commit comments