fix keyboard sync.

This commit is contained in:
Miroslav Šedivý 2021-12-11 14:04:03 +01:00
parent 42fdc43ff5
commit c00c30e211

View File

@ -378,9 +378,14 @@
} }
@Watch('clipboard') @Watch('clipboard')
onClipboardChanged(clipboard: string) { async onClipboardChanged(clipboard: string) {
if (this.clipboard_write_available) { 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() this.$accessor.video.pause()
}) })
document.addEventListener('focusin', this.onFocus.bind(this))
/* Initialize Guacamole Keyboard */ /* Initialize Guacamole Keyboard */
this.keyboard.onkeydown = (key: number) => { this.keyboard.onkeydown = (key: number) => {
if (!this.focused || !this.hosting || this.locked) { if (!this.focused || !this.hosting || this.locked) {
@ -458,7 +461,6 @@
beforeDestroy() { beforeDestroy() {
this.observer.disconnect() this.observer.disconnect()
this.$accessor.video.setPlayable(false) this.$accessor.video.setPlayable(false)
document.removeEventListener('focusin', this.onFocus.bind(this))
/* Guacamole Keyboard does not provide destroy functions */ /* Guacamole Keyboard does not provide destroy functions */
} }
@ -584,12 +586,8 @@
this._clipboard.open() this._clipboard.open()
} }
async onFocus() { async syncClipboard() {
if (!document.hasFocus() || !this.$accessor.active) { if (this.clipboard_read_available) {
return
}
if (this.hosting && this.clipboard_read_available) {
try { try {
const text = await navigator.clipboard.readText() const text = await navigator.clipboard.readText()
if (this.clipboard !== text) { if (this.clipboard !== text) {
@ -688,10 +686,11 @@
numLock: e.getModifierState('NumLock'), numLock: e.getModifierState('NumLock'),
scrollLock: e.getModifierState('ScrollLock'), scrollLock: e.getModifierState('ScrollLock'),
}) })
this.syncClipboard()
} }
this._overlay.focus() this._overlay.focus()
this.onFocus()
this.focused = true this.focused = true
} }