Skip to content

Commit e277c00

Browse files
committed
chore: coding style improvements
1 parent d22a42e commit e277c00

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

background.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717

1818
function storeConfigToLocalStorage(data) {
19-
chrome.storage.local.set({ [SETUP_STRING]: data || {} });
19+
// return promise
20+
return chrome.storage.local.set({ [SETUP_STRING]: data || {} })
2021
}
2122

2223
function getConfigFromLocalStorage() {
@@ -35,10 +36,14 @@
3536
sendMsgToAllContainPage('live-server-config-updated', msg.data);
3637
}
3738
else if (msg.req === 'get-live-server-config') {
38-
getConfigFromLocalStorage().then(
39-
function (value) { sendResponse(value) },
40-
function (error) { console.error(`Error: ${error}`) }
41-
);
39+
getConfigFromLocalStorage()
40+
.then(function (value) {
41+
sendResponse(value)
42+
})
43+
.catch(function (error) {
44+
console.error("Error in get-live-server-config:",error);
45+
sendResponse({})
46+
});
4247
}
4348
return true; //Keep the callback(sendResponse) active
4449
});

popup/popup.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
liveServerUrl: liveServerAddress.value || ''
1919
}
2020

21-
if (chrome && chrome.runtime) {
22-
chrome.runtime.sendMessage({
23-
req: 'set-live-server-config',
24-
data: formData
25-
});
26-
}
21+
chrome.runtime.sendMessage({
22+
req: 'set-live-server-config',
23+
data: formData
24+
});
25+
2726
}
2827

2928
liveReloadCheck.onclick = () => {
@@ -41,13 +40,12 @@
4140
chrome.runtime.sendMessage({
4241
req: 'get-live-server-config'
4342
}, (data) => {
44-
if (data) {
45-
liveReloadCheck.checked = data.isEnable || false;
46-
noProxyCheckBox.checked = !data.proxySetup;
47-
actualServerAddress.value = data.actualUrl || '';
48-
liveServerAddress.value = data.liveServerUrl || '';
49-
serverSetupDiv.className = noProxyCheckBox.checked ? 'show' : 'hide';
50-
}
43+
if (!data) return
44+
liveReloadCheck.checked = data.isEnable || false;
45+
noProxyCheckBox.checked = !data.proxySetup;
46+
actualServerAddress.value = data.actualUrl || '';
47+
liveServerAddress.value = data.liveServerUrl || '';
48+
serverSetupDiv.className = noProxyCheckBox.checked ? 'show' : 'hide';
5149
});
5250
});
5351

@@ -62,5 +60,4 @@
6260
submitBtn.classList.add('btn-highlight');
6361
}
6462

65-
6663
})();

0 commit comments

Comments
 (0)