request persistent permission more often, show dialog if not

This commit is contained in:
Steven Hugg 2020-07-12 23:54:09 -05:00
parent 85dc34eccb
commit f5a4844af3
3 changed files with 27 additions and 27 deletions

View File

@ -83,9 +83,11 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<hr> <hr>
<li><a class="dropdown-item" href="#" id="item_addfile_include">Add Include File...</a></li> <li><a class="dropdown-item" href="#" id="item_addfile_include">Add Include File...</a></li>
<li><a class="dropdown-item" href="#" id="item_addfile_link">Add Linked File...</a></li> <li><a class="dropdown-item" href="#" id="item_addfile_link">Add Linked File...</a></li>
<!--
<hr> <hr>
<li><a class="dropdown-item" href="#" id="item_switch_https" style="display:none">Switch to HTTPS...</a></li> <li><a class="dropdown-item" href="#" id="item_switch_https" style="display:none">Switch to HTTPS...</a></li>
<li><a class="dropdown-item" href="#" id="item_request_persist">Request Local Storage Permissions</a></li> <li><a class="dropdown-item" href="#" id="item_request_persist">Request Local Storage Permissions</a></li>
-->
</ul> </ul>
</li> </li>
<li class="dropdown dropdown-submenu"> <li class="dropdown dropdown-submenu">

View File

