Skip to content

Commit d35d91b

Browse files
committed
added comments
1 parent c111fbf commit d35d91b

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/app/styles/layout/_headContainer.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
color: transparent;
5555
}
5656

57+
// removes min-height of dropdown and change it to 100%
5758
.css-yk16xz-control,
5859
.css-1pahdxg-control {
5960
min-height: 100%;

src/extension/background.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const bgArr = [];
1+
const portsArr = [];
2+
// store ports in an array
23
const tabsObj = {
34
sourceTab: null,
45
};
@@ -18,22 +19,22 @@ function createTabObj(title) {
1819

1920
// establishing connection with devtools
2021
chrome.runtime.onConnect.addListener(port => {
21-
bgArr.push(port);
22+
// push every port connected to the ports array
23+
portsArr.push(port);
2224

23-
console.log('bgArr', bgArr);
24-
// send it to devtools as soon as connection to devtools is made
25+
// send tabs obj to the connected devtools as soon as connection to devtools is made
2526
if (Object.keys(tabsObj).length > 0) {
2627
port.postMessage({
2728
action: 'initialConnectSnapshots',
2829
payload: tabsObj,
2930
});
3031
}
3132

32-
// every time devtool is closed, remove the port from bgArr
33+
// every time devtool is closed, remove the port from portsArr
3334
port.onDisconnect.addListener(e => {
34-
for (let i = 0; i < bgArr.length; i += 1) {
35-
if (bgArr[i] === e) {
36-
bgArr.splice(i, 1);
35+
for (let i = 0; i < portsArr.length; i += 1) {
36+
if (portsArr[i] === e) {
37+
portsArr.splice(i, 1);
3738
break;
3839
}
3940
}
@@ -106,8 +107,8 @@ chrome.runtime.onMessage.addListener((request, sender) => {
106107
tabsObj[tabId].firstSnapshot = false;
107108
// don't add anything to snapshot storage if mode is persisting for the initial snapshot
108109
if (!persist) tabsObj[tabId].snapshots.push(request.payload);
109-
if (bgArr.length > 0) {
110-
bgArr.forEach(bg => bg.postMessage({
110+
if (portsArr.length > 0) {
111+
portsArr.forEach(bg => bg.postMessage({
111112
action: 'initialConnectSnapshots',
112113
payload: tabsObj,
113114
}));
@@ -119,8 +120,8 @@ chrome.runtime.onMessage.addListener((request, sender) => {
119120
tabsObj.sourceTab = tabId;
120121

121122
// send message to devtools
122-
if (bgArr.length > 0) {
123-
bgArr.forEach(bg => bg.postMessage({
123+
if (portsArr.length > 0) {
124+
portsArr.forEach(bg => bg.postMessage({
124125
action: 'sendSnapshots',
125126
payload: tabsObj,
126127
}));
@@ -133,14 +134,14 @@ chrome.runtime.onMessage.addListener((request, sender) => {
133134

134135
// when tab is closed, remove the tabid from the tabsObj
135136
chrome.tabs.onRemoved.addListener(tabId => {
136-
// after deleting the tab, send the updated tabs object to devtools
137-
if (bgArr.length > 0) {
138-
console.log('background => delete tab');
139-
bgArr.forEach(bg => bg.postMessage({
137+
// tell devtools which tab to delete
138+
if (portsArr.length > 0) {
139+
portsArr.forEach(bg => bg.postMessage({
140140
action: 'deleteTab',
141141
payload: tabId,
142142
}));
143143
}
144144

145+
// delete the tab from the tabsObj
145146
delete tabsObj[tabId];
146147
});

0 commit comments

Comments
 (0)