From f2682927f00fa4d9274a1a20e7cfe965e9254305 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 9 Jan 2023 21:30:42 +0100 Subject: [PATCH] Expose API to force file system sync. --- doc/classes/JavaScript.xml | 7 +++++++ platform/javascript/api/api.cpp | 3 +++ platform/javascript/api/javascript_singleton.h | 1 + platform/javascript/javascript_singleton.cpp | 5 +++++ platform/javascript/os_javascript.cpp | 6 ++++++ platform/javascript/os_javascript.h | 1 + 6 files changed, 23 insertions(+) diff --git a/doc/classes/JavaScript.xml b/doc/classes/JavaScript.xml index a812701a8..14977cd45 100644 --- a/doc/classes/JavaScript.xml +++ b/doc/classes/JavaScript.xml @@ -46,6 +46,13 @@ If [code]use_global_execution_context[/code] is [code]true[/code], the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment. + + + + Force synchronization of the persistent file system (when enabled). + [b]Note:[/b] This is only useful for modules or extensions that can't use [File] to write files. + + diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp index e24647012..b3cc93bb8 100644 --- a/platform/javascript/api/api.cpp +++ b/platform/javascript/api/api.cpp @@ -73,6 +73,7 @@ void JavaScript::_bind_methods() { ClassDB::bind_method(D_METHOD("download_buffer", "buffer", "name", "mime"), &JavaScript::download_buffer, DEFVAL("application/octet-stream")); ClassDB::bind_method(D_METHOD("pwa_needs_update"), &JavaScript::pwa_needs_update); ClassDB::bind_method(D_METHOD("pwa_update"), &JavaScript::pwa_update); + ClassDB::bind_method(D_METHOD("force_fs_sync"), &JavaScript::force_fs_sync); ADD_SIGNAL(MethodInfo("pwa_update_available")); } @@ -111,6 +112,8 @@ bool JavaScript::pwa_needs_update() const { Error JavaScript::pwa_update() { return ERR_UNAVAILABLE; } +void JavaScript::force_fs_sync() { +} void JavaScript::download_buffer(Vector p_arr, const String &p_name, const String &p_mime) { } #endif diff --git a/platform/javascript/api/javascript_singleton.h b/platform/javascript/api/javascript_singleton.h index 77fe1cfab..2931d61ff 100644 --- a/platform/javascript/api/javascript_singleton.h +++ b/platform/javascript/api/javascript_singleton.h @@ -60,6 +60,7 @@ public: void download_buffer(Vector p_arr, const String &p_name, const String &p_mime = "application/octet-stream"); bool pwa_needs_update() const; Error pwa_update(); + void force_fs_sync(); static JavaScript *get_singleton(); JavaScript(); diff --git a/platform/javascript/javascript_singleton.cpp b/platform/javascript/javascript_singleton.cpp index 905d16185..37f8b4c8d 100644 --- a/platform/javascript/javascript_singleton.cpp +++ b/platform/javascript/javascript_singleton.cpp @@ -351,6 +351,11 @@ void JavaScript::download_buffer(Vector p_arr, const String &p_name, co bool JavaScript::pwa_needs_update() const { return OS_JavaScript::get_singleton()->pwa_needs_update(); } + +void JavaScript::force_fs_sync() { + OS_JavaScript::get_singleton()->force_fs_sync(); +} + Error JavaScript::pwa_update() { return OS_JavaScript::get_singleton()->pwa_update(); } diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 69cde4d2c..a6081947d 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -1040,6 +1040,12 @@ Error OS_JavaScript::pwa_update() { return pandemonium_js_pwa_update() ? FAILED : OK; } +void OS_JavaScript::force_fs_sync() { + if (is_userfs_persistent()) { + idb_needs_sync = true; + } +} + bool OS_JavaScript::is_userfs_persistent() const { return idb_available; } diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 179ee7a1f..db2a6c0e3 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -119,6 +119,7 @@ public: bool check_size_force_redraw(); bool pwa_needs_update() const { return pwa_is_waiting; } Error pwa_update(); + void force_fs_sync(); // Override return type to make writing static callbacks less tedious. static OS_JavaScript *get_singleton();