0
0
mirror of https://github.com/marcrobledo/savegame-editors.git synced 2025-04-24 16:35:10 +00:00

Offline+Chrome fixes

- Chrome+Edge don't trivially accept dropped folders when the page is
  running as a local file:/// origin: https://github.com/danialfarid/ng-file-upload/issues/236
  Setting `inputFile.webkitdirectory = true` allows for *browsing* to
  pick folders in this situation, but it only accepts folders and
  prevents individual files from being picked, so I've left it commented
  out while leaving the later logic it needs to work.

- This means local usage+development is best experienced with either
  Firefox or (for Chrome/Edge) a simple http server.

- Chrome+Edge don't always set file.webkitRelativePath, here we just
  patch it in but there might be a cleaner way.
  https://github.com/ant-design/ant-design/issues/16426#issuecomment-490793206
This commit is contained in:
aquacluck 2024-02-10 20:43:54 -08:00
parent 5e402e8fe0
commit 63fc927cbb
2 changed files with 28 additions and 8 deletions

View File

@ -102,7 +102,22 @@ MarcDragAndDrop=(function(){
async function toFilePromise(fileEntry) {
try {
return await new Promise((resolve, reject) => {
fileEntry.file(resolve, reject);
fileEntry.file(function(file){
// Patch webkitRelativePath for Chrome which doesn't always set it? https://github.com/ant-design/ant-design/issues/16426
// TODO could we just pass fileEntry.fullpath out instead of patching this?
Object.defineProperties(file, {
webkitRelativePath: {
writable: true,
},
});
file.webkitRelativePath = file.webkitRelativePath || fileEntry.fullPath.replace(/^\//, '');
Object.defineProperties(file, {
webkitRelativePath: {
writable: false,
},
});
resolve(file);
}, reject);
});
} catch (err) {
console.log(err);
@ -196,10 +211,6 @@ function _tempFileLoadFunction(){
}
}
function loadSavegameFromInput(input){
tempFile=new MarcFile(input.files[0], _tempFileLoadFunction);
}
function saveChanges(){
if(decodeURIComponent(document.cookie).indexOf('hideWarningMessage=1')>=0 || location.protocol==='file:'){ /* chrome does not write cookies in local, so skip warning message in that case */
SavegameEditor.save();
@ -259,8 +270,17 @@ window.addEventListener('load', function(){
inputFile.type='file';
inputFile.className='hidden';
inputFile.id='file-load';
inputFile.addEventListener('change', function(){
loadSavegameFromInput(this);
// Requires a folder for "browse window" picking, but this works when running webpage from filesystem on Chrome, where dropping folders does not work.
// `webkitGetAsEntry` may be a better workaround https://github.com/danialfarid/ng-file-upload/issues/236#issuecomment-45053629
// inputFile.webkitdirectory = true;
inputFile.addEventListener('change', async function(evt){
if(this.files.length == 1 || typeof SavegameEditor.showSavegameIndex === 'undefined') {
// Load savegame from file
tempFile=new MarcFile(this.files[0], _tempFileLoadFunction);
} else {
// Some games have a complex structure of multiple savegames, so we provide a custom picker+overview
await SavegameEditor.showSavegameIndex(this.files);
}
}, false);
dragZone.appendChild(dragMessage);

View File

@ -1,5 +1,5 @@
/*
The legend of Zelda: Tears of the Kingdom savegame editor (last update 2024-01-02)
The legend of Zelda: Tears of the Kingdom savegame editor (last update 2024-02-11)
by Marc Robledo 2023-2024
*/