Skip to content

Commit a9a9ad5

Browse files
Merge pull request #55 from tsu-ku-ne/master
Refactor `NewWindow` by using struct
2 parents d02c68d + 211a55d commit a9a9ad5

File tree

16 files changed

+90
-33
lines changed

16 files changed

+90
-33
lines changed

examples/chat/client/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ func main() {
1717
thrust.InitLogger()
1818
thrust.Start()
1919

20-
thrustWindow := thrust.NewWindow(fmt.Sprintf("http://127.0.0.1:%d", *port), nil)
20+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
21+
RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
22+
})
2123
thrustWindow.Show()
2224
thrustWindow.Focus()
2325
// BLOCKING - Dont run before youve excuted all commands you want first.

examples/chat/server/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ func main() {
145145

146146
thrust.InitLogger()
147147
thrust.Start()
148-
thrustWindow := thrust.NewWindow(fmt.Sprintf("http://127.0.0.1:%d", *port), nil)
148+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
149+
RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
150+
})
149151
thrustWindow.Show()
150152
thrustWindow.Focus()
151153

examples/jankybrowser/browser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func main() {
3434
thrust.InitLogger()
3535
thrust.Start()
3636

37-
thrustWindow := thrust.NewWindow(fmt.Sprintf("http://127.0.0.1:%d", *port), nil)
37+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
38+
RootUrl: fmt.Sprintf("http://127.0.0.1:%d", *port),
39+
})
3840
thrustWindow.Show()
3941
thrustWindow.Focus()
4042

