1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Add OS clipboard set support to OS Javascript

This commit is contained in:
Fabio Alessandrelli
2019-05-28 12:59:29 +02:00
parent 6273e4d76d
commit 0f76df2397
2 changed files with 21 additions and 0 deletions

View File

@@ -795,6 +795,25 @@ const char *OS_JavaScript::get_audio_driver_name(int p_driver) const {
return "JavaScript";
}
// Clipboard
void OS_JavaScript::set_clipboard(const String &p_text) {
OS::set_clipboard(p_text);
/* clang-format off */
int err = EM_ASM_INT({
var text = UTF8ToString($0);
if (!navigator.clipboard || !navigator.clipboard.writeText)
return 1;
navigator.clipboard.writeText(text).catch(e => {
// Setting OS clipboard is only possible from an input callback.
console.error("Setting OS clipboard is only possible from an input callback for the HTML5 plafrom. Exception:", e);
});
return 0;
}, p_text.utf8().get_data());
/* clang-format on */
ERR_EXPLAIN("Clipboard API is not supported.");
ERR_FAIL_COND(err);
}
// Lifecycle
int OS_JavaScript::get_current_video_driver() const {
return video_driver_index;