/
vnc.go
57 lines (52 loc) · 1.19 KB
/
vnc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"github.com/kaginawa/kvnc"
)
const (
hostPlaceholder = "{HOST}"
portPlaceholder = "{PORT}"
defaultCommandFormat = "./vncviewer " + hostPlaceholder + "::" + portPlaceholder
macOSCommandFormat = "open vnc://" + hostPlaceholder + ":" + portPlaceholder
)
type viewerParams struct {
trueColor bool
fullScreen bool
viewOnly bool
}
func startViewer(port string, params viewerParams) {
format := defaultCommandFormat
if runtime.GOOS == "darwin" {
format = macOSCommandFormat
}
if len(config.ViewerCmd) > 0 {
format = config.ViewerCmd
}
command := strings.Replace(format, hostPlaceholder, "localhost", 1)
command = strings.Replace(command, portPlaceholder, port, 1)
if runtime.GOOS != "darwin" {
if params.trueColor {
command += " -8bit"
}
if params.fullScreen {
command += " -fullscreen"
}
if params.viewOnly {
command += " -viewonly"
}
}
tokens := strings.Split(command, " ")
viewer := exec.Command(tokens[0], tokens[1:]...)
kvnc.PrepareBackgroundCommand(viewer)
res, err := viewer.Output()
if err != nil {
println(string(res))
os.Exit(1)
}
fmt.Println(string(res))
os.Exit(0)
}