Skip to content

Commit 70d1b37

Browse files
Christopher StamperChristopher Stamper
authored andcommitted
Started implementing error handling for reconnect
1 parent 759ae6a commit 70d1b37

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/app/containers/ButtonsContainer.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,42 @@ function ButtonsContainer(): JSX.Element {
5757

5858
//adding a local state using useState for the reconnect button functionality
5959
const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false);
60-
const [disconnectedDialogOpen, setDisconnectedDialogOpen] = useState(false);
6160

6261
//logic for handling dialog box opening and closing
6362
const handleReconnectClick = () => {
6463
setReconnectDialogOpen(true);
6564
}
6665

6766
const handleReconnectConfirm = () => {
68-
//reconnection logic here
69-
dispatch(startReconnect());
67+
const maxRetries = 10;
68+
const retryInterval = 1000;
69+
const maxTimeout = 15000
70+
71+
const attemptReconnection = (retries: number, startTime: number) => {
72+
console.log('WORKING')
73+
if (retries <= maxRetries && Date.now() - startTime < maxTimeout) {
74+
console.log('HITTING IF');
75+
chrome.runtime.sendMessage({ action: 'attemptReconnect' }, (response) => {
76+
console.log('response: ', response);
77+
// if (response && response.success) {
78+
// console.log('SUCCESS')
79+
// } else {
80+
// console.log('Reconnect failed: ', !response && response.success);
81+
82+
// setTimeout(() => {
83+
// console.log('trying!')
84+
// attemptReconnection(retries + 1, startTime);
85+
// }, retryInterval);
86+
// }
87+
});
88+
} else {
89+
console.log('Max tries completed');
90+
}
91+
}
92+
7093
handleReconnectCancel();
94+
attemptReconnection(1, Date.now());
95+
// dispatch(startReconnect);
7196
}
7297

7398
const handleReconnectCancel = () => {

src/app/containers/MainContainer.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import {
1414
noDev,
1515
setCurrentLocation,
1616
disconnected,
17-
endReconnect
17+
endReconnect,
18+
launchContentScript,
1819
} from '../RTKslices';
1920
import { useDispatch, useSelector } from 'react-redux';
2021

22+
import { Status } from '../../backend/types/backendTypes';
23+
2124
/*
2225
This is the main container where everything in our application is rendered
2326
*/
@@ -118,12 +121,17 @@ function MainContainer(): JSX.Element {
118121
// used to track when the above connection closes unexpectedly. Remember that it should persist throughout the application lifecycle
119122
chrome.runtime.onMessage.addListener(handleDisconnect);
120123

124+
setTimeout(() => {
125+
currentPort.disconnect();
126+
}, 17000)
127+
121128
// assign port to state so it could be used by other components
122129
if (currentPort)
123130
dispatch(setPort(currentPort));
124131

125-
if (!connectionStatus && reconnectRequested)
132+
if (!connectionStatus && reconnectRequested) {
126133
dispatch(endReconnect());
134+
}
127135
});
128136

129137
// Error Page launch IF(Content script not launched OR RDT not installed OR Target not React app)

src/extension/background.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
290290
}
291291

292292
switch (action) {
293+
case 'attemptReconnect': {
294+
console.log('AYO');
295+
296+
const success = true;
297+
sendResponse({ success });
298+
break;
299+
}
293300
case 'jumpToSnap': {
294301
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index, name);
295302
if (portsArr.length > 0) {

0 commit comments

Comments
 (0)