Fix bulk updates
This commit is contained in:
parent
a0ba63bb19
commit
403049692c
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
const retrying = new Set();
|
const retrying = new Set();
|
||||||
|
|
||||||
API_METHODS.updateCheckAll = checkAllStyles;
|
API_METHODS.updateCheckBulk = checkBulkStyles;
|
||||||
API_METHODS.updateCheck = checkStyle;
|
API_METHODS.updateCheck = checkStyle;
|
||||||
API_METHODS.getUpdaterStates = () => STATES;
|
API_METHODS.getUpdaterStates = () => STATES;
|
||||||
|
|
||||||
|
@ -39,18 +39,22 @@
|
||||||
schedule();
|
schedule();
|
||||||
chrome.alarms.onAlarm.addListener(onAlarm);
|
chrome.alarms.onAlarm.addListener(onAlarm);
|
||||||
|
|
||||||
return {checkAllStyles, checkStyle, STATES};
|
return {checkBulkStyles, checkStyle, STATES};
|
||||||
|
|
||||||
function checkAllStyles({
|
function checkBulkStyles({
|
||||||
save = true,
|
save = true,
|
||||||
ignoreDigest,
|
ignoreDigest,
|
||||||
observe,
|
observe,
|
||||||
|
styleIds = [],
|
||||||
} = {}) {
|
} = {}) {
|
||||||
resetInterval();
|
resetInterval();
|
||||||
checkingAll = true;
|
checkingAll = true;
|
||||||
retrying.clear();
|
retrying.clear();
|
||||||
const port = observe && chrome.runtime.connect({name: 'updater'});
|
const port = observe && chrome.runtime.connect({name: 'updater'});
|
||||||
return styleManager.getAllStyles().then(styles => {
|
return styleManager.getAllStyles().then(styles => {
|
||||||
|
if (styleIds.length) {
|
||||||
|
styles = styles.filter(style => styleIds.includes(style.id));
|
||||||
|
}
|
||||||
styles = styles.filter(style => style.updateUrl);
|
styles = styles.filter(style => style.updateUrl);
|
||||||
if (port) port.postMessage({count: styles.length});
|
if (port) port.postMessage({count: styles.length});
|
||||||
log('');
|
log('');
|
||||||
|
@ -247,7 +251,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAlarm({name}) {
|
function onAlarm({name}) {
|
||||||
if (name === ALARM_NAME) checkAllStyles();
|
if (name === ALARM_NAME) checkBulkStyles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetInterval() {
|
function resetInterval() {
|
||||||
|
|
|
@ -427,7 +427,7 @@
|
||||||
<!-- Bulk update -->
|
<!-- Bulk update -->
|
||||||
<span data-bulk="update">
|
<span data-bulk="update">
|
||||||
<button id="apply-all-updates" class="hidden" i18n-text="applyAllUpdates"></button>
|
<button id="apply-all-updates" class="hidden" i18n-text="applyAllUpdates"></button>
|
||||||
<span id="update-all-no-updates" class="hidden" i18n-text="updateAllCheckSucceededNoUpdate"></span>
|
<span id="update-all-no-updates" class="tt-e hidden" i18n-text="updateAllCheckSucceededNoUpdate"></span>
|
||||||
<button id="check-all-updates-force" class="hidden" i18n-text="checkAllUpdatesForce"></button>
|
<button id="check-all-updates-force" class="hidden" i18n-text="checkAllUpdatesForce"></button>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global $ $$ API t prefs handleEvent installed exportToFile checkUpdate exportDropbox
|
/* global $ $$ API t prefs handleEvent installed exportToFile checkUpdateBulk exportDropbox
|
||||||
messageBox */
|
messageBox */
|
||||||
/* exported bulk */
|
/* exported bulk */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -11,6 +11,16 @@ const bulk = {
|
||||||
$('#bulk-actions-apply').onclick = bulk.handleApply;
|
$('#bulk-actions-apply').onclick = bulk.handleApply;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
checkApply: () => {
|
||||||
|
const checkedEntries = $$('.entry-filter-toggle').filter(entry => entry.checked);
|
||||||
|
if (checkedEntries.length > 0 && $('#bulk-actions-select').value !== '') {
|
||||||
|
$('#bulk-actions-apply').removeAttribute('disabled');
|
||||||
|
} else {
|
||||||
|
$('#bulk-actions-apply').setAttribute('disabled', true);
|
||||||
|
}
|
||||||
|
$('#bulk-filter-count').textContent = checkedEntries.length || '';
|
||||||
|
},
|
||||||
|
|
||||||
handleSelect: event => {
|
handleSelect: event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$$('[data-bulk]').forEach(el => el.classList.add('hidden'));
|
$$('[data-bulk]').forEach(el => el.classList.add('hidden'));
|
||||||
|
@ -60,22 +70,25 @@ const bulk = {
|
||||||
return exportToFile(styles);
|
return exportToFile(styles);
|
||||||
}
|
}
|
||||||
case 'update':
|
case 'update':
|
||||||
styles = entries.map(entry => entry.styleMeta);
|
checkUpdateBulk();
|
||||||
checkUpdate(styles); // TO DO: don't check all styles
|
|
||||||
break;
|
break;
|
||||||
// case 'reset':
|
// case 'reset':
|
||||||
// break;
|
// break;
|
||||||
case 'delete':
|
case 'delete': {
|
||||||
styles = entries.reduce((acc, entry) => {
|
styles = entries.reduce((acc, entry) => {
|
||||||
const style = entry.styleMeta;
|
const style = entry.styleMeta;
|
||||||
acc[style.name] = style.id;
|
acc[style.id] = style.name;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
bulk.deleteBulk(event, styles);
|
bulk.deleteBulk(event, styles);
|
||||||
$('#toggle-all-filters').checked = false;
|
const toggle = $('#toggle-all-filters');
|
||||||
|
toggle.checked = false;
|
||||||
|
toggle.indeterminate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$('#bulk-actions-select').value = '';
|
$('#bulk-actions-select').value = '';
|
||||||
|
$('#bulk-actions-apply').setAttribute('disabled', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateBulkFilters: ({target}) => {
|
updateBulkFilters: ({target}) => {
|
||||||
|
@ -102,27 +115,20 @@ const bulk = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const count = $$('.entry-filter-toggle').filter(entry => entry.checked).length;
|
bulk.checkApply();
|
||||||
$('#bulk-filter-count').textContent = count || '';
|
|
||||||
|
|
||||||
if (count > 0 && $('#bulk-actions-select').value !== '') {
|
|
||||||
$('#bulk-actions-apply').removeAttribute('disabled');
|
|
||||||
} else {
|
|
||||||
$('#bulk-actions-apply').setAttribute('disabled', true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteBulk: (event, styles) => {
|
deleteBulk: (event, styles) => {
|
||||||
messageBox({
|
messageBox({
|
||||||
title: t('deleteStyleConfirm'),
|
title: t('deleteStyleConfirm'),
|
||||||
contents: Object.keys(styles).join(', '),
|
contents: Object.values(styles).join(', '),
|
||||||
className: 'danger center',
|
className: 'danger center',
|
||||||
buttons: [t('confirmDelete'), t('confirmCancel')],
|
buttons: [t('confirmDelete'), t('confirmCancel')],
|
||||||
})
|
})
|
||||||
.then(({button}) => {
|
.then(({button}) => {
|
||||||
if (button === 0) {
|
if (button === 0) {
|
||||||
Object.values(styles).forEach(id => API.deleteStyle(id));
|
Object.keys(styles).forEach(id => API.deleteStyle(Number(id)));
|
||||||
installed.dataset.total -= Object.keys(styles).length;
|
installed.dataset.total -= Object.keys(styles).length;
|
||||||
bulk.updateBulkFilters({target: $('#toggle-all-filters')});
|
bulk.updateBulkFilters({target: $('#toggle-all-filters')});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ global messageBox getStyleWithNoCode
|
||||||
URLS enforceInputRange t
|
URLS enforceInputRange t
|
||||||
getOwnTab getActiveTab openURL animateElement sessionStorageHash debounce
|
getOwnTab getActiveTab openURL animateElement sessionStorageHash debounce
|
||||||
scrollElementIntoView FIREFOX
|
scrollElementIntoView FIREFOX
|
||||||
UI
|
UI bulk
|
||||||
*/
|
*/
|
||||||
/* exported updateInjectionOrder */
|
/* exported updateInjectionOrder */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -305,7 +305,7 @@ Object.assign(handleEvent, {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const box = $('#message-box')
|
const box = $('#message-box');
|
||||||
box.removeEventListener('change', handleEvent.manageFavicons);
|
box.removeEventListener('change', handleEvent.manageFavicons);
|
||||||
box.removeEventListener('input', handleEvent.manageFavicons);
|
box.removeEventListener('input', handleEvent.manageFavicons);
|
||||||
});
|
});
|
||||||
|
@ -339,6 +339,8 @@ function handleUpdate(style, {reason, method} = {}) {
|
||||||
}
|
}
|
||||||
entry = entry || UI.createStyleElement({style});
|
entry = entry || UI.createStyleElement({style});
|
||||||
if (oldEntry) {
|
if (oldEntry) {
|
||||||
|
// Make sure to update the filter checkbox since it's state isn't saved to the style
|
||||||
|
$('.entry-filter-toggle', entry).checked = $('.entry-filter-toggle', oldEntry).checked;
|
||||||
if (oldEntry.styleNameLowerCase === entry.styleNameLowerCase) {
|
if (oldEntry.styleNameLowerCase === entry.styleNameLowerCase) {
|
||||||
installed.replaceChild(entry, oldEntry);
|
installed.replaceChild(entry, oldEntry);
|
||||||
} else {
|
} else {
|
||||||
|
@ -349,6 +351,7 @@ function handleUpdate(style, {reason, method} = {}) {
|
||||||
handleUpdateInstalled(entry, reason);
|
handleUpdateInstalled(entry, reason);
|
||||||
}
|
}
|
||||||
filterAndAppend({entry}).then(sorter.update);
|
filterAndAppend({entry}).then(sorter.update);
|
||||||
|
|
||||||
if (!entry.matches('.hidden') && reason !== 'import') {
|
if (!entry.matches('.hidden') && reason !== 'import') {
|
||||||
animateElement(entry);
|
animateElement(entry);
|
||||||
requestAnimationFrame(() => scrollElementIntoView(entry));
|
requestAnimationFrame(() => scrollElementIntoView(entry));
|
||||||
|
@ -421,7 +424,6 @@ function switchUI({styleOnly} = {}) {
|
||||||
for (const targets of $$('.entry .targets')) {
|
for (const targets of $$('.entry .targets')) {
|
||||||
const items = $$('.target', targets);
|
const items = $$('.target', targets);
|
||||||
const extra = $('.applies-to-extra', targets);
|
const extra = $('.applies-to-extra', targets);
|
||||||
const x = items.length === 54;
|
|
||||||
items.splice(0, UI.targets).forEach(el => {
|
items.splice(0, UI.targets).forEach(el => {
|
||||||
if (!el.parentElement.classList.contains('targets')) {
|
if (!el.parentElement.classList.contains('targets')) {
|
||||||
targets.insertBefore(el, extra);
|
targets.insertBefore(el, extra);
|
||||||
|
|
|
@ -32,13 +32,13 @@ const UI = {
|
||||||
$('.ext-version').textContent = `v${chrome.runtime.getManifest().version}`;
|
$('.ext-version').textContent = `v${chrome.runtime.getManifest().version}`;
|
||||||
|
|
||||||
// translate CSS manually
|
// translate CSS manually
|
||||||
|
// #update-all-no-updates[data-skipped-edited="true"]::after {
|
||||||
|
// content: " ${t('updateAllCheckSucceededSomeEdited')}";
|
||||||
|
// }
|
||||||
document.head.appendChild($create('style', `
|
document.head.appendChild($create('style', `
|
||||||
body.all-styles-hidden-by-filters #installed:after {
|
body.all-styles-hidden-by-filters #installed:after {
|
||||||
content: "${t('filteredStylesAllHidden')}";
|
content: "${t('filteredStylesAllHidden')}";
|
||||||
}
|
}
|
||||||
#update-all-no-updates[data-skipped-edited="true"]::after {
|
|
||||||
content: " ${t('updateAllCheckSucceededSomeEdited')}";
|
|
||||||
}
|
|
||||||
`));
|
`));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
/* exported handleUpdateInstalled */
|
/* exported handleUpdateInstalled */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
let updateTimer;
|
||||||
|
|
||||||
onDOMready().then(() => {
|
onDOMready().then(() => {
|
||||||
// $('#check-all-updates').onclick = checkUpdateAll;
|
$('#check-all-updates-force').onclick = checkUpdateBulk;
|
||||||
$('#check-all-updates-force').onclick = checkUpdateAll;
|
|
||||||
$('#apply-all-updates').onclick = applyUpdateAll;
|
$('#apply-all-updates').onclick = applyUpdateAll;
|
||||||
$('#update-history').onclick = showUpdateHistory;
|
$('#update-history').onclick = showUpdateHistory;
|
||||||
});
|
});
|
||||||
|
@ -27,17 +28,18 @@ function applyUpdateAll() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function checkUpdateAll() {
|
function checkUpdateBulk() {
|
||||||
|
clearTimeout(updateTimer);
|
||||||
document.body.classList.add('update-in-progress');
|
document.body.classList.add('update-in-progress');
|
||||||
// const btnCheck = $('#check-all-updates');
|
// const btnCheck = $('#check-all-updates');
|
||||||
const btnCheckForce = $('#check-all-updates-force');
|
const btnCheckForce = $('#check-all-updates-force');
|
||||||
const btnApply = $('#apply-all-updates');
|
const btnApply = $('#apply-all-updates');
|
||||||
const noUpdates = $('#update-all-no-updates');
|
const noUpdates = $('#update-all-no-updates');
|
||||||
|
const styleIds = $$('.entry-filter-toggle:checked').map(el => el.closest('.entry').styleMeta.id);
|
||||||
// btnCheck.disabled = true;
|
// btnCheck.disabled = true;
|
||||||
btnCheckForce.classList.add('hidden');
|
btnCheckForce.classList.add('hidden');
|
||||||
btnApply.classList.add('hidden');
|
btnApply.classList.add('hidden');
|
||||||
noUpdates.classList.add('hidden');
|
noUpdates.classList.add('hidden');
|
||||||
|
|
||||||
const ignoreDigest = this && this.id === 'check-all-updates-force';
|
const ignoreDigest = this && this.id === 'check-all-updates-force';
|
||||||
$$('.updatable:not(.can-update)' + (ignoreDigest ? '' : ':not(.update-problem)'))
|
$$('.updatable:not(.can-update)' + (ignoreDigest ? '' : ':not(.update-problem)'))
|
||||||
.map(checkUpdate);
|
.map(checkUpdate);
|
||||||
|
@ -53,10 +55,11 @@ function checkUpdateAll() {
|
||||||
chrome.runtime.onConnect.removeListener(onConnect);
|
chrome.runtime.onConnect.removeListener(onConnect);
|
||||||
});
|
});
|
||||||
|
|
||||||
API.updateCheckAll({
|
API.updateCheckBulk({
|
||||||
save: false,
|
save: false,
|
||||||
observe: true,
|
observe: true,
|
||||||
ignoreDigest,
|
ignoreDigest,
|
||||||
|
styleIds,
|
||||||
});
|
});
|
||||||
|
|
||||||
function observer(info, port) {
|
function observer(info, port) {
|
||||||
|
@ -86,9 +89,15 @@ function checkUpdateAll() {
|
||||||
btnApply.disabled = false;
|
btnApply.disabled = false;
|
||||||
renderUpdatesOnlyFilter({check: updated + skippedEdited > 0});
|
renderUpdatesOnlyFilter({check: updated + skippedEdited > 0});
|
||||||
if (!updated) {
|
if (!updated) {
|
||||||
noUpdates.dataset.skippedEdited = skippedEdited > 0;
|
if (skippedEdited > 0) {
|
||||||
|
noUpdates.dataset.title = t('updateAllCheckSucceededSomeEdited');
|
||||||
|
}
|
||||||
noUpdates.classList.remove('hidden');
|
noUpdates.classList.remove('hidden');
|
||||||
btnCheckForce.classList.toggle('hidden', skippedEdited === 0);
|
btnCheckForce.classList.toggle('hidden', skippedEdited === 0);
|
||||||
|
updateTimer = setTimeout(() => {
|
||||||
|
noUpdates.classList.add('hidden');
|
||||||
|
noUpdates.dataset.title = '';
|
||||||
|
}, 1e4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ function checkUpdates() {
|
||||||
chrome.runtime.onConnect.removeListener(onConnect);
|
chrome.runtime.onConnect.removeListener(onConnect);
|
||||||
});
|
});
|
||||||
|
|
||||||
API.updateCheckAll({observe: true});
|
API.updateCheckBulk({observe: true});
|
||||||
|
|
||||||
function observer(info) {
|
function observer(info) {
|
||||||
if ('count' in info) {
|
if ('count' in info) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user