summaryrefslogtreecommitdiff
path: root/platform/javascript/api
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/api')
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.cpp25
1 files changed, 6 insertions, 19 deletions
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp
index d44e8139a1..8d781703ed 100644
--- a/platform/javascript/api/javascript_tools_editor_plugin.cpp
+++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp
@@ -39,6 +39,11 @@
#include <emscripten/emscripten.h>
+// JavaScript functions defined in library_godot_editor_tools.js
+extern "C" {
+extern void godot_js_editor_download_file(const char *p_path, const char *p_name, const char *p_mime);
+}
+
static void _javascript_editor_init_callback() {
EditorNode::get_singleton()->add_editor_plugin(memnew(JavaScriptToolsEditorPlugin(EditorNode::get_singleton())));
}
@@ -65,25 +70,7 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
_zip_recursive(resource_path, base_path, zip);
zipClose(zip, NULL);
- EM_ASM({
- const path = "/tmp/project.zip";
- const size = FS.stat(path)["size"];
- const buf = new Uint8Array(size);
- const fd = FS.open(path, "r");
- FS.read(fd, buf, 0, size);
- FS.close(fd);
- FS.unlink(path);
- const blob = new Blob([buf], { type: "application/zip" });
- const url = window.URL.createObjectURL(blob);
- const a = document.createElement("a");
- a.href = url;
- a.download = "project.zip";
- a.style.display = "none";
- document.body.appendChild(a);
- a.click();
- a.remove();
- window.URL.revokeObjectURL(url);
- });
+ godot_js_editor_download_file("/tmp/project.zip", "project.zip", "application/zip");
}
void JavaScriptToolsEditorPlugin::_bind_methods() {