allow live-reload on localhost and updates on file://
...if file access is allowed
This commit is contained in:
parent
7ad3f94697
commit
b17eef4053
|
@ -175,6 +175,8 @@ msg.on((msg, sender) => {
|
|||
//#endregion
|
||||
|
||||
Promise.all([
|
||||
browser.extension.isAllowedFileSchemeAccess()
|
||||
.then(res => API.data.set('hasFileAccess', res)),
|
||||
bgReady.styles,
|
||||
/* These are loaded conditionally.
|
||||
Each item uses `require` individually so IDE can jump to the source and track usage. */
|
||||
|
|
|
@ -223,7 +223,9 @@ const updateMan = (() => {
|
|||
let err;
|
||||
if (!delta && !ignoreDigest) {
|
||||
// re-install is invalid in a soft upgrade
|
||||
err = response === style.sourceCode ? STATES.SAME_CODE : STATES.SAME_VERSION;
|
||||
err = response === style.sourceCode
|
||||
? STATES.SAME_CODE
|
||||
: !URLS.isLocalhost(updateUrl) && STATES.SAME_VERSION;
|
||||
}
|
||||
if (delta < 0) {
|
||||
// downgrade is always invalid
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* global $ $create $createLink $$remove showSpinner */// dom.js
|
||||
/* global API */// msg.js
|
||||
/* global closeCurrentTab deepEqual */// toolbox.js
|
||||
/* global URLS closeCurrentTab deepEqual */// toolbox.js
|
||||
/* global messageBox */
|
||||
/* global prefs */
|
||||
/* global preinit */
|
||||
|
@ -61,12 +61,18 @@ setTimeout(() => !cm && showSpinner($('#header')), 200);
|
|||
'/js/color/color-view',
|
||||
]));
|
||||
|
||||
({tabId, initialUrl} = await preinit);
|
||||
({tabId, initialUrl} = preinit);
|
||||
liveReload = initLiveReload();
|
||||
|
||||
const {dup, style, error, sourceCode} = await preinit.ready;
|
||||
const [
|
||||
{dup, style, error, sourceCode},
|
||||
hasFileAccess,
|
||||
] = await Promise.all([
|
||||
preinit.ready,
|
||||
API.data.get('hasFileAccess'),
|
||||
]);
|
||||
if (!style && sourceCode == null) {
|
||||
messageBox.alert(isNaN(error) ? error : 'HTTP Error ' + error, 'pre');
|
||||
messageBox.alert(isNaN(error) ? `${error}` : 'HTTP Error ' + error, 'pre');
|
||||
return;
|
||||
}
|
||||
await scriptsReady;
|
||||
|
@ -118,7 +124,7 @@ setTimeout(() => !cm && showSpinner($('#header')), 200);
|
|||
checker.checked = true;
|
||||
// there is no way to "unset" updateUrl, you can only overwrite it.
|
||||
checker.disabled = true;
|
||||
} else if (updateUrl.protocol !== 'file:') {
|
||||
} else if (updateUrl.protocol !== 'file:' || hasFileAccess) {
|
||||
checker.checked = true;
|
||||
style.updateUrl = updateUrl.href;
|
||||
}
|
||||
|
@ -129,7 +135,7 @@ setTimeout(() => !cm && showSpinner($('#header')), 200);
|
|||
$('.set-update-url p').textContent = updateUrl.href.length < 300 ? updateUrl.href :
|
||||
updateUrl.href.slice(0, 300) + '...';
|
||||
|
||||
if (initialUrl.startsWith('file:')) {
|
||||
if (URLS.isLocalhost(initialUrl)) {
|
||||
$('.live-reload input').onchange = liveReload.onToggled;
|
||||
} else {
|
||||
$('.live-reload').remove();
|
||||
|
|
|
@ -25,7 +25,10 @@ const preinit = (() => {
|
|||
function DirectDownloader() {
|
||||
let oldCode = null;
|
||||
return async () => {
|
||||
const code = await download(initialUrl);
|
||||
const code = await download(initialUrl, {
|
||||
// Disabling cache on http://localhost otherwise the recheck delay gets too big
|
||||
headers: {'Cache-Control': 'no-cache, no-store'},
|
||||
});
|
||||
if (oldCode !== code) {
|
||||
oldCode = code;
|
||||
return code;
|
||||
|
|
|
@ -115,6 +115,8 @@ const URLS = {
|
|||
url.startsWith(URLS.ownOrigin) ||
|
||||
!URLS.chromeProtectsNTP && url.startsWith('chrome://newtab/')
|
||||
),
|
||||
|
||||
isLocalhost: url => /^file:|^https?:\/\/(localhost|127\.0\.0\.1)\//.test(url),
|
||||
};
|
||||
|
||||
const RX_META = /\/\*!?\s*==userstyle==[\s\S]*?==\/userstyle==\s*\*\//i;
|
||||
|
|
Loading…
Reference in New Issue
Block a user