Skip to content

Commit 096c6b0

Browse files
Thrust Sessions, and AutoInstall improved
1 parent 36ead52 commit 096c6b0

File tree

12 files changed

+103
-38
lines changed

12 files changed

+103
-38
lines changed

commands/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type CommandArguments struct {
2323
Label string `json:"label,omitempty"`
2424
MenuID uint `json:"menu_id,omitempty"` // this should never be 0 anyway
2525
WindowID uint `json:"window_id,omitempty"`
26+
SessionID uint `json:"session_id,omitempty"`
2627
GroupID uint `json:"group_id,omitempty"`
2728
Value bool `json:"value"`
2829
CookieStore bool `json:"cookie_store"`

common/common.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
var ActionId uint = 0
1111

1212
const (
13-
SOCKET_BOUNDARY = "--(Foo)++__THRUST_SHELL_BOUNDARY__++(Bar)--"
14-
THRUST_VERSION = "0.7.0"
15-
THRUST_GO_VERSION = "0.1.0"
13+
SOCKET_BOUNDARY = "--(Foo)++__THRUST_SHELL_BOUNDARY__++(Bar)--"
1614
)
1715

1816
var Log log.Logger

common/versions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package common
2+
3+
const (
4+
THRUST_VERSION = "0.7.1"
5+
THRUST_GO_VERSION = "0.1.0"
6+
)

demo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/miketheprogrammer/go-thrust/connection"
1313
"github.com/miketheprogrammer/go-thrust/dispatcher"
1414
"github.com/miketheprogrammer/go-thrust/menu"
15+
"github.com/miketheprogrammer/go-thrust/session"
1516
"github.com/miketheprogrammer/go-thrust/spawn"
1617
"github.com/miketheprogrammer/go-thrust/window"
1718
)
@@ -37,16 +38,19 @@ func main() {
3738
}
3839
out, in := connection.GetCommunicationChannels()
3940

41+
mainSession := session.Session{}
42+
mainSession.Create(in)
43+
4044
thrustWindow := window.Window{
41-
Url: "http://brach.cc",
45+
Url: "http://breach.cc/",
4246
}
4347
rootMenu := menu.Menu{}
4448
fileMenu := menu.Menu{}
4549
checkList := menu.Menu{}
4650
radioList := menu.Menu{}
4751
viewMenu := menu.Menu{}
4852
// Calls to other methods after create are Queued until Create returns
49-
thrustWindow.Create(in)
53+
thrustWindow.Create(in, nil)
5054
thrustWindow.Show()
5155

