summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2017-10-03 12:24:11 +0200
committerGitHub <noreply@github.com>2017-10-03 12:24:11 +0200
commit2bece6bbd35c53390b2d3eedcf9b6d9949db518d (patch)
treeaad5340ed55e7727d50d6beb438cc843c78051e2 /platform
parentcc407847286e8033252db8caa382857a5601fbf2 (diff)
parent7b23665e728fe10cd0eedb54824aaeae4ae23758 (diff)
Merge pull request #11782 from eska014/persistent-userfs-test
Add OS::is_userfs_persistent, allow starting HTML5 platform in private mode
Diffstat (limited to 'platform')
-rw-r--r--platform/javascript/javascript_main.cpp16
-rw-r--r--platform/javascript/os_javascript.cpp21
-rw-r--r--platform/javascript/os_javascript.h5
3 files changed, 28 insertions, 14 deletions
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index 4c948bf181..ed4f416cfd 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -39,8 +39,13 @@ static void main_loop() {
os->main_loop_iterate();
}
-extern "C" void main_after_fs_sync() {
+extern "C" void main_after_fs_sync(char *p_idbfs_err) {
+ String idbfs_err = String::utf8(p_idbfs_err);
+ if (!idbfs_err.empty()) {
+ print_line("IndexedDB not available: " + idbfs_err);
+ }
+ os->set_idbfs_available(idbfs_err.empty());
// Ease up compatibility
ResourceLoader::set_abort_on_missing_resources(false);
Main::start();
@@ -60,14 +65,7 @@ int main(int argc, char *argv[]) {
FS.mkdir('/userfs');
FS.mount(IDBFS, {}, '/userfs');
FS.syncfs(true, function(err) {
- if (err) {
- Module.setStatus('Failed to load persistent data\nPlease allow (third-party) cookies');
- Module.printErr('Failed to populate IDB file system: ' + err.message);
- Module.noExitRuntime = false;
- } else {
- Module.print('Successfully populated IDB file system');
- ccall('main_after_fs_sync', null);
- }
+ Module['ccall']('main_after_fs_sync', null, ['string'], [err ? err.message : ""])
});
);
/* clang-format on */
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 82a8409615..f6446e77da 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -825,7 +825,7 @@ bool OS_JavaScript::main_loop_iterate() {
if (!main_loop)
return false;
- if (time_to_save_sync >= 0) {
+ if (idbfs_available && time_to_save_sync >= 0) {
int64_t newtime = get_ticks_msec();
int64_t elapsed = newtime - last_sync_time;
last_sync_time = newtime;
@@ -915,10 +915,10 @@ String OS_JavaScript::get_executable_path() const {
void OS_JavaScript::_close_notification_funcs(const String &p_file, int p_flags) {
- print_line("close " + p_file + " flags " + itos(p_flags));
- if (p_file.begins_with("/userfs") && p_flags & FileAccess::WRITE) {
- static_cast<OS_JavaScript *>(get_singleton())->last_sync_time = OS::get_singleton()->get_ticks_msec();
- static_cast<OS_JavaScript *>(get_singleton())->time_to_save_sync = 5000; //five seconds since last save
+ OS_JavaScript *os = static_cast<OS_JavaScript *>(get_singleton());
+ if (os->idbfs_available && p_file.begins_with("/userfs") && p_flags & FileAccess::WRITE) {
+ os->last_sync_time = OS::get_singleton()->get_ticks_msec();
+ os->time_to_save_sync = 5000; //five seconds since last save
}
}
@@ -993,6 +993,16 @@ bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
return p_feature == "web" || p_feature == "s3tc"; // TODO check for these features really being available
}
+void OS_JavaScript::set_idbfs_available(bool p_idbfs_available) {
+
+ idbfs_available = p_idbfs_available;
+}
+
+bool OS_JavaScript::is_userfs_persistent() const {
+
+ return idbfs_available;
+}
+
OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func) {
set_cmdline(p_execpath, get_cmdline_args());
main_loop = NULL;
@@ -1004,6 +1014,7 @@ OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_d
get_data_dir_func = p_get_data_dir_func;
FileAccessUnix::close_notification_func = _close_notification_funcs;
+ idbfs_available = false;
time_to_save_sync = -1;
}
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 1c7bcfef45..1c939d3fd5 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -49,6 +49,7 @@ typedef String (*GetDataDirFunc)();
class OS_JavaScript : public OS_Unix {
+ bool idbfs_available;
int64_t time_to_save_sync;
int64_t last_sync_time;
@@ -136,6 +137,8 @@ public:
virtual bool can_draw() const;
+ virtual bool is_userfs_persistent() const;
+
virtual void set_cursor_shape(CursorShape p_shape);
void main_loop_begin();
@@ -167,6 +170,8 @@ public:
virtual bool _check_internal_feature_support(const String &p_feature);
+ void set_idbfs_available(bool p_idbfs_available);
+
OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func);
~OS_JavaScript();
};