lib/bindings/window/window.go

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ type Window struct {
2929
SendChannel *connection.In `json:"-"`
3030
}
3131

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+
3241
func checkUrl(s string) (string, error) {
3342
u, err := url.Parse(s)
3443
if err != nil {
@@ -47,39 +56,40 @@ func checkUrl(s string) (string, error) {
4756
return u.String(), err
4857
}
4958

50-
func NewWindow(s string, sess *session.Session) *Window {
51-
u, _ := checkUrl(s)
52-
59+
func NewWindow(options Options) *Window {
5360
w := Window{}
54-
w.Url = u
55-
if len(w.Url) == 0 {
56-
w.Url = "http://google.com"
57-
}
61+
w.setOptions(options)
5862
_, sendChannel := connection.GetCommunicationChannels()
5963

64+
size := options.Size
65+
if options.Size == (SizeHW{}) {
66+
size = SizeHW{
67+
Width: 1024,
68+
Height: 768,
69+
}
70+
}
71+
6072
windowCreate := Command{
6173
Action: "create",
6274
ObjectType: "window",
6375
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,
7080
},
7181
}
7282
dispatcher.RegisterHandler(w.DispatchResponse)
73-
if sess == nil {
83+
if options.Session == nil {
7484
w.SetSendChannel(sendChannel)
7585
w.WaitingResponses = append(w.WaitingResponses, &windowCreate)
7686
w.Send(&windowCreate)
7787
} else {
7888
go func() {
7989
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
8393
w.SetSendChannel(sendChannel)
8494
w.WaitingResponses = append(w.WaitingResponses, &windowCreate)
8595
w.Send(&windowCreate)
@@ -92,6 +102,19 @@ func NewWindow(s string, sess *session.Session) *Window {
92102
return &w
93103
}
94104

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+
95118
func (w *Window) SetSendChannel(sendChannel *connection.In) {
96119
w.SendChannel = sendChannel
97120
}

lib/commands/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type CommandArguments struct {
4646
Fullscreen bool `json:"fullscreen"`
4747
Kiosk bool `json:"kiosk"`
4848
Focus bool `json:"focus"`
49+
HasFrame bool `json:"has_frame"`
4950
Path string `json:"path,omitempty"`
5051
Message RemoteMessage `json:"message,omitempty"`
5152
}

thrust/thrust.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ Begin Generic Access and Binding Management Section.
2121
Bindings
2222
*/
2323

24+
type WindowOptions window.Options
25+
2426
/* NewWindow creates a new Window Binding */
25-
func NewWindow(url string, sess *session.Session) *window.Window {
26-
return window.NewWindow(url, sess)
27+
func NewWindow(options WindowOptions) *window.Window {
28+
return window.NewWindow(window.Options(options))
2729
}
2830

2931
/* NewSession creates a new Session Binding */

tutorials/advanced_session/advanced_session.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ func main() {
3232
Modified basic_window, where we provide, a session argument
3333
to NewWindow.
3434
*/
35-
thrustWindow := thrust.NewWindow("http://breach.cc/", mysession)
35+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
36+
RootUrl: "http://breach.cc/",
37+
Session: mysession,
38+
})
3639
thrustWindow.Show()
3740
thrustWindow.Maximize()
3841
thrustWindow.Focus()

tutorials/advanced_window_devtools/advanced_window_devtools.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ func main() {
1313
thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
1414
// thrust.Start() must always come before any bindings are created.
1515
thrust.Start()
16-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
16+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
17+
RootUrl: "http://breach.cc/",
18+
})
1719
thrustWindow.Show()
1820
thrustWindow.Maximize()
1921
thrustWindow.Focus()

tutorials/basic_menu/basic_menu.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ func main() {
1111
thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
1212
// thrust.Start() must always come before any bindings are created.
1313
thrust.Start()
14-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
14+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
15+
RootUrl: "http://breach.cc/",
16+
})
1517
thrustWindow.Show()
1618
thrustWindow.Maximize()
1719
thrustWindow.Focus()

tutorials/basic_menu_events/basic_menu_events.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ func main() {
1515
thrust.SetProvisioner(tutorial.NewTutorialProvisioner())
1616
// thrust.Start() must always come before any bindings are created.
1717
thrust.Start()
18-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
18+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
19+
RootUrl: "http://breach.cc/",
20+
})
1921
thrustWindow.Show()
2022
thrustWindow.Maximize()
2123
thrustWindow.Focus()

tutorials/basic_multiple_windows/basic_multiple_windows.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ func main() {
1212
// thrust.Start() must always come before any bindings are created.
1313
thrust.Start()
1414

15-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
15+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
16+
RootUrl: "http://breach.cc/",
17+
})
1618
thrustWindow.Show()
1719
thrustWindow.Maximize()
1820
thrustWindow.Focus()
1921

20-
thrustWindow2 := thrust.NewWindow("http://google.com/", nil)
22+
thrustWindow2 := thrust.NewWindow(thrust.WindowOptions{
23+
RootUrl: "http://google.com/",
24+
})
2125
thrustWindow2.Show()
2226
thrustWindow2.Focus()
2327

tutorials/basic_remote_messaging/basic_remote_messaging.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func main() {
2222
// thrust.Start() must always come before any bindings are created.
2323
thrust.Start()
2424

25-
thrustWindow := thrust.NewWindow("http://localhost:8080/", nil)
25+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
26+
RootUrl: "http://localhost:8080/",
27+
})
2628
thrustWindow.Show()
2729
thrustWindow.Maximize()
2830
thrustWindow.Focus()

tutorials/basic_session/basic_session.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ func main() {
2525
Modified basic_window, where we provide, a session argument
2626
to NewWindow.
2727
*/
28-
thrustWindow := thrust.NewWindow("http://breach.cc/", mysession)
28+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
29+
RootUrl: "http://breach.cc/",
30+
Session: mysession,
31+
})
2932
thrustWindow.Show()
3033
thrustWindow.Maximize()
3134
thrustWindow.Focus()

tutorials/basic_webserver_app/basic_webserver_app.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ func main() {
2222

2323
mysession := thrust.NewSession(false, false, "cache")
2424

25-
thrustWindow := thrust.NewWindow("http://localhost:8080/", mysession)
25+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
26+
RootUrl: "http://localhost:8080/",
27+
Session: mysession,
28+
})
2629
thrustWindow.Show()
2730
thrustWindow.Maximize()
2831
thrustWindow.Focus()

tutorials/basic_window/basic_window.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ func main() {
1515
// thrust.Start() must always come before any bindings are created.
1616
thrust.Start()
1717

18-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
18+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
19+
RootUrl: "http://breach.cc/",
20+
})
1921
thrustWindow.Show()
2022
thrustWindow.Maximize()
2123
thrustWindow.Focus()

tutorials/basic_window_events/basic_window_events.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func main() {
2424
// thrust.Start() must always come before any bindings are created.
2525
thrust.Start()
2626

27-
thrustWindow := thrust.NewWindow("http://breach.cc/", nil)
27+
thrustWindow := thrust.NewWindow(thrust.WindowOptions{
28+
RootUrl: "http://breach.cc/",
29+
})
2830
thrustWindow.Show()
2931

3032
/*

0 commit comments

Comments
 (0)