show busy indicator badge text

This commit is contained in:
Alex Adam 2018-01-09 21:48:22 +02:00
parent 745a2b7ada
commit 1db3b504ec

View file

@ -1,12 +1,23 @@
var isBusy = false;
chrome.commands.onCommand.addListener(function(command) { chrome.commands.onCommand.addListener(function(command) {
// alert(isBusy)
if (isBusy) {
alert('BUSY')
return;
}
if (command === 'save-page') { if (command === 'save-page') {
dispatch('extract-page', false, false); dispatch('extract-page', false, false);
isBusy = true;
} else if (command === 'save-selection') { } else if (command === 'save-selection') {
dispatch('extract-selection', false, false); dispatch('extract-selection', false, false);
isBusy = true;
} else if (command === 'add-page') { } else if (command === 'add-page') {
dispatch('extract-page', true, false); dispatch('extract-page', true, false);
isBusy = true;
} else if (command === 'add-selection') { } else if (command === 'add-selection') {
dispatch('extract-selection', true, false); dispatch('extract-selection', true, false);
isBusy = true;
} }
}); });
@ -14,6 +25,9 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
if (!justAddToBuffer) { if (!justAddToBuffer) {
removeEbook(); removeEbook();
} }
chrome.browserAction.setBadgeBackgroundColor({color:"red"});
chrome.browserAction.setBadgeText({text: "Busy"});
chrome.tabs.query({ chrome.tabs.query({
currentWindow: true, currentWindow: true,
active: true active: true
@ -51,9 +65,14 @@ function sendMessage(tabId, action, justAddToBuffer, appliedStyles) {
} else { } else {
alert('Cannot generate the eBook from an empty selection!'); alert('Cannot generate the eBook from an empty selection!');
} }
isBusy = false;
chrome.browserAction.setBadgeText({text: ""});
return;
} }
if (!justAddToBuffer) { if (!justAddToBuffer) {
buildEbook([response]); buildEbook([response]);
isBusy = false;
chrome.browserAction.setBadgeText({text: ""});
} else { } else {
chrome.storage.local.get('allPages', function (data) { chrome.storage.local.get('allPages', function (data) {
if (!data || !data.allPages) { if (!data || !data.allPages) {
@ -61,6 +80,8 @@ function sendMessage(tabId, action, justAddToBuffer, appliedStyles) {
} }
data.allPages.push(response); data.allPages.push(response);
chrome.storage.local.set({'allPages': data.allPages}); chrome.storage.local.set({'allPages': data.allPages});
isBusy = false;
chrome.browserAction.setBadgeText({text: ""});
alert('Page or selection added as chapter!') alert('Page or selection added as chapter!')
}) })
} }