RemoteDesktop: sync clipboard between local and remote

This commit is contained in:
DanyLE
2022-08-17 18:43:52 +02:00
parent a4943e83d1
commit f3a8f17ef1
9 changed files with 34 additions and 6 deletions

View File

@@ -262,8 +262,13 @@ class WVNC
sendTextAsClipboard: (text) ->
return unless @socket
console.log "send ", text
@socket.send (@buildCommand 0x07, text)
# send ctrl-v to paste
charcode = 'v'.charCodeAt 0
@sendKeyEvent 0xFFE3, 1 # CTRL down
@sendKeyEvent charcode, 1 # v down
@sendKeyEvent charcode, 0 # v up
@sendKeyEvent 0xFFE3, 0 # CTRL up
oncredential: () ->
return new Promise (resolve, reject) ->

View File

@@ -88,6 +88,8 @@ class RemoteDesktop extends this.OS.application.BaseApplication
@client = new WVNC {
element: @canvas
}
@bindKey "CTRL-SHIFT-V", (e) =>
@pasteText()
@client.onerror = (m) =>
@error m
@showConnectionDialog()
@@ -103,7 +105,9 @@ class RemoteDesktop extends this.OS.application.BaseApplication
}
.then (d) ->
r(d)
@client.oncopy = (text) =>
@_api.setClipboard text
@client.oncredential = () =>
return new Promise (r,e) =>
@openDialog new CredentialDialog, { title: __("User credential") }
@@ -114,6 +118,23 @@ class RemoteDesktop extends this.OS.application.BaseApplication
@client.init().then () =>
@showConnectionDialog()
pasteText: () ->
return unless @client
cb = (text) =>
return unless text and text isnt ""
@client.sendTextAsClipboard text
@_api.getClipboard()
.then (text) =>
cb(text)
.catch (e) =>
@error __("Unable to paste"), e
#ask for user to enter the text manually
@openDialog("TextDialog", { title: "Paste text"})
.then (text) =>
cb(text)
.catch (err) => @error err.toString(), err
setScale: () ->
return unless @client and @client.resolution
w = $(@container).width()