You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
[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:
committed by
Rémi Verschelde
parent
7e5020b2fa
commit
64feaed39b
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user