Skip to content

Commit

Permalink
chore: coding style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwickdey committed Dec 25, 2024
1 parent d22a42e commit e277c00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
15 changes: 10 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}

function storeConfigToLocalStorage(data) {
chrome.storage.local.set({ [SETUP_STRING]: data || {} });
// return promise
return chrome.storage.local.set({ [SETUP_STRING]: data || {} })
}

function getConfigFromLocalStorage() {
Expand All @@ -35,10 +36,14 @@
sendMsgToAllContainPage('live-server-config-updated', msg.data);
}
else if (msg.req === 'get-live-server-config') {
getConfigFromLocalStorage().then(
function (value) { sendResponse(value) },
function (error) { console.error(`Error: ${error}`) }
);
getConfigFromLocalStorage()
.then(function (value) {
sendResponse(value)
})
.catch(function (error) {
console.error("Error in get-live-server-config:",error);
sendResponse({})
});
}
return true; //Keep the callback(sendResponse) active
});
Expand Down
25 changes: 11 additions & 14 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
liveServerUrl: liveServerAddress.value || ''
}

if (chrome && chrome.runtime) {
chrome.runtime.sendMessage({
req: 'set-live-server-config',
data: formData
});
}
chrome.runtime.sendMessage({
req: 'set-live-server-config',
data: formData
});

}

liveReloadCheck.onclick = () => {
Expand All @@ -41,13 +40,12 @@
chrome.runtime.sendMessage({
req: 'get-live-server-config'
}, (data) => {
if (data) {
liveReloadCheck.checked = data.isEnable || false;
noProxyCheckBox.checked = !data.proxySetup;
actualServerAddress.value = data.actualUrl || '';
liveServerAddress.value = data.liveServerUrl || '';
serverSetupDiv.className = noProxyCheckBox.checked ? 'show' : 'hide';
}
if (!data) return
liveReloadCheck.checked = data.isEnable || false;
noProxyCheckBox.checked = !data.proxySetup;
actualServerAddress.value = data.actualUrl || '';
liveServerAddress.value = data.liveServerUrl || '';
serverSetupDiv.className = noProxyCheckBox.checked ? 'show' : 'hide';
});
});

Expand All @@ -62,5 +60,4 @@
submitBtn.classList.add('btn-highlight');
}


})();

0 comments on commit e277c00

Please sign in to comment.