show the reason why update/liveReload is unavailable

fixes #458
This commit is contained in:
tophf 2018-08-01 14:36:36 +03:00
parent d8914c38a7
commit 35baf6f018
3 changed files with 16 additions and 5 deletions

View File

@ -528,6 +528,9 @@
"message": "Check for updates",
"description": "Label for the checkbox to save current URL for update check"
},
"installUpdateUnavailable": {
"message": "To enable check for updates, drop the file on the tab strip or specify @updateURL in the style metadata."
},
"license": {
"message": "License",
"description": "Label for the license"
@ -611,6 +614,9 @@
"message": "An error occurred while watching the file",
"description": "The label of live-reload error"
},
"liveReloadUnavailable": {
"message": "To enable live reload, drop the file on the tab strip (the area where the tab titles are shown)."
},
"manageFilters": {
"message": "Filters",
"description": "Label for filters container"

View File

@ -306,7 +306,7 @@ li {
user-select: auto;
}
label {
label:not(.unavailable) {
padding-left: 16px;
position: relative;
}

View File

@ -3,6 +3,8 @@
'use strict';
(() => {
const DUMMY_URL = 'foo:';
// TODO: remove .replace(/^\?/, '') when minimum_chrome_version >= 52 (https://crbug.com/601425)
const params = new URLSearchParams(location.search.replace(/^\?/, ''));
let liveReload = false;
@ -14,7 +16,8 @@
let port;
if (params.has('direct')) {
$('.live-reload').remove();
$('.live-reload').textContent = t('liveReloadUnavailable');
$('.live-reload').classList.add('unavailable');
getCodeDirectly();
} else {
port = chrome.tabs.connect(tabId);
@ -308,15 +311,17 @@
const checker = $('.set-update-url input[type=checkbox]');
// prefer the installation URL unless drag'n'dropped on the manage page
const installationUrl = (params.get('updateUrl') || '').replace(/^blob.+/, '');
const updateUrl = new URL(installationUrl || style.updateUrl || 'foo:bar');
const updateUrl = new URL(installationUrl || style.updateUrl || DUMMY_URL);
$('.set-update-url > span').textContent = t('installUpdateFromLabel');
if (dup && dup.updateUrl === updateUrl.href) {
checker.checked = true;
// there is no way to "unset" updateUrl, you can only overwrite it.
checker.disabled = true;
} else if (updateUrl.protocol === 'foo:') {
} else if (updateUrl.href === DUMMY_URL) {
// drag'n'dropped on the manage page and the style doesn't have @updateURL
checker.disabled = true;
$('.set-update-url').textContent = t('installUpdateUnavailable');
$('.set-update-url').classList.add('unavailable');
return;
} else if (updateUrl.protocol !== 'file:') {
checker.checked = true;
style.updateUrl = updateUrl.href;