From c00c30e2111de212cd62b76cad92e15b42b3652e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 11 Dec 2021 14:04:03 +0100 Subject: [PATCH] fix keyboard sync. --- client/src/components/video.vue | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/client/src/components/video.vue b/client/src/components/video.vue index 7f3a705..c823a30 100644 --- a/client/src/components/video.vue +++ b/client/src/components/video.vue @@ -378,9 +378,14 @@ } @Watch('clipboard') - onClipboardChanged(clipboard: string) { + async onClipboardChanged(clipboard: string) { if (this.clipboard_write_available) { - navigator.clipboard.writeText(clipboard).catch(console.error) + try { + await navigator.clipboard.writeText(clipboard) + this.$accessor.remote.setClipboard(clipboard) + } catch (err: any) { + this.$log.error(err) + } } } @@ -434,8 +439,6 @@ this.$accessor.video.pause() }) - document.addEventListener('focusin', this.onFocus.bind(this)) - /* Initialize Guacamole Keyboard */ this.keyboard.onkeydown = (key: number) => { if (!this.focused || !this.hosting || this.locked) { @@ -458,7 +461,6 @@ beforeDestroy() { this.observer.disconnect() this.$accessor.video.setPlayable(false) - document.removeEventListener('focusin', this.onFocus.bind(this)) /* Guacamole Keyboard does not provide destroy functions */ } @@ -584,12 +586,8 @@ this._clipboard.open() } - async onFocus() { - if (!document.hasFocus() || !this.$accessor.active) { - return - } - - if (this.hosting && this.clipboard_read_available) { + async syncClipboard() { + if (this.clipboard_read_available) { try { const text = await navigator.clipboard.readText() if (this.clipboard !== text) { @@ -688,10 +686,11 @@ numLock: e.getModifierState('NumLock'), scrollLock: e.getModifierState('ScrollLock'), }) + + this.syncClipboard() } this._overlay.focus() - this.onFocus() this.focused = true }