2017-02-14 15:35:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-04-04 17:21:03 +00:00
|
|
|
setupLivePrefs([
|
|
|
|
'show-badge',
|
|
|
|
'popup.stylesFirst',
|
|
|
|
'badgeNormal',
|
|
|
|
'badgeDisabled',
|
|
|
|
'popupWidth',
|
|
|
|
'updateInterval',
|
|
|
|
]);
|
2017-04-05 13:14:59 +00:00
|
|
|
enforceInputRange($('#popupWidth'));
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2017-03-25 06:30:34 +00:00
|
|
|
// overwrite the default URL if browser is Opera
|
2017-04-09 06:43:51 +00:00
|
|
|
$('[data-cmd="open-keyboard"]').href = URLS.configureCommands;
|
2017-02-14 15:35:53 +00:00
|
|
|
|
|
|
|
// actions
|
2017-03-25 06:30:34 +00:00
|
|
|
document.onclick = e => {
|
2017-04-14 15:30:09 +00:00
|
|
|
const target = e.target.closest('[data-cmd]');
|
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// prevent double-triggering in case a sub-element was clicked
|
|
|
|
e.stopPropagation();
|
2017-02-14 15:35:53 +00:00
|
|
|
|
2017-03-26 02:30:59 +00:00
|
|
|
function check() {
|
2017-04-14 15:30:09 +00:00
|
|
|
let total = 0;
|
|
|
|
let checked = 0;
|
|
|
|
let updated = 0;
|
|
|
|
$('#update-progress').style.width = 0;
|
|
|
|
$('#updates-installed').dataset.value = '';
|
|
|
|
document.body.classList.add('update-in-progress');
|
|
|
|
const maxWidth = $('#update-progress').parentElement.clientWidth;
|
2017-04-14 07:50:52 +00:00
|
|
|
function showProgress() {
|
2017-04-14 15:30:09 +00:00
|
|
|
$('#update-progress').style.width = Math.round(checked / total * maxWidth) + 'px';
|
|
|
|
$('#updates-installed').dataset.value = updated || '';
|
2017-04-14 07:50:52 +00:00
|
|
|
}
|
|
|
|
function done() {
|
2017-04-14 15:30:09 +00:00
|
|
|
document.body.classList.remove('update-in-progress');
|
2017-04-14 07:50:52 +00:00
|
|
|
}
|
2017-04-11 10:51:40 +00:00
|
|
|
BG.update.perform((cmd, value) => {
|
2017-03-28 10:05:58 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case 'count':
|
|
|
|
total = value;
|
|
|
|
if (!total) {
|
2017-04-14 07:50:52 +00:00
|
|
|
done();
|
2017-03-28 10:05:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'single-updated':
|
|
|
|
updated++;
|
2017-04-14 15:30:09 +00:00
|
|
|
// fallthrough
|
|
|
|
case 'single-skipped':
|
|
|
|
checked++;
|
|
|
|
if (total && checked === total) {
|
2017-04-14 07:50:52 +00:00
|
|
|
done();
|
2017-03-28 10:05:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
showProgress();
|
2017-02-14 15:35:53 +00:00
|
|
|
});
|
|
|
|
// notify the automatic updater to reset the next automatic update accordingly
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
method: 'resetInterval'
|
|
|
|
});
|
2017-03-26 02:30:59 +00:00
|
|
|
}
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-04-14 15:30:09 +00:00
|
|
|
switch (target.dataset.cmd) {
|
2017-03-26 02:30:59 +00:00
|
|
|
case 'open-manage':
|
|
|
|
openURL({url: '/manage.html'});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'check-updates':
|
|
|
|
check();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'open-keyboard':
|
2017-04-09 06:43:51 +00:00
|
|
|
openURL({url: e.target.href});
|
|
|
|
e.preventDefault();
|
2017-03-26 02:30:59 +00:00
|
|
|
break;
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-04-04 17:21:03 +00:00
|
|
|
case 'reset':
|
|
|
|
$$('input')
|
|
|
|
.filter(input => input.id in prefs.readOnlyValues)
|
|
|
|
.forEach(input => prefs.reset(input.id));
|
|
|
|
break;
|
2017-02-15 05:48:47 +00:00
|
|
|
}
|
2017-03-25 06:30:34 +00:00
|
|
|
};
|