You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -95,90 +95,89 @@ function MainContainer(): JSX.Element {
95
95
});
96
96
}
97
97
98
+
constmessageListener=(message: {
99
+
action: string;
100
+
payload: Record<string,unknown>;
101
+
sourceTab: number
102
+
})=>{
103
+
const{ action, payload, sourceTab }=message;
104
+
letmaxTab: number;
105
+
106
+
if(!sourceTab&&action!=='keepAlive'){// if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
107
+
consttabsArray: Array<string>=Object.keys(payload);// we create a tabsArray of strings composed of keys from our payload object
108
+
constnumTabsArray: number[]=tabsArray.map((tab)=>Number(tab));// we then map out our tabsArray where we convert each string into a number
109
+
110
+
maxTab=Math.max(...numTabsArray);// we then get the largest tab number value
111
+
}
112
+
113
+
switch(action){
114
+
case'deleteTab': {
115
+
dispatch(deleteTab(payload));
116
+
break;
117
+
}
118
+
case'devTools': {
119
+
dispatch(noDev(payload));
120
+
break;
121
+
}
122
+
case'changeTab': {
123
+
console.log('received changeTab message')
124
+
dispatch(setTab(payload));
125
+
break;
126
+
}
127
+
case'sendSnapshots': {
128
+
dispatch(setTab(sourceTab));
129
+
// set state with the information received from the background script
130
+
dispatch(addNewSnapshots(payload));
131
+
break;
132
+
}
133
+
case'initialConnectSnapshots': {
134
+
dispatch(initialConnect(payload));
135
+
break;
136
+
}
137
+
case'setCurrentLocation': {
138
+
dispatch(setCurrentLocation(payload));
139
+
break;
140
+
}
141
+
default:
142
+
}
143
+
}
144
+
98
145
useEffect(()=>{
99
146
if(!connectRequested)return;// only open port once so if it exists, do not run useEffect again
100
147
101
148
// chrome.runtime allows our application to retrieve our service worker (our eventual bundles/background.bundle.js after running npm run build), details about the manifest, and allows us to listen and respond to events in our application lifecycle.
102
149
103
150
handleConnect()
104
-
.then((port)=>{
151
+
.then((port: chrome.runtime.Port|null)=>{
105
152
if(port){
106
153
console.log('PORT SUCCESS: ',port)
107
-
setCurrentPort(port);
108
-
}else{
109
-
console.log('PORT FAIL: ',port);
110
-
}
111
-
});
112
-
113
-
console.log('that port tho: ',currentPort);
114
-
115
-
// listen for a message containing snapshots from the /extension/build/background.js service worker
116
-
currentPort.onMessage.addListener(
117
-
// parameter message is an object with following type script properties
118
-
(message: {
119
-
action: string;
120
-
payload: Record<string,unknown>;
121
-
sourceTab: number
122
-
})=>{
123
-
const{ action, payload, sourceTab }=message;
124
-
letmaxTab: number;
125
-
126
-
if(!sourceTab&&action!=='keepAlive'){// if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
127
-
consttabsArray: Array<string>=Object.keys(payload);// we create a tabsArray of strings composed of keys from our payload object
128
-
constnumTabsArray: number[]=tabsArray.map((tab)=>Number(tab));// we then map out our tabsArray where we convert each string into a number
129
154
130
-
maxTab=Math.max(...numTabsArray);// we then get the largest tab number value
131
-
}
132
-
133
-
switch(action){
134
-
case'deleteTab': {
135
-
dispatch(deleteTab(payload));
136
-
break;
137
-
}
138
-
case'devTools': {
139
-
dispatch(noDev(payload));
140
-
break;
141
-
}
142
-
case'changeTab': {
143
-
dispatch(setTab(payload));
144
-
break;
145
-
}
146
-
case'sendSnapshots': {
147
-
dispatch(setTab(sourceTab));
148
-
// set state with the information received from the background script
0 commit comments