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.
This commit is contained in:
Fabio Alessandrelli 2019-05-29 21:30:29 +02:00
parent 2b436dd50e
commit ce542bced1
2 changed files with 18 additions and 0 deletions

View file

@ -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;

View file

@ -134,6 +134,7 @@ public:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const;
virtual MainLoop *get_main_loop() const;
void run_async();