class ConnectionDialog extends this.OS.GUI.BasicDialog
constructor: () ->
super "ConnectionDialog", ConnectionDialog.scheme
main: () ->
super.main()
@find("bbp").data = [
{ text: "16 bits", value: 16, selected: true },
{ text: "32 bits", value: 32 }
]
@find("compression").data = [
{text: "No compression", value:0},
{text: "JPEG", value:1},
{text: "zLib", value:2},
{text: "JPEG & zLib", value:3, selected:true}
]
@find("jq").value = 40
@find("bt-ok").onbtclick = (e) =>
return unless @handle
data =
wvnc: (@find "txtWVNC").value
server: (@find "txtServer").value
bbp: (@find "bbp").selectedItem.data.value,
flag: (@find "compression").selectedItem.data.value,
quality:(@find "jq").value
@handle data
@quit()
@find("bt-cancel").onbtclick = (e) =>
@quit()
ConnectionDialog.scheme = """
"""
class CredentialDialog extends this.OS.GUI.BasicDialog
constructor: () ->
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 = """
"""
class RemoteDesktop extends this.OS.application.BaseApplication
constructor: ( args ) ->
super "RemoteDesktop", args
main: () ->
@canvas = @find "screen"
@container = @find "container"
@client = new WVNC {
element: @canvas,
worker: "#{@_api.handle.get}/#{@meta().path}/decoder.js"
}
@client.onerror = (m) =>
@error m
@showConnectionDialog()
@client.onresize = ()=>
@setScale()
@client.onpassword = ()=>
return new Promise (r,e)=>
@openDialog "PromptDialog", {
title: __("VNC password"),
label: __("VNC password"),
value: "!x$@n9ph",
type: "password"
}
.then (d) ->
r(d)
@client.oncredential = () =>
return new Promise (r,e) =>
@openDialog new CredentialDialog, { title: __("User credential") }
.then (d) ->
r(d.username, d.password)
@on "resize", (e)=> @setScale()
@on "focus", (e) => $(@canvas).focus()
@client.init().then () =>
@showConnectionDialog()
setScale: () ->
return unless @client and @client.resolution
w = $(@container).width()
h = $(@container).height()
sx = w / @client.resolution.w
sy = h / @client.resolution.h
if sx > sy then @client.setScale sy else @client.setScale sx
menu: () ->
[
{
text: "__(Connection)",
nodes: [
{ text: "__(New Connection)", dataid: "#{@name}-new", },
{ text: "__(Disconnect)", dataid: "#{@name}-close" }
],
onchildselect: (e) => @actionConnection()
}
]
actionConnection: (e) ->
@client.disconnect() if @client
@showConnectionDialog()
showConnectionDialog: () ->
@openDialog new ConnectionDialog, { title: __("Connection")}
.then (d) =>
@client.ws = d.wvnc
console.log d
@client.connect d.server, d
cleanup: () ->
@client.disconnect() if @client
this.OS.register "RemoteDesktop", RemoteDesktop