manage: show update history button

This commit is contained in:
tophf 2017-04-26 23:55:54 +03:00
parent c47e2af430
commit 809e70a89c
5 changed files with 61 additions and 7 deletions

View File

@ -80,6 +80,9 @@
"message": "Check again, I didn't edit any styles!", "message": "Check again, I didn't edit any styles!",
"description": "Label for the button to apply all detected updates" "description": "Label for the button to apply all detected updates"
}, },
"updateCheckHistory": {
"message": "History of update checks"
},
"checkForUpdate": { "checkForUpdate": {
"message": "Check for update", "message": "Check for update",
"description": "Label for the button to check a single style for an update" "description": "Label for the button to check a single style for an update"
@ -128,6 +131,10 @@
"message": "Disabled", "message": "Disabled",
"description": "Used in various lists/options to indicate that something is disabled" "description": "Used in various lists/options to indicate that something is disabled"
}, },
"genericHistoryLabel": {
"message": "History",
"description": "Used in various places to show a history log of something"
},
"confirmNo": { "confirmNo": {
"message": "No", "message": "No",
"description": "'No' button in a confirm dialog" "description": "'No' button in a confirm dialog"

View File

@ -66,13 +66,11 @@ a:hover {
height: 20px; height: 20px;
} }
.svg-icon, .svg-icon:hover {
.svg-icon.info:hover {
fill: #000; fill: #000;
} }
.svg-icon:hover, .svg-icon {
.svg-icon.info {
fill: #666; fill: #666;
} }
@ -607,6 +605,13 @@ fieldset > * {
margin-left: 1.5em; margin-left: 1.5em;
} }
.update-history-log {
font-size: 11px;
white-space: pre;
overflow-x: hidden;
text-overflow: ellipsis;
}
@keyframes fadein { @keyframes fadein {
from { from {
opacity: 0; opacity: 0;

View File

@ -158,6 +158,11 @@
</fieldset> </fieldset>
<p> <p>
<button id="check-all-updates" i18n-text="checkAllUpdates"><span id="update-progress"></span></button> <button id="check-all-updates" i18n-text="checkAllUpdates"><span id="update-progress"></span></button>
<span id="update-history" i18n-title="genericHistoryLabel">
<svg class="svg-icon" viewBox="0 0 20 20" i18n-alt="helpAlt">
<path d="M13,7H7V6h6Zm6,6.5A5.5,5.5,0,0,1,8.61,16H4V3H16V8.61A5.5,5.5,0,0,1,19,13.5ZM8,14c0-.16,0-.84,0-1H7V12H8.21a5.46,5.46,0,0,1,.39-1H7V10H9.26a5.55,5.55,0,0,1,1.09-1H7V8h7V5H6v9Zm10-.5A4.5,4.5,0,1,0,13.5,18,4.5,4.5,0,0,0,18,13.5ZM14,13V10H13v4h4V13Z"/>
</svg>
</span>
</p> </p>
<p> <p>
<button id="apply-all-updates" class="hidden" i18n-text="applyAllUpdates"></button> <button id="apply-all-updates" class="hidden" i18n-text="applyAllUpdates"></button>

View File

@ -53,6 +53,7 @@ function initGlobalEvents() {
$('#check-all-updates').onclick = checkUpdateAll; $('#check-all-updates').onclick = checkUpdateAll;
$('#check-all-updates-force').onclick = checkUpdateAll; $('#check-all-updates-force').onclick = checkUpdateAll;
$('#apply-all-updates').onclick = applyUpdateAll; $('#apply-all-updates').onclick = applyUpdateAll;
$('#update-history').onclick = showUpdateHistory;
$('#search').oninput = searchStyles; $('#search').oninput = searchStyles;
$('#manage-options-button').onclick = () => chrome.runtime.openOptionsPage(); $('#manage-options-button').onclick = () => chrome.runtime.openOptionsPage();
$('#manage-shortcuts-button').onclick = () => openURL({url: URLS.configureCommands}); $('#manage-shortcuts-button').onclick = () => openURL({url: URLS.configureCommands});
@ -675,6 +676,21 @@ function renderUpdatesOnlyFilter({show, check} = {}) {
} }
function showUpdateHistory() {
BG.chromeLocal.getValue('updateLog').then((lines = []) => {
messageBox({
title: t('updateCheckHistory'),
contents: $element({
className: 'update-history-log',
textContent: lines.join('\n'),
}),
buttons: [t('confirmOK')],
onshow: () => ($('#message-box-contents').scrollTop = 1e9),
});
});
}
function searchStyles({immediately, container}) { function searchStyles({immediately, container}) {
const searchElement = $('#search'); const searchElement = $('#search');
const query = searchElement.value.toLocaleLowerCase(); const query = searchElement.value.toLocaleLowerCase();

View File

@ -1,4 +1,4 @@
/* global getStyles, saveStyle, styleSectionsEqual */ /* global getStyles, saveStyle, styleSectionsEqual, chromeLocal */
/* global getStyleDigests, updateStyleDigest */ /* global getStyleDigests, updateStyleDigest */
'use strict'; 'use strict';
@ -25,11 +25,13 @@ var updater = {
return getStyles({}).then(styles => { return getStyles({}).then(styles => {
styles = styles.filter(style => style.updateUrl); styles = styles.filter(style => style.updateUrl);
observer(updater.COUNT, styles.length); observer(updater.COUNT, styles.length);
updater.log(`${save ? 'Scheduled' : 'Manual'} update check for ${styles.length} styles`);
return Promise.all( return Promise.all(
styles.map(style => styles.map(style =>
updater.checkStyle({style, observer, save, ignoreDigest}))); updater.checkStyle({style, observer, save, ignoreDigest})));
}).then(() => { }).then(() => {
observer(updater.DONE); observer(updater.DONE);
updater.log('');
}); });
}, },
@ -53,8 +55,15 @@ var updater = {
.then(fetchMd5IfNotEdited) .then(fetchMd5IfNotEdited)
.then(fetchCodeIfMd5Changed) .then(fetchCodeIfMd5Changed)
.then(saveIfUpdated) .then(saveIfUpdated)
.then(saved => observer(updater.UPDATED, saved)) .then(saved => {
.catch(err => observer(updater.SKIPPED, style, err)); observer(updater.UPDATED, saved);
updater.log(updater.UPDATED + ` #${saved.id} ${saved.name}`);
})
.catch(err => {
observer(updater.SKIPPED, style, err);
err = err === 0 ? 'server unreachable' : err;
updater.log(updater.SKIPPED + ` (${err}) #${style.id} ${style.name}`);
});
function fetchMd5IfNotEdited([originalDigest, current]) { function fetchMd5IfNotEdited([originalDigest, current]) {
hasDigest = Boolean(originalDigest); hasDigest = Boolean(originalDigest);
@ -118,6 +127,18 @@ var updater = {
localStorage.lastUpdateTime = updater.lastUpdateTime = Date.now(); localStorage.lastUpdateTime = updater.lastUpdateTime = Date.now();
updater.schedule(); updater.schedule();
}, },
log(text) {
chromeLocal.getValue('updateLog').then((lines = []) => {
const time = text && performance.now() - (updater.log.lastWriteTime || 0) > 10e3
? new Date().toLocaleString() + '\t'
: '';
lines.splice(0, lines.length - 1000);
lines.push(time + text);
chromeLocal.setValue('updateLog', lines);
updater.log.lastWriteTime = performance.now();
});
},
}; };
updater.schedule(); updater.schedule();