You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
Add OS clipboard set support to OS Javascript
This commit is contained in:
@@ -795,6 +795,25 @@ const char *OS_JavaScript::get_audio_driver_name(int p_driver) const {
|
|||||||
return "JavaScript";
|
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
|
// Lifecycle
|
||||||
int OS_JavaScript::get_current_video_driver() const {
|
int OS_JavaScript::get_current_video_driver() const {
|
||||||
return video_driver_index;
|
return video_driver_index;
|
||||||
|
|||||||
@@ -133,6 +133,8 @@ public:
|
|||||||
virtual int get_audio_driver_count() const;
|
virtual int get_audio_driver_count() const;
|
||||||
virtual const char *get_audio_driver_name(int p_driver) 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;
|
virtual MainLoop *get_main_loop() const;
|
||||||
void run_async();
|
void run_async();
|
||||||
bool main_loop_iterate();
|
bool main_loop_iterate();
|
||||||
|
|||||||
Reference in New Issue
Block a user