Fix: add set updateUrl option

This commit is contained in:
eight 2017-09-19 08:23:47 +08:00
parent ba4c06ae82
commit 0852b56ce4
3 changed files with 48 additions and 5 deletions

View File

@ -405,6 +405,19 @@
"message": "Install update",
"description": "Label for the button to install an update for a single style"
},
"installUpdateFrom": {
"message": "Currently the style is updated from $url$",
"description": "Label to describe where the style gets update",
"placeholders": {
"url": {
"content": "$1"
}
}
},
"installUpdateFromLabel": {
"message": "Install update from this URL",
"description": "Label for the checkbox to save current URL for update check"
},
"license": {
"message": "License",
"description": "Label for the license"

View File

@ -49,7 +49,7 @@ h1 small {
margin: 15px 0;
}
.live-reload {
.actions label {
width: fit-content;
width: -moz-fit-content;
display: flex;
@ -57,7 +57,7 @@ h1 small {
margin: 0.5em 0;
}
.live-reload input {
.actions label input {
margin: 0 0.5em 0 0;
}

View File

@ -7,8 +7,7 @@ let pendingResource;
function install(style) {
const request = Object.assign(style, {
method: 'saveUsercss',
reason: 'update',
updateUrl: location.protocol === 'file:' ? null : location.href
reason: 'update'
});
return runtimeSend(request)
.then(result => {
@ -17,6 +16,9 @@ function install(style) {
$('button.install').textContent = 'Installed';
$('button.install').disabled = true;
$('button.install').classList.add('installed');
$('.set-update-url').disabled = true;
$('.set-update-url-label').title = result.updateUrl ?
t('installUpdateFrom', result.updateUrl) : '';
window.dispatchEvent(new CustomEvent('installed', {detail: result}));
})
.catch(err => {
@ -76,6 +78,21 @@ function initInstallPage({style, dup}, sourceLoader) {
install(style);
}
};
if (dup && dup.updateUrl === location.href) {
$('.set-update-url').checked = true;
// there is no way to "unset" updateUrl, you can only overwrite it.
$('.set-update-url').disabled = true;
} else if (!dup && location.protocol !== 'file:') {
$('.set-update-url').checked = true;
style.updateUrl = location.href;
}
$('.set-update-url').onchange = e => {
if (e.target.checked) {
style.updateUrl = location.href;
} else {
delete style.updateUrl;
}
};
if (location.protocol === 'file:') {
initLiveReload(sourceLoader);
@ -85,7 +102,20 @@ function initInstallPage({style, dup}, sourceLoader) {
return $element({className: 'container', appendChild: [
$element({className: 'header', appendChild: [
$element({className: 'actions', appendChild: [
$element({tag: 'button', className: 'install', textContent: installButtonLabel()})
$element({tag: 'button', className: 'install', textContent: installButtonLabel()}),
$element({
tag: 'label',
title: dup && dup.updateUrl && t('installUpdateFrom', dup.updateUrl) || '',
className: 'set-update-url-label',
appendChild: [
$element({
tag: 'input',
type: 'checkbox',
className: 'set-update-url'
}),
$element({tag: 'span', textContent: t('installUpdateFromLabel')})
]
})
]}),
$element({tag: 'h1', appendChild: [
data.name,