2018-10-01 16:39:17 +02:00
|
|
|
class ConnectionDialog extends this.OS.GUI.BasicDialog
|
|
|
|
constructor: () ->
|
2020-07-10 16:09:23 +02:00
|
|
|
super "ConnectionDialog", ConnectionDialog.scheme
|
|
|
|
|
|
|
|
|
|
|
|
main: () ->
|
|
|
|
super.main()
|
2022-08-17 22:23:09 +02:00
|
|
|
@find("bbp").data = [
|
2023-07-23 13:18:43 +02:00
|
|
|
{ text: "16 bits", value: 16},
|
2022-08-17 22:23:09 +02:00
|
|
|
{ text: "32 bits", value: 32 }
|
|
|
|
]
|
2023-07-23 13:18:43 +02:00
|
|
|
(@find "txtWVNC").value = @parent.setting.wvnc
|
|
|
|
(@find "txtServer").value = @parent.setting.server
|
|
|
|
sel = 0
|
|
|
|
sel = 1 if @parent.setting.bbc is 32
|
|
|
|
(@find "bbp").selected = sel
|
|
|
|
(@find "jq").value = @parent.setting.quality
|
|
|
|
|
2020-07-10 16:09:23 +02:00
|
|
|
@find("bt-ok").onbtclick = (e) =>
|
|
|
|
return unless @handle
|
2023-07-23 13:18:43 +02:00
|
|
|
@parent.setting.wvnc = (@find "txtWVNC").value
|
|
|
|
@parent.setting.server = (@find "txtServer").value
|
|
|
|
@parent.setting.bbc = (@find "bbp").selectedItem.data.value
|
|
|
|
@parent.setting.quality = (@find "jq").value
|
|
|
|
@handle undefined
|
2020-07-10 16:09:23 +02:00
|
|
|
@quit()
|
|
|
|
|
|
|
|
@find("bt-cancel").onbtclick = (e) =>
|
|
|
|
@quit()
|
|
|
|
|
|
|
|
ConnectionDialog.scheme = """
|
2023-01-01 01:54:04 +01:00
|
|
|
<afx-app-window width='350' height='320'>
|
|
|
|
<afx-vbox padding="5">
|
2023-07-23 13:18:43 +02:00
|
|
|
<afx-input label="__(WVNC Websocket)" data-height="50" data-id="txtWVNC"></afx-input>
|
|
|
|
<afx-input label="__(VNC Server)" data-height="50" data-id="txtServer" ></afx-input>
|
2023-01-01 01:54:04 +01:00
|
|
|
<div data-height="5"></div>
|
|
|
|
<afx-label text="__(Bits per pixel)" data-height="30" class="header" ></afx-label>
|
|
|
|
<afx-list-view dropdown = "true" data-id ="bbp" data-height="35" ></afx-list-view>
|
|
|
|
<div data-height="5"></div>
|
|
|
|
<afx-label text="__(JPEG quality)" data-height="30" class="header" ></afx-label>
|
|
|
|
<afx-slider data-id ="jq" data-height="30" ></afx-slider>
|
2023-01-08 00:21:02 +01:00
|
|
|
<div></div>
|
2023-01-01 01:54:04 +01:00
|
|
|
<afx-hbox data-height = '35'>
|
|
|
|
<div style=' text-align:right;'>
|
|
|
|
<afx-button data-id = "bt-ok" text = "__(Connect)"></afx-button>
|
|
|
|
<afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>
|
|
|
|
</div>
|
|
|
|
</afx-hbox>
|
|
|
|
</afx-vbox>
|
2020-07-10 16:09:23 +02:00
|
|
|
</afx-app-window>
|
|
|
|
|
|
|
|
"""
|
2018-10-01 16:39:17 +02:00
|
|
|
|
2018-10-02 12:01:09 +02:00
|
|
|
class CredentialDialog extends this.OS.GUI.BasicDialog
|
|
|
|
constructor: () ->
|
2020-07-10 16:09:23 +02:00
|
|
|
super "CredentialDialog", CredentialDialog.scheme
|
|
|
|
|
|
|
|
main: () ->
|
|
|
|
@find("bt-ok").onbtclick = () =>
|
|
|
|
return @quit() unless @handle
|
|
|
|
data =
|
|
|
|
username: (@find "txtUser").value
|
|
|
|
password: (@find "txtPass").value
|
|
|
|
@handle data
|
|
|
|
@quit()
|
|
|
|
@find("bt-cancel").onbtclick = () =>
|
|
|
|
@quit()
|
|
|
|
|
|
|
|
CredentialDialog.scheme = """
|
2023-01-01 01:54:04 +01:00
|
|
|
<afx-app-window width='350' height='170'>
|
|
|
|
<afx-vbox padding="5">
|
|
|
|
<afx-input label="__(Username)" data-height="55" data-id="txtUser"></afx-input>
|
|
|
|
<afx-input label="__(Password)" data-height="55" type="password" data-id="txtPass"></afx-input>
|
2023-01-08 00:21:02 +01:00
|
|
|
<div></div>
|
2023-01-01 01:54:04 +01:00
|
|
|
<afx-hbox data-height = '35'>
|
2020-07-10 16:09:23 +02:00
|
|
|
<div style=' text-align:right;'>
|
|
|
|
<afx-button data-id = "bt-ok" text = "__(Ok)"></afx-button>
|
|
|
|
<afx-button data-id = "bt-cancel" text = "__(Cancel)"></afx-button>
|
|
|
|
</div>
|
|
|
|
</afx-hbox>
|
|
|
|
</afx-vbox>
|
|
|
|
</afx-app-window>
|
|
|
|
"""
|
2018-10-02 12:01:09 +02:00
|
|
|
|
2020-07-10 16:09:23 +02:00
|
|
|
class RemoteDesktop extends this.OS.application.BaseApplication
|
2018-10-01 16:39:17 +02:00
|
|
|
constructor: ( args ) ->
|
|
|
|
super "RemoteDesktop", args
|
|
|
|
|
|
|
|
main: () ->
|
|
|
|
@canvas = @find "screen"
|
2018-10-01 22:50:32 +02:00
|
|
|
@container = @find "container"
|
2023-01-07 14:51:15 +01:00
|
|
|
@zoom = @find "zoom"
|
|
|
|
@btreset = @find "btreset"
|
|
|
|
@zoom.max = 200
|
|
|
|
@zoom.value = 100
|
|
|
|
@zoom.onvaluechange = (e) => @setScale()
|
2023-01-08 00:21:02 +01:00
|
|
|
@switch = @find "capture_mouse"
|
|
|
|
@switch.onswchange = (e) =>
|
|
|
|
@client.mouseCapture = @switch.swon
|
2023-07-23 13:18:43 +02:00
|
|
|
|
|
|
|
proto = "ws"
|
|
|
|
proto += "s" if window.location.protocol.startsWith "https"
|
|
|
|
host = "#{window.location.host}"
|
|
|
|
if window.location.port and window.location.port isnt ""
|
|
|
|
host += ":#{window.location.port}"
|
|
|
|
@setting.wvnc = "#{proto}://#{host}/wvnc" unless @setting.wvnc
|
|
|
|
@setting.server = "127.0.0.1:5900" unless @setting.server
|
|
|
|
@setting.bbp = 16 unless @setting.bbp
|
|
|
|
@setting.quality = 40 unless @setting.quality
|
2023-01-07 14:51:15 +01:00
|
|
|
@btreset.onbtclick = (e) =>
|
|
|
|
w = $(@container).width()
|
|
|
|
h = $(@container).height()
|
|
|
|
sx = w / @client.resolution.w
|
|
|
|
sy = h / @client.resolution.h
|
|
|
|
if sx > sy
|
|
|
|
@zoom.value = sy*100
|
|
|
|
else
|
|
|
|
@zoom.value = sx*100
|
|
|
|
@setScale()
|
2018-10-01 22:50:32 +02:00
|
|
|
@client = new WVNC {
|
2022-08-16 21:30:08 +02:00
|
|
|
element: @canvas
|
2018-10-01 16:39:17 +02:00
|
|
|
}
|
2022-08-17 18:43:52 +02:00
|
|
|
@bindKey "CTRL-SHIFT-V", (e) =>
|
|
|
|
@pasteText()
|
2022-08-18 21:35:37 +02:00
|
|
|
#@client.onerror = (m) =>
|
|
|
|
# @error m.toString()
|
|
|
|
# @showConnectionDialog()
|
|
|
|
@client.ondisconnect = () =>
|
2020-07-10 16:09:23 +02:00
|
|
|
@showConnectionDialog()
|
|
|
|
@client.onresize = ()=>
|
|
|
|
@setScale()
|
|
|
|
@client.onpassword = ()=>
|
|
|
|
return new Promise (r,e)=>
|
|
|
|
@openDialog "PromptDialog", {
|
|
|
|
title: __("VNC password"),
|
|
|
|
label: __("VNC password"),
|
2020-12-29 20:36:35 +01:00
|
|
|
value: "password",
|
2020-07-10 16:09:23 +02:00
|
|
|
type: "password"
|
|
|
|
}
|
|
|
|
.then (d) ->
|
2018-10-01 19:13:47 +02:00
|
|
|
r(d)
|
2022-08-17 18:43:52 +02:00
|
|
|
@client.oncopy = (text) =>
|
|
|
|
@_api.setClipboard text
|
|
|
|
|
2020-07-10 16:09:23 +02:00
|
|
|
@client.oncredential = () =>
|
|
|
|
return new Promise (r,e) =>
|
|
|
|
@openDialog new CredentialDialog, { title: __("User credential") }
|
|
|
|
.then (d) ->
|
2018-10-02 12:01:09 +02:00
|
|
|
r(d.username, d.password)
|
2023-01-07 14:51:15 +01:00
|
|
|
# @on "resize", (e)=> @setScale()
|
2020-07-10 16:09:23 +02:00
|
|
|
@on "focus", (e) => $(@canvas).focus()
|
|
|
|
@client.init().then () =>
|
|
|
|
@showConnectionDialog()
|
2018-10-01 16:39:17 +02:00
|
|
|
|
2022-08-17 18:43:52 +02:00
|
|
|
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
|
|
|
|
|
2018-10-01 22:50:32 +02:00
|
|
|
setScale: () ->
|
2023-01-07 14:51:15 +01:00
|
|
|
console.log "scale changed"
|
2018-10-01 22:50:32 +02:00
|
|
|
return unless @client and @client.resolution
|
2023-01-07 14:51:15 +01:00
|
|
|
@client.setScale @zoom.value / 100.0
|
|
|
|
@container.scrollLeft = 0
|
|
|
|
@container.scrollTop = 0
|
2018-10-01 22:50:32 +02:00
|
|
|
|
2018-10-02 12:01:09 +02:00
|
|
|
menu: () ->
|
2020-07-10 16:09:23 +02:00
|
|
|
|
2018-10-02 12:01:09 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
text: "__(Connection)",
|
2020-07-10 16:09:23 +02:00
|
|
|
nodes: [
|
2018-10-02 12:01:09 +02:00
|
|
|
{ text: "__(New Connection)", dataid: "#{@name}-new", },
|
|
|
|
{ text: "__(Disconnect)", dataid: "#{@name}-close" }
|
|
|
|
],
|
2022-08-18 21:35:37 +02:00
|
|
|
onchildselect: (e) =>
|
|
|
|
@client.disconnect(false) if @client
|
2018-10-02 12:01:09 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-10-01 16:39:17 +02:00
|
|
|
showConnectionDialog: () ->
|
2022-08-18 21:35:37 +02:00
|
|
|
return unless @client
|
2023-07-23 13:18:43 +02:00
|
|
|
@openDialog new ConnectionDialog, { title: __("Connection"), data: @setting}
|
2020-07-10 16:09:23 +02:00
|
|
|
.then (d) =>
|
2023-07-23 13:18:43 +02:00
|
|
|
@client.ws = @setting.wvnc
|
|
|
|
@client.connect @setting.server, @setting
|
2018-10-01 19:13:47 +02:00
|
|
|
|
|
|
|
cleanup: () ->
|
2020-12-29 20:36:35 +01:00
|
|
|
@client.disconnect(true) if @client
|
2022-08-18 21:35:37 +02:00
|
|
|
@client = undefined
|
2020-12-29 20:36:35 +01:00
|
|
|
|
2018-10-01 16:39:17 +02:00
|
|
|
this.OS.register "RemoteDesktop", RemoteDesktop
|