[HTML5] Drag and drop zip in project manager.
With a very nice hack, a new hidden configuration option that delays
dropped files removal at exit.
This still leaks while the project manager is running, but will clear
memory as soon as it exits or load something.
(reminder, dropped files are reguarly removed after the signal is
emitted specifically to avoid leaks, but I prefer hacking the HTML5
config then the project manager).
(cherry picked from commit f1e810adcb
)
This commit is contained in:
parent
7e5020b2fa
commit
64feaed39b
4 changed files with 50 additions and 28 deletions
4
misc/dist/html/editor.html
vendored
4
misc/dist/html/editor.html
vendored
|
@ -502,7 +502,7 @@
|
|||
showTab('loader');
|
||||
setLoaderEnabled(true);
|
||||
};
|
||||
editor.start({'args': args});
|
||||
editor.start({'args': args, 'persistentDrops': is_project_manager});
|
||||
});
|
||||
}, 0);
|
||||
OnEditorExit = null;
|
||||
|
@ -563,7 +563,7 @@
|
|||
//selectVideoMode();
|
||||
showTab('editor');
|
||||
setLoaderEnabled(false);
|
||||
editor.start({'args': ['--video-driver', video_driver]}).then(function() {
|
||||
editor.start({'args': ['--project-manager', '--video-driver', video_driver], 'persistentDrops': true}).then(function() {
|
||||
setStatusMode('hidden');
|
||||
initializing = false;
|
||||
});
|
||||
|
|
|
@ -103,6 +103,11 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
|||
* @type {Array.<string>}
|
||||
*/
|
||||
persistentPaths: ['/userfs'],
|
||||
/**
|
||||
* @ignore
|
||||
* @type {boolean}
|
||||
*/
|
||||
persistentDrops: false,
|
||||
/**
|
||||
* @ignore
|
||||
* @type {Array.<string>}
|
||||
|
@ -231,6 +236,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
|||
this.locale = parse('locale', this.locale);
|
||||
this.canvasResizePolicy = parse('canvasResizePolicy', this.canvasResizePolicy);
|
||||
this.persistentPaths = parse('persistentPaths', this.persistentPaths);
|
||||
this.persistentDrops = parse('persistentDrops', this.persistentDrops);
|
||||
this.experimentalVK = parse('experimentalVK', this.experimentalVK);
|
||||
this.gdnativeLibs = parse('gdnativeLibs', this.gdnativeLibs);
|
||||
this.fileSizes = parse('fileSizes', this.fileSizes);
|
||||
|
@ -316,6 +322,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
|
|||
'canvas': this.canvas,
|
||||
'canvasResizePolicy': this.canvasResizePolicy,
|
||||
'locale': locale,
|
||||
'persistentDrops': this.persistentDrops,
|
||||
'virtualKeyboard': this.experimentalVK,
|
||||
'onExecute': this.onExecute,
|
||||
'onExit': function (p_code) {
|
||||
|
|
|
@ -192,33 +192,45 @@ const GodotDisplayDragDrop = {
|
|||
GodotDisplayDragDrop.promises = [];
|
||||
GodotDisplayDragDrop.pending_files = [];
|
||||
callback(drops);
|
||||
const dirs = [DROP.substr(0, DROP.length - 1)];
|
||||
// Remove temporary files
|
||||
files.forEach(function (file) {
|
||||
FS.unlink(file);
|
||||
let dir = file.replace(DROP, '');
|
||||
let idx = dir.lastIndexOf('/');
|
||||
while (idx > 0) {
|
||||
dir = dir.substr(0, idx);
|
||||
if (dirs.indexOf(DROP + dir) === -1) {
|
||||
dirs.push(DROP + dir);
|
||||
}
|
||||
idx = dir.lastIndexOf('/');
|
||||
if (GodotConfig.persistent_drops) {
|
||||
// Delay removal at exit.
|
||||
GodotOS.atexit(function (resolve, reject) {
|
||||
GodotDisplayDragDrop.remove_drop(files, DROP);
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
GodotDisplayDragDrop.remove_drop(files, DROP);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
remove_drop: function (files, drop_path) {
|
||||
const dirs = [drop_path.substr(0, drop_path.length - 1)];
|
||||
// Remove temporary files
|
||||
files.forEach(function (file) {
|
||||
FS.unlink(file);
|
||||
let dir = file.replace(drop_path, '');
|
||||
let idx = dir.lastIndexOf('/');
|
||||
while (idx > 0) {
|
||||
dir = dir.substr(0, idx);
|
||||
if (dirs.indexOf(drop_path + dir) === -1) {
|
||||
dirs.push(drop_path + dir);
|
||||
}
|
||||
});
|
||||
// Remove dirs.
|
||||
dirs.sort(function (a, b) {
|
||||
const al = (a.match(/\//g) || []).length;
|
||||
const bl = (b.match(/\//g) || []).length;
|
||||
if (al > bl) {
|
||||
return -1;
|
||||
} else if (al < bl) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}).forEach(function (dir) {
|
||||
FS.rmdir(dir);
|
||||
});
|
||||
idx = dir.lastIndexOf('/');
|
||||
}
|
||||
});
|
||||
// Remove dirs.
|
||||
dirs.sort(function (a, b) {
|
||||
const al = (a.match(/\//g) || []).length;
|
||||
const bl = (b.match(/\//g) || []).length;
|
||||
if (al > bl) {
|
||||
return -1;
|
||||
} else if (al < bl) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}).forEach(function (dir) {
|
||||
FS.rmdir(dir);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ const GodotConfig = {
|
|||
locale: 'en',
|
||||
canvas_resize_policy: 2, // Adaptive
|
||||
virtual_keyboard: false,
|
||||
persistent_drops: false,
|
||||
on_execute: null,
|
||||
on_exit: null,
|
||||
|
||||
|
@ -68,6 +69,7 @@ const GodotConfig = {
|
|||
GodotConfig.canvas = p_opts['canvas'];
|
||||
GodotConfig.locale = p_opts['locale'] || GodotConfig.locale;
|
||||
GodotConfig.virtual_keyboard = p_opts['virtualKeyboard'];
|
||||
GodotConfig.persistent_drops = !!p_opts['persistentDrops'];
|
||||
GodotConfig.on_execute = p_opts['onExecute'];
|
||||
GodotConfig.on_exit = p_opts['onExit'];
|
||||
},
|
||||
|
@ -80,6 +82,7 @@ const GodotConfig = {
|
|||
GodotConfig.locale = 'en';
|
||||
GodotConfig.canvas_resize_policy = 2;
|
||||
GodotConfig.virtual_keyboard = false;
|
||||
GodotConfig.persistent_drops = false;
|
||||
GodotConfig.on_execute = null;
|
||||
GodotConfig.on_exit = null;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue