diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-05-29 21:30:29 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-05-29 23:21:09 +0200 |
commit | ce542bced1167a465ba2fc4150e16816e6d82e29 (patch) | |
tree | ec2af36eeb6392c066be52ab59d358317ec059f4 /platform/javascript/os_javascript.cpp | |
parent | 2b436dd50e55e32bf09021d3c819339a7fce3e9f (diff) | |
download | redot-engine-ce542bced1167a465ba2fc4150e16816e6d82e29.tar.gz |
Implement Clipboard API read when supported.
Being async, the first time a value is pasted GUI elements will still
return the previous one.
This at least until 'clipboardchange' window event gets implemented by
user agents.
Diffstat (limited to 'platform/javascript/os_javascript.cpp')
-rw-r--r-- | platform/javascript/os_javascript.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 6c4764bf7b..502463a6f1 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -819,6 +819,23 @@ void OS_JavaScript::set_clipboard(const String &p_text) { ERR_FAIL_COND(err); } +String OS_JavaScript::get_clipboard() const { + /* clang-format off */ + EM_ASM({ + try { + navigator.clipboard.readText().then(function (result) { + ccall('update_clipboard', 'void', ['string'], [result]); + }).catch(function (e) { + // Fail graciously. + }); + } catch (e) { + // Fail graciously. + } + }); + /* clang-format on */ + return this->OS::get_clipboard(); +} + // Lifecycle int OS_JavaScript::get_current_video_driver() const { return video_driver_index; |