Improve compatibility with file: protocol

main
Isaiah Odhner 2021-01-29 21:34:13 -05:00
parent 8ec952f170
commit ea3b98f8d3
3 changed files with 37 additions and 10 deletions

View File

@ -79,10 +79,15 @@ function set_all_url_params(params, {replace_history_state=false}={}) {
// This is desired for upgrading backwards compatibility URLs;
// may not be desired for future cases.
const new_url = `${location.origin}${location.pathname}#${new_hash}`;
if (replace_history_state) {
history.replaceState(null, document.title, new_url);
} else {
history.pushState(null, document.title, new_url);
try {
// can fail when running from file: protocol
if (replace_history_state) {
history.replaceState(null, document.title, new_url);
} else {
history.pushState(null, document.title, new_url);
}
} catch(error) {
location.hash = new_hash;
}
$G.triggerHandler("change-url-params");

View File

@ -246,10 +246,31 @@ function open_help_viewer(options){
}
}
$.get(options.contentsFile, hhc => {
$($.parseHTML(hhc)).filter("ul").children().get().forEach((li)=> {
renderItem(li, null);
fetch(options.contentsFile).then((response)=> {
response.text().then((hhc)=> {
$($.parseHTML(hhc)).filter("ul").children().get().forEach((li)=> {
renderItem(li, null);
});
}, (error)=> {
show_error_message(`${localize("Failed to launch help.")} Failed to read ${options.contentsFile}.`, error);
});
}, (/* error */)=> {
// access to error message is not allowed either, basically
if (location.protocol === "file:") {
const $w = $FormToolWindow().title(localize("Paint")).addClass("dialogue-window");
$w.$main.html(`
<p>${localize("Failed to launch help.")}</p>
<p>This feature is not available when running from the <code>file:</code> protocol.</p>
<p>To use this feature, start a web server. If you have Python, you can use <code>python -m SimpleHTTPServer</code></p>
`);
$w.$main.css({maxWidth: "500px"});
$w.$Button(localize("OK"), () => {
$w.close();
});
$w.center();
} else {
show_error_message(`${localize("Failed to launch help.")} ${localize("Access to %1 was denied.", options.contentsFile)}`);
}
});
// @TODO: keyboard accessability

View File

@ -31,9 +31,10 @@ const ChooserCanvas = (
);
// eslint-disable-next-line no-empty
} catch(error) {}
if(invert){
invert_rgb(c.ctx);
}
// if(invert){
// invert_rgb(c.ctx); // can fail due to tainted canvas if running from file: protocol
// }
c.style.filter = invert ? "invert()" : "";
};
$(img).on("load", render);
render();