Add OS clipboard set support to OS Javascript
This commit is contained in:
parent
6273e4d76d
commit
0f76df2397
2 changed files with 21 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -133,6 +133,8 @@ public:
|
|||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void set_clipboard(const String &p_text);
|
||||
|
||||
virtual MainLoop *get_main_loop() const;
|
||||
void run_async();
|
||||
bool main_loop_iterate();
|
||||
|
|
Loading…
Reference in a new issue