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", "message": "Check for updates",
"description": "Label for the checkbox to save current URL for update check" "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": { "license": {
"message": "License", "message": "License",
"description": "Label for the license" "description": "Label for the license"
@ -611,6 +614,9 @@
"message": "An error occurred while watching the file", "message": "An error occurred while watching the file",
"description": "The label of live-reload error" "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": { "manageFilters": {
"message": "Filters", "message": "Filters",
"description": "Label for filters container" "description": "Label for filters container"

View File

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

View File

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