Browse Source

Merge pull request #46930 from Faless/js/4.x_project_manager_drop_hack

[HTML5] Drag and drop zip in project manager.
Rémi Verschelde 4 years ago
parent
commit
a1eccd9eb8

+ 2 - 2
misc/dist/html/editor.html

@@ -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;
 					});

+ 7 - 0
platform/javascript/js/engine/config.js

@@ -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) {

+ 38 - 26
platform/javascript/js/libs/library_godot_display.js

@@ -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('/');
-					}
-				});
-				// 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;
+				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);
 					}
-					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);
 			});
 		},
 

+ 3 - 0
platform/javascript/js/libs/library_godot_os.js

@@ -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;
 		},