@@ -29,6 +29,15 @@ type Window struct {
29
29
SendChannel * connection.In `json:"-"`
30
30
}
31
31
32
+ type Options struct {
33
+ RootUrl string
34
+ Size SizeHW
35
+ Title string
36
+ IconPath string
37
+ HasFrame bool
38
+ Session * session.Session
39
+ }
40
+
32
41
func checkUrl (s string ) (string , error ) {
33
42
u , err := url .Parse (s )
34
43
if err != nil {
@@ -47,39 +56,40 @@ func checkUrl(s string) (string, error) {
47
56
return u .String (), err
48
57
}
49
58
50
- func NewWindow (s string , sess * session.Session ) * Window {
51
- u , _ := checkUrl (s )
52
-
59
+ func NewWindow (options Options ) * Window {
53
60
w := Window {}
54
- w .Url = u
55
- if len (w .Url ) == 0 {
56
- w .Url = "http://google.com"
57
- }
61
+ w .setOptions (options )
58
62
_ , sendChannel := connection .GetCommunicationChannels ()
59
63
64
+ size := options .Size
65
+ if options .Size == (SizeHW {}) {
66
+ size = SizeHW {
67
+ Width : 1024 ,
68
+ Height : 768 ,
69
+ }
70
+ }
71
+
60
72
windowCreate := Command {
61
73
Action : "create" ,
62
74
ObjectType : "window" ,
63
75
Args : CommandArguments {
64
- RootUrl : w .Url ,
65
- Title : spawn .ApplicationName ,
66
- Size : SizeHW {
67
- Width : 1024 ,
68
- Height : 768 ,
69
- },
76
+ RootUrl : w .Url ,
77
+ Title : spawn .ApplicationName ,
78
+ Size : size ,
79
+ HasFrame : options .HasFrame ,
70
80
},
71
81
}
72
82
dispatcher .RegisterHandler (w .DispatchResponse )
73
- if sess == nil {
83
+ if options . Session == nil {
74
84
w .SetSendChannel (sendChannel )
75
85
w .WaitingResponses = append (w .WaitingResponses , & windowCreate )
76
86
w .Send (& windowCreate )
77
87
} else {
78
88
go func () {
79
89
for {
80
- if sess .TargetID != 0 {
81
- fmt .Println ("sess" , sess .TargetID )
82
- windowCreate .Args .SessionID = sess .TargetID
90
+ if options . Session .TargetID != 0 {
91
+ fmt .Println ("sess" , options . Session .TargetID )
92
+ windowCreate .Args .SessionID = options . Session .TargetID
83
93
w .SetSendChannel (sendChannel )
84
94
w .WaitingResponses = append (w .WaitingResponses , & windowCreate )
85
95
w .Send (& windowCreate )
@@ -92,6 +102,19 @@ func NewWindow(s string, sess *session.Session) *Window {
92
102
return & w
93
103
}
94
104
105
+ func (w * Window ) setOptions (options Options ) {
106
+ u , _ := checkUrl (options .RootUrl )
107
+ w .Url = u
108
+ if len (w .Url ) == 0 {
109
+ w .Url = "http://google.com"
110
+ }
111
+
112
+ w .Title = options .Title
113
+ if len (w .Title ) == 0 {
114
+ w .Title = spawn .ApplicationName
115
+ }
116
+ }
117
+
95
118
func (w * Window ) SetSendChannel (sendChannel * connection.In ) {
96
119
w .SendChannel = sendChannel
97
120
}
0 commit comments