[HTML5] Implement JavaScript PWA update callbacks.

Allows detecting when a new version of the progressive web app service
worker is waiting (i.e. an update is pending), along a function to force
the update and reload all clients.
This commit is contained in:
Fabio Alessandrelli 2022-01-31 15:28:12 +01:00
parent 3cc72ac03f
commit 948e66c3d6
8 changed files with 119 additions and 0 deletions

View file

@ -71,6 +71,9 @@ void JavaScript::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "create_object", &JavaScript::_create_object_bind, mi);
}
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);
ADD_SIGNAL(MethodInfo("pwa_update_available"));
}
#if !defined(JAVASCRIPT_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED)
@ -102,6 +105,12 @@ Variant JavaScript::_create_object_bind(const Variant **p_args, int p_argcount,
}
#endif
#if !defined(JAVASCRIPT_ENABLED)
bool JavaScript::pwa_needs_update() const {
return false;
}
Error JavaScript::pwa_update() {
return ERR_UNAVAILABLE;
}
void JavaScript::download_buffer(Vector<uint8_t> p_arr, const String &p_name, const String &p_mime) {
}
#endif