@@ -72,6 +72,7 @@ let _localTabId = NOID
72
72
export const state = {
73
73
bgConnection : undefined as ConnectionInfo | undefined ,
74
74
searchPopupConnections : new Map < ID , ConnectionInfo > ( ) ,
75
+ editingPopupConnections : new Map < ID , ConnectionInfo > ( ) ,
75
76
sidebarConnections : new Map < ID , ConnectionInfo > ( ) ,
76
77
setupPageConnections : new Map < ID , ConnectionInfo > ( ) ,
77
78
groupPageConnections : new Map < ID , ConnectionInfo > ( ) ,
@@ -101,6 +102,7 @@ export function isConnected(type: InstanceType, id = NOID): boolean {
101
102
else if ( type === InstanceType . sidebar ) return state . sidebarConnections . has ( id )
102
103
else if ( type === InstanceType . setup ) return state . setupPageConnections . has ( id )
103
104
else if ( type === InstanceType . search ) return state . searchPopupConnections . has ( id )
105
+ else if ( type === InstanceType . editing ) return state . editingPopupConnections . has ( id )
104
106
else if ( type === InstanceType . group ) return state . groupPageConnections . has ( id )
105
107
else if ( type === InstanceType . sync ) return state . syncConnections . has ( id )
106
108
else if ( type === InstanceType . panelConfig ) return state . panelConfigConnections . has ( id )
@@ -113,18 +115,20 @@ export function getConnection(type: InstanceType, id: ID): ConnectionInfo | unde
113
115
else if ( type === InstanceType . sidebar ) return state . sidebarConnections . get ( id )
114
116
else if ( type === InstanceType . setup ) return state . setupPageConnections . get ( id )
115
117
else if ( type === InstanceType . search ) return state . searchPopupConnections . get ( id )
118
+ else if ( type === InstanceType . editing ) return state . editingPopupConnections . get ( id )
116
119
else if ( type === InstanceType . group ) return state . groupPageConnections . get ( id )
117
120
else if ( type === InstanceType . sync ) return state . syncConnections . get ( id )
118
121
else if ( type === InstanceType . panelConfig ) return state . panelConfigConnections . get ( id )
119
122
else if ( type === InstanceType . preview ) return state . previewConnection
120
123
}
121
124
122
125
function removeConnection ( type : InstanceType , id : ID ) {
123
- Logs . info ( 'IPC.REMOVE:' , getInstanceName ( type ) , id )
126
+ // Logs.info('IPC.REMOVE:', getInstanceName(type), id)
124
127
if ( type === InstanceType . bg ) state . bgConnection = undefined
125
128
else if ( type === InstanceType . sidebar ) state . sidebarConnections . delete ( id )
126
129
else if ( type === InstanceType . setup ) state . setupPageConnections . delete ( id )
127
130
else if ( type === InstanceType . search ) state . searchPopupConnections . delete ( id )
131
+ else if ( type === InstanceType . editing ) state . editingPopupConnections . delete ( id )
128
132
else if ( type === InstanceType . sync ) state . syncConnections . delete ( id )
129
133
else if ( type === InstanceType . panelConfig ) state . panelConfigConnections . delete ( id )
130
134
else if ( type === InstanceType . group ) state . groupPageConnections . delete ( id )
@@ -144,6 +148,7 @@ function createConnection(type: InstanceType, id: ID): ConnectionInfo {
144
148
else if ( type === InstanceType . sidebar ) state . sidebarConnections . set ( id , connection )
145
149
else if ( type === InstanceType . setup ) state . setupPageConnections . set ( id , connection )
146
150
else if ( type === InstanceType . search ) state . searchPopupConnections . set ( id , connection )
151
+ else if ( type === InstanceType . editing ) state . editingPopupConnections . set ( id , connection )
147
152
else if ( type === InstanceType . group ) state . groupPageConnections . set ( id , connection )
148
153
else if ( type === InstanceType . sync ) state . syncConnections . set ( id , connection )
149
154
else if ( type === InstanceType . panelConfig ) state . panelConfigConnections . set ( id , connection )
@@ -167,6 +172,7 @@ export function connectTo(
167
172
const toSidebar = dstType === InstanceType . sidebar
168
173
const toSetup = dstType === InstanceType . setup
169
174
const toSearch = dstType === InstanceType . search
175
+ const toEditing = dstType === InstanceType . editing
170
176
const toSync = dstType === InstanceType . sync
171
177
const toPanelConfig = dstType === InstanceType . panelConfig
172
178
const toGroup = dstType === InstanceType . group
@@ -176,8 +182,9 @@ export function connectTo(
176
182
// Check destination id
177
183
let id
178
184
if ( toBg || toPreview ) id = NOID
179
- else if ( ( toSidebar || toSearch || toSync || toPanelConfig ) && dstWinId !== NOID ) id = dstWinId
180
- else if ( ( toSetup || toGroup ) && dstTabId !== NOID ) id = dstTabId
185
+ else if ( ( toSidebar || toSearch || toEditing || toSync || toPanelConfig ) && dstWinId !== NOID ) {
186
+ id = dstWinId
187
+ } else if ( ( toSetup || toGroup ) && dstTabId !== NOID ) id = dstTabId
181
188
else {
182
189
Logs . err ( `${ dbgPrefix } No destination id` )
183
190
return
@@ -187,7 +194,7 @@ export function connectTo(
187
194
const portNameData : PortNameData = { srcType, dstType }
188
195
if ( srcWinId !== NOID ) portNameData . srcWinId = srcWinId
189
196
if ( srcTabId !== NOID ) portNameData . srcTabId = srcTabId
190
- if ( dstWinId !== NOID && ( toSidebar || toSearch || toSync || toPanelConfig ) ) {
197
+ if ( dstWinId !== NOID && ( toSidebar || toSearch || toEditing || toSync || toPanelConfig ) ) {
191
198
portNameData . dstWinId = dstWinId
192
199
}
193
200
if ( dstTabId !== NOID && ( toSetup || toGroup ) ) portNameData . dstTabId = dstTabId
@@ -274,7 +281,7 @@ export function connectTo(
274
281
// Reset reconnection count after 5s
275
282
clearTimeout ( connection . reconnectingTimeout )
276
283
connection . reconnectingTimeout = setTimeout ( ( ) => {
277
- Logs . info ( `${ dbgPrefix } Reseting reconnection count:` , connection . reconnectCount )
284
+ // Logs.info(`${dbgPrefix} Reseting reconnection count:`, connection.reconnectCount)
278
285
connection . reconnectCount = 0
279
286
} , RESET_RECON_COUNT_TIMEOUT )
280
287
@@ -304,7 +311,7 @@ export function connectTo(
304
311
timeout,
305
312
portName : '' ,
306
313
ok : ( ) => {
307
- Logs . info ( `IPC.connectTo(${ getInstanceName ( dstType ) } ): CONFIRMED` )
314
+ // Logs.info(`IPC.connectTo(${getInstanceName(dstType)}): CONFIRMED`)
308
315
connection . state = ConnectionState . Ready
309
316
if ( connectionIsNew ) {
310
317
const handlers = connectionHandlers . get ( dstType )
@@ -426,6 +433,17 @@ export function sendToSearchPopup<T extends InstanceType.search, A extends Actio
426
433
send ( { dstType : InstanceType . search , dstWinId, action, args } )
427
434
}
428
435
436
+ /**
437
+ * Sends message to editing popup.
438
+ */
439
+ export function sendToEditingPopup < T extends InstanceType . editing , A extends ActionsKeys < T > > (
440
+ dstWinId : ID ,
441
+ action : A ,
442
+ ...args : Parameters < ActionsType < T > [ A ] >
443
+ ) : void {
444
+ send ( { dstType : InstanceType . editing , dstWinId, action, args } )
445
+ }
446
+
429
447
/**
430
448
* Sends message to background.
431
449
*/
@@ -460,6 +478,7 @@ export function send<T extends InstanceType, A extends ActionsKeys<T>>(msg: Mess
460
478
if ( msg . dstType === InstanceType . sidebar && msg . dstWinId !== undefined ) id = msg . dstWinId
461
479
else if ( msg . dstType === InstanceType . setup && msg . dstTabId !== undefined ) id = msg . dstTabId
462
480
else if ( msg . dstType === InstanceType . search && msg . dstWinId !== undefined ) id = msg . dstWinId
481
+ else if ( msg . dstType === InstanceType . editing && msg . dstWinId !== undefined ) id = msg . dstWinId
463
482
else if ( msg . dstType === InstanceType . group && msg . dstTabId !== undefined ) id = msg . dstTabId
464
483
465
484
// Get port
@@ -521,6 +540,7 @@ export async function request<T extends InstanceType, A extends ActionsKeys<T>>(
521
540
if ( dstType === InstanceType . sidebar && msg . dstWinId !== undefined ) id = msg . dstWinId
522
541
else if ( dstType === InstanceType . setup && msg . dstTabId !== undefined ) id = msg . dstTabId
523
542
else if ( dstType === InstanceType . search && msg . dstWinId !== undefined ) id = msg . dstWinId
543
+ else if ( dstType === InstanceType . editing && msg . dstWinId !== undefined ) id = msg . dstWinId
524
544
else if ( dstType === InstanceType . sync && msg . dstWinId !== undefined ) id = msg . dstWinId
525
545
else if ( dstType === InstanceType . panelConfig && msg . dstWinId !== undefined ) id = msg . dstWinId
526
546
else if ( dstType === InstanceType . group && msg . dstTabId !== undefined ) id = msg . dstTabId
@@ -668,13 +688,15 @@ function onConnect(port: browser.runtime.Port) {
668
688
const fromSidebar = srcType === InstanceType . sidebar
669
689
const fromSetup = srcType === InstanceType . setup
670
690
const fromSearch = srcType === InstanceType . search
691
+ const fromEditing = srcType === InstanceType . editing
671
692
const fromGroup = srcType === InstanceType . group
672
693
const fromSync = srcType === InstanceType . sync
673
694
const fromPanelConfig = srcType === InstanceType . panelConfig
674
695
const fromPreview = srcType === InstanceType . preview
675
696
if ( fromSidebar && srcWinId === NOID ) return Logs . err ( 'IPC.onConnect: Sidebar: No srcWinId' )
676
697
if ( fromSetup && srcTabId === NOID ) return Logs . err ( 'IPC.onConnect: Setup page: No srcTabId' )
677
698
if ( fromSearch && srcWinId === NOID ) return Logs . err ( 'IPC.onConnect: Search popup: No srcWinId' )
699
+ if ( fromEditing && srcWinId === NOID ) return Logs . err ( 'IPC.onConnect: Editing popup: No srcWinId' )
678
700
if ( fromSync && srcWinId === NOID ) return Logs . err ( 'IPC.onConnect: Sync: No srcWinId' )
679
701
if ( fromPanelConfig && srcWinId === NOID ) return Logs . err ( 'IPC.onConnect: PanelConf: No srcWinId' )
680
702
if ( fromGroup && srcTabId === NOID ) return Logs . err ( 'IPC.onConnect: Group page: No srcTabId' )
@@ -683,7 +705,10 @@ function onConnect(port: browser.runtime.Port) {
683
705
let id
684
706
if ( fromBg || fromPreview ) {
685
707
id = NOID
686
- } else if ( ( fromSidebar || fromSearch || fromSync || fromPanelConfig ) && srcWinId !== NOID ) {
708
+ } else if (
709
+ ( fromSidebar || fromSearch || fromEditing || fromSync || fromPanelConfig ) &&
710
+ srcWinId !== NOID
711
+ ) {
687
712
id = srcWinId
688
713
} else if ( ( fromSetup || fromGroup ) && srcTabId !== NOID ) {
689
714
id = srcTabId
@@ -764,6 +789,7 @@ export function onConnected(type: InstanceType, cb: (winOrTabId: ID) => void) {
764
789
if ( type === InstanceType . sidebar ) state . sidebarConnections . forEach ( con => cb ( con . id ) )
765
790
if ( type === InstanceType . setup ) state . setupPageConnections . forEach ( con => cb ( con . id ) )
766
791
if ( type === InstanceType . search ) state . searchPopupConnections . forEach ( con => cb ( con . id ) )
792
+ if ( type === InstanceType . editing ) state . editingPopupConnections . forEach ( con => cb ( con . id ) )
767
793
if ( type === InstanceType . sync ) state . syncConnections . forEach ( con => cb ( con . id ) )
768
794
if ( type === InstanceType . panelConfig ) state . panelConfigConnections . forEach ( con => cb ( con . id ) )
769
795
if ( type === InstanceType . group ) state . groupPageConnections . forEach ( con => cb ( con . id ) )
0 commit comments