kicanvas icon indicating copy to clipboard operation
kicanvas copied to clipboard

[Feature] Detect local file access problems

Open set-soft opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. When using KiCanvas as an embedding and loading the HTML from a local file system the user will most probably get an empty screen, wondering what was wrong.

Describe the solution you'd like It would be nice if KiCanvas could just inform the problem.

I'm not a Java Script guru, but here is a probe of concept showing how to inform the problem:

function ready()
{
 try
   {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', '1.kicad_sch', false);
    xmlhttp.send();
   }
 catch (error)
   {
    if (window.location.protocol === 'file:')
      {
       document.getElementById('no_file_access').style.display = 'block';
      }
    throw(error);
   }
}

window.addEventListener('DOMContentLoaded', ready);

Here '1.kicad_sch' is just one of the sources. Then in the HTML I have:

     <div id="no_file_access" style="display: none; ">
       <span>The browser can't read local files. Enable it to continue. I.e. use <i>--allow-file-access-from-files</i> on Chrome</span>
     </div>

Here is a working example: example.zip

I think a similar mechanism should be inside kicanvas.js, perhaps with an option to disable it, just in case the user wants to make it in a different way.

set-soft avatar Jan 31 '24 12:01 set-soft