summaryrefslogtreecommitdiffstats
path: root/platform/javascript/os_javascript.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-05-29 21:30:29 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-05-29 23:21:09 +0200
commitce542bced1167a465ba2fc4150e16816e6d82e29 (patch)
treeec2af36eeb6392c066be52ab59d358317ec059f4 /platform/javascript/os_javascript.cpp
parent2b436dd50e55e32bf09021d3c819339a7fce3e9f (diff)
downloadredot-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.cpp17
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;