@ -6,29 +6,33 @@ const unsigned char LZG_LENGTH_DECODE_LUT[32] = {
18,19,20,21,22,23,24,25,26,27,28,29,35,48,72,128 18,19,20,21,22,23,24,25,26,27,28,29,35,48,72,128
}; };
#pragma codesize (200) // make code faster #pragma codesize (200) // make code faster?
unsigned char* lzg_decode_vram(const unsigned char* _src, unsigned char* lzg_decode_vram(const unsigned char* _src,
unsigned char* _dest, unsigned char* _dest,
unsigned char* _end) { unsigned char* _end) {
// copy params to static locals // copy params to static locals
const unsigned char* src = _src; register const unsigned char* src = _src;
unsigned char* dest = _dest; register unsigned char* dest = _dest;
unsigned char* end = _end; unsigned char* end = _end;
// more locals
char marker[4]; char marker[4];
unsigned int length, offset; unsigned int length, offset;
unsigned char sym, b, b2; unsigned char sym, b, b2;
unsigned char* copysrc;
// copy 4 marker bytes to locals
memcpy(marker, src, 4); memcpy(marker, src, 4);
src += 4; src += 4;
// loop until we run out of buffer space
while (dest < end) { while (dest < end) {
sym = *src++; sym = src[0];
b = *src++; b = src[1];
src += 2;
// copy commands // copy commands
offset = 0; offset = 0;
length = LZG_LENGTH_DECODE_LUT[b & 0x1f]; b2 = b & 0x1f;
length = LZG_LENGTH_DECODE_LUT[b2]; // required for aaaa,y
// look for marker symbols
if (sym == marker[0]) { if (sym == marker[0]) {
if (b == 0) goto literal; if (b == 0) goto literal;
b2 = *src++; b2 = *src++;
@ -55,8 +59,7 @@ literal:
length = end - dest; length = end - dest;
} }
// copy bytes // copy bytes
copysrc = dest - offset; memcpy(dest, dest - offset, length);
memcpy(dest, copysrc, length);
dest += length; dest += length;
} }
return dest; return dest;

View File

@ -122,18 +122,18 @@ var hasLocalStorage : boolean = function() {
}(); }();
// https://developers.google.com/web/updates/2016/06/persistent-storage // https://developers.google.com/web/updates/2016/06/persistent-storage
function requestPersistPermission(interactive: boolean) { function requestPersistPermission(interactive: boolean, failureonly: boolean) {
if (navigator.storage && navigator.storage.persist) { if (navigator.storage && navigator.storage.persist) {
navigator.storage.persist().then(persistent=>{ navigator.storage.persist().then(persistent=>{
console.log("requestPersistPermission =", persistent); console.log("requestPersistPermission =", persistent);
if (persistent) { if (persistent) {
interactive && alertInfo("Your browser says it will persist your local file edits, but you may want to back up your work anyway."); interactive && !failureonly && alertInfo("Your browser says it will persist your local file edits, but you may want to back up your work anyway.");
} else { } else {
interactive && alertInfo("Your browser won't agree to persist your local file edits. Make sure to back up your work periodically."); interactive && alertInfo("Your browser refused to expand the peristent storage quota. Your edits may not be preserved after closing the page.");
} }
}); });
} else { } else {
interactive && alertInfo("Your browser doesn't support expanding the persistent storage quota. Make sure to back up your work periodically."); interactive && alertInfo("Your browser doesn't support expanding the persistent storage quota. Your edits may not be preserved after closing the page.");
} }
} }
@ -339,6 +339,8 @@ async function loadProject(preset_id:string) {
// don't alert if we selected "new file" // don't alert if we selected "new file"
if (!qs['newfile']) { if (!qs['newfile']) {
alertInfo("Could not find file \"" + preset_id + "\". Loading default file."); alertInfo("Could not find file \"" + preset_id + "\". Loading default file.");
} else {
requestPersistPermission(true, true);
} }
delete qs['newfile']; delete qs['newfile'];
replaceURLState(); replaceURLState();
@ -1614,7 +1616,7 @@ function setupDebugControls() {
} }
$("#item_addfile_include").click(_addIncludeFile); $("#item_addfile_include").click(_addIncludeFile);
$("#item_addfile_link").click(_addLinkFile); $("#item_addfile_link").click(_addLinkFile);
$("#item_request_persist").click(() => requestPersistPermission(true)); $("#item_request_persist").click(() => requestPersistPermission(true, false));
updateDebugWindows(); updateDebugWindows();
// show help button? // show help button?
if (platform.showHelp) { if (platform.showHelp) {
@ -1734,8 +1736,8 @@ function showWelcomeMessage() {
{ {
element: "#workspace", element: "#workspace",
title: "Code Editor", title: "Code Editor",
content: is_vcs ? "Type your 6502 assembly code into the editor, and it'll be assembled in real-time. All changes are saved to browser local storage, except on Safari or iOS." content: is_vcs ? "Type your 6502 assembly code into the editor, and it'll be assembled in real-time."
: "Type your source code into the editor, and it'll be compiled in real-time. All changes are saved to browser local storage, except on Safari or iOS." : "Type your source code into the editor, and it'll be compiled in real-time."
}, },
{ {
element: "#emulator", element: "#emulator",
@ -1779,7 +1781,7 @@ function showWelcomeMessage() {
//storage:false, //storage:false,
steps:steps, steps:steps,
onEnd: () => { onEnd: () => {
requestPersistPermission(false); requestPersistPermission(false, true);
} }
}); });
setTimeout(() => { tour.start(); }, 2000); setTimeout(() => { tour.start(); }, 2000);
@ -1806,7 +1808,7 @@ function globalErrorHandler(msgevent) {
var msg = (msgevent.message || msgevent.error || msgevent)+""; var msg = (msgevent.message || msgevent.error || msgevent)+"";
// storage quota full? (Chrome) try to expand it // storage quota full? (Chrome) try to expand it
if (msg.indexOf("QuotaExceededError") >= 0) { if (msg.indexOf("QuotaExceededError") >= 0) {
requestPersistPermission(false); requestPersistPermission(false, false);
} else { } else {
showErrorAlert([{msg:msg,line:0}]); showErrorAlert([{msg:msg,line:0}]);
} }
@ -2025,14 +2027,6 @@ export async function startUI() {
importProjectFromGithub(qs['githubURL'], true); importProjectFromGithub(qs['githubURL'], true);
return; return;
} }
// warning when using Safari/iOS
if (hasLocalStorage && !localStorage.getItem("__applealert")) {
localStorage.setItem("__applealert", "true");
var browserResult = browserDetect();
if (browserResult.name == 'safari' || browserResult.name == 'ios') {
alertError("WARNING: This browser may not persist changes to source code. Try a recent version of Firefox or Chrome.");
}
}
// add default platform? // add default platform?
platform_id = qs['platform'] || (hasLocalStorage && localStorage.getItem("__lastplatform")); platform_id = qs['platform'] || (hasLocalStorage && localStorage.getItem("__lastplatform"));
if (!platform_id) { if (!platform_id) {
@ -2048,6 +2042,7 @@ export async function startUI() {
qs['platform'] = platform_id = repo.platform_id; qs['platform'] = platform_id = repo.platform_id;
if (!qs['file']) if (!qs['file'])
qs['file'] = repo.mainPath; qs['file'] = repo.mainPath;
requestPersistPermission(true, true);
} }
} else { } else {
repo_id = ''; repo_id = '';