From 615fd98620d577c82ed9d99fd51ceeee714430ba Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 27 Dec 2022 12:17:42 +0100 Subject: [Web] Expose API to force file system sync. Mostly useful for modules and extensions that can't use FileAccess to write files. --- doc/classes/JavaScriptBridge.xml | 7 +++++++ platform/web/api/api.cpp | 3 +++ platform/web/api/javascript_bridge_singleton.h | 1 + platform/web/javascript_bridge_singleton.cpp | 5 +++++ platform/web/os_web.cpp | 6 ++++++ platform/web/os_web.h | 1 + 6 files changed, 23 insertions(+) diff --git a/doc/classes/JavaScriptBridge.xml b/doc/classes/JavaScriptBridge.xml index 5e36b5cc80..340c296eef 100644 --- a/doc/classes/JavaScriptBridge.xml +++ b/doc/classes/JavaScriptBridge.xml @@ -46,6 +46,13 @@ If [param use_global_execution_context] 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 [FileAccess] to write files. + + diff --git a/platform/web/api/api.cpp b/platform/web/api/api.cpp index e637f2aef2..9f43610d86 100644 --- a/platform/web/api/api.cpp +++ b/platform/web/api/api.cpp @@ -73,6 +73,7 @@ void JavaScriptBridge::_bind_methods() { ClassDB::bind_method(D_METHOD("download_buffer", "buffer", "name", "mime"), &JavaScriptBridge::download_buffer, DEFVAL("application/octet-stream")); ClassDB::bind_method(D_METHOD("pwa_needs_update"), &JavaScriptBridge::pwa_needs_update); ClassDB::bind_method(D_METHOD("pwa_update"), &JavaScriptBridge::pwa_update); + ClassDB::bind_method(D_METHOD("force_fs_sync"), &JavaScriptBridge::force_fs_sync); ADD_SIGNAL(MethodInfo("pwa_update_available")); } @@ -111,6 +112,8 @@ bool JavaScriptBridge::pwa_needs_update() const { Error JavaScriptBridge::pwa_update() { return ERR_UNAVAILABLE; } +void JavaScriptBridge::force_fs_sync() { +} void JavaScriptBridge::download_buffer(Vector p_arr, const String &p_name, const String &p_mime) { } #endif diff --git a/platform/web/api/javascript_bridge_singleton.h b/platform/web/api/javascript_bridge_singleton.h index 1e7b5a1699..93288cdea1 100644 --- a/platform/web/api/javascript_bridge_singleton.h +++ b/platform/web/api/javascript_bridge_singleton.h @@ -61,6 +61,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 JavaScriptBridge *get_singleton(); JavaScriptBridge(); diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp index 69cd0cece1..ce94d511a6 100644 --- a/platform/web/javascript_bridge_singleton.cpp +++ b/platform/web/javascript_bridge_singleton.cpp @@ -361,6 +361,11 @@ void JavaScriptBridge::download_buffer(Vector p_arr, const String &p_na bool JavaScriptBridge::pwa_needs_update() const { return OS_Web::get_singleton()->pwa_needs_update(); } + Error JavaScriptBridge::pwa_update() { return OS_Web::get_singleton()->pwa_update(); } + +void JavaScriptBridge::force_fs_sync() { + OS_Web::get_singleton()->force_fs_sync(); +} diff --git a/platform/web/os_web.cpp b/platform/web/os_web.cpp index 07c53e51d0..6152e803de 100644 --- a/platform/web/os_web.cpp +++ b/platform/web/os_web.cpp @@ -196,6 +196,12 @@ void OS_Web::update_pwa_state_callback() { } } +void OS_Web::force_fs_sync() { + if (is_userfs_persistent()) { + idb_needs_sync = true; + } +} + Error OS_Web::pwa_update() { return godot_js_pwa_update() ? FAILED : OK; } diff --git a/platform/web/os_web.h b/platform/web/os_web.h index 64f3a4d133..21fd212db6 100644 --- a/platform/web/os_web.h +++ b/platform/web/os_web.h @@ -69,6 +69,7 @@ public: bool pwa_needs_update() const { return pwa_is_waiting; } Error pwa_update(); + void force_fs_sync(); void initialize_joypads() override; -- cgit v1.2.3