5256
rootMenu.Create(in)
@@ -108,6 +112,10 @@ func main() {
108112
dispatcher.RegisterHandler(func(c commands.CommandResponse) {
109113
rootMenu.DispatchResponse(c)
110114
})
115+
116+
dispatcher.RegisterHandler(func(c commands.CommandResponse) {
117+
mainSession.DispatchResponse(c)
118+
})
111119
for {
112120
select {
113121
case response := <-out.CommandResponses:

makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
build.release:
2+
rm -rf release/vendor/darwin/x64/*
3+
touch release/vendor/darwin/x64/README.md
4+
rm -rf release/vendor/linux/x64/*
5+
touch release/vendor/linux/x64/README.md
6+
cp -rf tools release/
7+
rm -f release/Thrust
28
go build -o release/Thrust

release/tools/bootstrap_darwin.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
wget https://github.com/breach/thrust/releases/download/v0.7.0/thrust-v0.7.0-darwin-x64.zip
2-
mv thrust-v0.7.0-darwin-x64.zip ./vendor/darwin/x64
3-
cd ./vendor/darwin/x64
4-
unzip thrust-v0.7.0-darwin-x64.zip
5-
rm thrust-v0.7.0-darwin-x64.zip
1+
wget https://github.com/breach/thrust/releases/download/v$1/thrust-v$1-darwin-x64.zip
2+
mkdir -p ./vendor/darwin/x64/v$1
3+
mv thrust-v$1-darwin-x64.zip ./vendor/darwin/x64/v$1/thrust-v$1-darwin-x64.zip
4+
cd ./vendor/darwin/x64/v$1/
5+
unzip thrust-v$1-darwin-x64.zip
6+
rm thrust-v$1-darwin-x64.zip

release/tools/bootstrap_linux.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
wget https://github.com/breach/thrust/releases/download/v0.7.0/thrust-v0.7.0-linux-x64.zip
2-
mv thrust-v0.7.0-linux-x64.zip ./vendor/linux/x64
3-
cd ./vendor/linux/x64
4-
unzip thrust-v0.7.0-linux-x64.zip
5-
rm thrust-v0.7.0-linux-x64.zip
1+
wget https://github.com/breach/thrust/releases/download/v$1/thrust-v$1-linux-x64.zip
2+
mkdir -p ./vendor/linux/x64/v$1
3+
mv thrust-v$1-linux-x64.zip ./vendor/linux/x64/v$1
4+
cd ./vendor/linux/x64/$1
5+
unzip thrust-v$1-linux-x64.zip
6+
rm thrust-v$1-linux-x64.zip

session/session.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ type Session struct {
1515
ResponseHistory []*CommandResponse
1616
WaitingResponses []*Command
1717
CommandQueue []*Command
18+
SendChannel *connection.In
1819
}
1920

2021
func (session *Session) Create(sendChannel *connection.In) {
21-
command := commands.Commands{
22+
command := Command{
2223
Action: "create",
2324
ObjectType: "session",
2425
Args: CommandArguments{
2526
CookieStore: session.CookieStore,
2627
OffTheRecord: session.OffTheRecord,
2728
},
2829
}
30+
session.SendChannel = sendChannel
2931
session.WaitingResponses = append(session.WaitingResponses, &command)
3032
session.Send(&command)
3133
}
@@ -60,6 +62,15 @@ func (session *Session) HandleReply(reply CommandResponse) {
6062
}
6163
}
6264

65+
func (session *Session) DispatchResponse(reply CommandResponse) {
66+
switch reply.Action {
67+
case "event":
68+
session.HandleEvent(reply)
69+
case "reply":
70+
session.HandleReply(reply)
71+
}
72+
}
73+
6374
func (session *Session) InvokeCookiesLoad(response CommandResponse) {
6475

6576
}

spawn/spawn_process.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func SpawnThrustCore(addr string, autoloaderDisabled bool) (io.ReadCloser, io.Wr
1717
var thrustExecPath string
1818
var thrustBoostrapPath string
1919
if strings.Contains(runtime.GOOS, "darwin") {
20-
thrustExecPath = "./vendor/darwin/x64/ThrustShell.app/Contents/MacOS/ThrustShell"
20+
thrustExecPath = "./vendor/darwin/x64/v" + THRUST_VERSION + "/ThrustShell.app/Contents/MacOS/ThrustShell"
2121
thrustBoostrapPath = "./tools/bootstrap_darwin.sh"
2222
}
2323
if strings.Contains(runtime.GOOS, "linux") {
24-
thrustExecPath = "./vendor/linux/x64/thrust_shell"
24+
thrustExecPath = "./vendor/linux/x64/v" + THRUST_VERSION + "/thrust_shell"
2525
thrustBoostrapPath = "./tools/bootstrap_linux.sh"
2626
}
2727

@@ -30,14 +30,29 @@ func SpawnThrustCore(addr string, autoloaderDisabled bool) (io.ReadCloser, io.Wr
3030
Log.Info("Could not find executable:", thrustExecPath)
3131
Log.Info("Attempting to Download and Install the Thrust Core Executable")
3232

33-
installCmd := exec.Command("sh", thrustBoostrapPath)
34-
installCmd.Stdout = os.Stdout
35-
installCmd.Stderr = os.Stderr
33+
installCmd := exec.Command("sh", thrustBoostrapPath, THRUST_VERSION)
34+
if Log.LogDebug() {
35+
installCmd.Stdout = os.Stdout
36+
installCmd.Stderr = os.Stderr
37+
}
3638

39+
installDoneChan := make(chan bool, 1)
3740
installCmd.Start()
38-
Log.Info("Waiting for install to finish....")
39-
installErr := installCmd.Wait()
41+
fmt.Print("Installing ")
42+
go func() {
43+
for {
44+
select {
45+
case <-installDoneChan:
46+
return
47+
default:
48+
fmt.Print(".")
49+
time.Sleep(time.Second)
50+
}
51+
}
52+
}()
4053

54+
installErr := installCmd.Wait()
55+
installDoneChan <- true
4156
if installErr != nil {
4257
Log.Errorf("Could not bootstrap, ErrorCode:", err)
4358
} else {
@@ -67,7 +82,7 @@ func SpawnThrustCore(addr string, autoloaderDisabled bool) (io.ReadCloser, io.Wr
6782

6883
cmd.Start()
6984

70-
time.Sleep(time.Millisecond * 1000)
85+
//time.Sleep(time.Millisecond * 1000)
7186
Log.Info("Returning to Main Process.")
7287
return cmdOut, cmdIn
7388
} else {

tools/bootstrap_darwin.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
wget https://github.com/breach/thrust/releases/download/v0.7.1/thrust-v0.7.1-darwin-x64.zip
2-
mv thrust-v0.7.1-darwin-x64.zip ./vendor/darwin/x64
3-
cd ./vendor/darwin/x64
4-
unzip thrust-v0.7.1-darwin-x64.zip
5-
rm thrust-v0.7.1-darwin-x64.zip
1+
wget https://github.com/breach/thrust/releases/download/v$1/thrust-v$1-darwin-x64.zip
2+
mkdir -p ./vendor/darwin/x64/v$1
3+
mv thrust-v$1-darwin-x64.zip ./vendor/darwin/x64/v$1/thrust-v$1-darwin-x64.zip
4+
cd ./vendor/darwin/x64/v$1/
5+
unzip thrust-v$1-darwin-x64.zip
6+
rm thrust-v$1-darwin-x64.zip

0 commit comments

Comments
 (0)