Skip to content

Commit 3e234a8

Browse files
single binary refactoring and tutorial
1 parent 09e4c1a commit 3e234a8

File tree

12 files changed

+206
-64
lines changed

12 files changed

+206
-64
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ Start Go Thrust using source and GoLang runtime
5151
go run tutorials/basic_window/basic_window.go
5252
```
5353

54+
For Single Binary Install please use the tutorial
55+
```bash
56+
cd tutorials/advanced_single_binary_distribution
57+
mkdir vendor
58+
cd vendor
59+
wget https://github.com/breach/thrust/releases/download/v0.7.6/thrust-v0.7.6-darwin-x64.zip
60+
cd ..
61+
go-bindata -pkg provisioner -o provisioner/vendor.go vendor/
62+
go run advanced_single_binary_distribution.go
63+
64+
```
65+
5466
Forward:
5567
==================
5668
Go-Thrust is a cross platform GUI Application development base. It aims to provide the
@@ -80,7 +92,7 @@ Helper methods receive the UpperCamelCase version of their relative names in Thr
8092

8193
i.e. insert_item_at == InsertItemAt
8294

83-
Please note that the intended use case of Application Menus is to only support
95+
Please note that the intended use case of Application Menus is to only support
8496
OSX and Unity/X11 global menu bars. This means that you should implement most menus in html and javascript, using IPC/RPC to communicate with the host application. The side effect is primarily that Windows, and certain unix/linux systems will not load ApplicationMenus
8597

8698

@@ -101,4 +113,3 @@ The Future of Go-Thrust
101113
================
102114
Any user of Go-Thrust should feel free to contribute ideas, code, anything that can help move this project in the right direction. The ideal goal is to stay as much out of the way, but still provide a useful system.
103115
```
104-

lib/spawn/download.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ package spawn
33
import (
44
"errors"
55
"fmt"
6-
"github.com/cheggaaa/pb"
76
"io"
87
"net/http"
98
"os"
109
"strings"
1110
"time"
1211

12+
"github.com/cheggaaa/pb"
13+
1314
. "github.com/miketheprogrammer/go-thrust/lib/common"
1415
)
1516

1617
func downloadFromUrl(url, filepath, version string) (fileName string, err error) {
1718
url = strings.Replace(url, "$V", version, 2)
1819
fileName = strings.Replace(filepath, "$V", version, 1)
20+
if PathNotExist(fileName) == false {
21+
fmt.Println("Thrust already exists on filesystem .... skipping")
22+
return
23+
}
24+
fmt.Println("Extract directory was", GetDownloadPath())
1925
fmt.Println("Downloading", url, "to", fileName)
2026

2127
output, err := os.Create(fileName)

lib/spawn/helper_darwin.go

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7+
"path/filepath"
78
"strings"
89
)
910

@@ -15,7 +16,17 @@ func GetThrustDirectory() string {
1516
return base + "/vendor/darwin/x64/v" + thrustVersion
1617
}
1718

18-
func GetAppDirectory() string {
19+
/*
20+
GetDownloadPath gets the download or extract directory for Thrust
21+
*/
22+
func GetDownloadPath() string {
23+
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
24+
}
25+
26+
/*
27+
Get the path to the .app directory (only OSX)
28+
*/
29+
func getAppDirectory() string {
1930
return base + "/vendor/darwin/x64/v" + thrustVersion + "/" + ApplicationName + ".app"
2031
}
2132

@@ -28,18 +39,18 @@ func GetExecutablePath() string {
2839
}
2940

3041
/*
31-
GetDownloadUrl returns the interpolatable version of the Thrust download url
42+
GetDownloadURL returns the interpolatable version of the Thrust download url
3243
Differs between builds based on OS
3344
*/
34-
func GetDownloadUrl() string {
45+
func GetDownloadURL() string {
3546
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-darwin-x64.zip"
3647
}
3748

3849
/*
3950
SetThrustApplicationTitle sets the title in the Info.plist. This method only exists on Darwin.
4051
*/
4152
func Bootstrap() error {
42-
if executableNotExist() == true {
53+
if ExecutableNotExist() == true {
4354
var err error
4455
if err = prepareExecutable(); err != nil {
4556
return err
@@ -55,14 +66,15 @@ func Bootstrap() error {
5566
}
5667

5768
/*
58-
executableNotExist checks if the executable does not exist
69+
ExecutableNotExist checks if the executable does not exist
5970
*/
60-
func executableNotExist() bool {
71+
func ExecutableNotExist() bool {
6172
_, err := os.Stat(GetExecutablePath())
73+
fmt.Println(err)
6274
return os.IsNotExist(err)
6375
}
6476

65-
func pathNotExist(path string) bool {
77+
func PathNotExist(path string) bool {
6678
_, err := os.Stat(path)
6779
return os.IsNotExist(err)
6880
}
@@ -71,19 +83,23 @@ func pathNotExist(path string) bool {
7183
prepareExecutable dowloads, unzips and does alot of other magic to prepare our thrust core build.
7284
*/
7385
func prepareExecutable() error {
74-
path, err := downloadFromUrl(GetDownloadUrl(), base+"/$V", thrustVersion)
86+
path, err := downloadFromUrl(GetDownloadURL(), base+"/$V", thrustVersion)
7587
if err != nil {
7688
return err
7789
}
78-
if err = unzip(path, GetThrustDirectory()); err != nil {
90+
91+
return UnzipExecutable(path)
92+
}
93+
94+
func UnzipExecutable(path string) error {
95+
if err := unzip(path, GetThrustDirectory()); err != nil {
7996
return err
8097
}
8198
os.Rename(GetThrustDirectory()+"/ThrustShell.app/Contents/MacOS/ThrustShell", GetThrustDirectory()+"/ThrustShell.app/Contents/MacOS/"+ApplicationName)
8299
os.Rename(GetThrustDirectory()+"/ThrustShell.app", GetThrustDirectory()+"/"+ApplicationName+".app")
83100

84-
if err = applySymlinks(); err != nil {
101+
if err := applySymlinks(); err != nil {
85102
panic(err)
86-
return err
87103
}
88104

89105
return nil
@@ -95,88 +111,88 @@ ApplySymLinks exists because our unzip utility does not respect deferred symlink
95111
func applySymlinks() error {
96112
fmt.Println("Removing bad symlinks")
97113
var err error
98-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == false {
99-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
114+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == false {
115+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
100116
return err
101117
}
102118
}
103119

104-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == false {
105-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
120+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == false {
121+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
106122
return err
107123
}
108124
}
109125

110-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == false {
111-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
126+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == false {
127+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
112128
return err
113129
}
114130
}
115131

116-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == false {
117-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
132+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == false {
133+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
118134
return err
119135
}
120136
}
121137

122-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == false {
123-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
138+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == false {
139+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
124140
return err
125141
}
126142
}
127143

128-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == false {
129-
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
144+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == false {
145+
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
130146
return err
131147
}
132148
}
133149

134150
fmt.Println("Applying Symlinks")
135151

136-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == true {
152+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == true {
137153
if err = os.Symlink(
138-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A",
139-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
154+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A",
155+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
140156
return err
141157
}
142158
}
143159

144-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == true {
160+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == true {
145161
if err = os.Symlink(
146-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Frameworks",
147-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
162+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Frameworks",
163+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
148164
return err
149165
}
150166
}
151167

152-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == true {
168+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == true {
153169
if err = os.Symlink(
154-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries",
155-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
170+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries",
171+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
156172
return err
157173
}
158174
}
159175

160-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == true {
176+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == true {
161177
if err = os.Symlink(
162-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Resources",
163-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
178+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Resources",
179+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
164180
return err
165181
}
166182
}
167183

168-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == true {
184+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == true {
169185
if err = os.Symlink(
170-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/ThrustShell Framework",
171-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
186+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/ThrustShell Framework",
187+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
172188
return err
173189
}
174190
}
175191

176-
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == true {
192+
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == true {
177193
if err = os.Symlink(
178-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A/Libraries/Libraries",
179-
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
194+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A/Libraries/Libraries",
195+
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
180196
return err
181197
}
182198
}

lib/spawn/helper_linux.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ func GetThrustDirectory() string {
1414
return filepath.Join(base, "vendor", "linux", "x64", thrustVersion)
1515
}
1616

17+
/*
18+
GetDownloadDirectory gets the download or extract directory for Thrust
19+
*/
20+
func GetDownloadPath() string {
21+
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
22+
}
23+
1724
/*
1825
GetExecutablePath returns the path to the Thrust Executable
1926
Differs between builds based on OS
@@ -23,13 +30,16 @@ func GetExecutablePath() string {
2330
}
2431

2532
/*
26-
GetDownloadUrl returns the interpolatable version of the Thrust download url
33+
GetDownloadURL returns the interpolatable version of the Thrust download url
2734
Differs between builds based on OS
2835
*/
29-
func GetDownloadUrl() string {
36+
func GetDownloadURL() string {
3037
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-linux-x64.zip"
3138
}
3239

40+
/*
41+
Bootstrap executes the default bootstrapping plan for this system and returns an error if failed
42+
*/
3343
func Bootstrap() error {
3444
if executableNotExist() == true {
3545
return prepareExecutable()
@@ -43,9 +53,14 @@ func executableNotExist() bool {
4353
}
4454

4555
func prepareExecutable() error {
46-
_, err := downloadFromUrl(GetDownloadUrl(), base+"/$V", thrustVersion)
56+
path, err := downloadFromUrl(GetDownloadURL(), base+"/$V", thrustVersion)
4757
if err != nil {
4858
return err
4959
}
50-
return unzip(strings.Replace(base+"/$V", "$V", thrustVersion, 1), GetThrustDirectory())
60+
61+
return UnzipExecutable(path)
62+
}
63+
64+
func UnzipExecutable(path string) error {
65+
return unzip(path, GetThrustDirectory())
5166
}

lib/spawn/helper_windows.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"os"
55
"path/filepath"
66
"strings"
7-
8-
"github.com/miketheprogrammer/go-thrust/lib/common"
97
)
108

119
/*
@@ -16,6 +14,13 @@ func GetThrustDirectory() string {
1614
return filepath.Join(base, "vendor", "windows", "ia32", thrustVersion)
1715
}
1816

17+
/*
18+
GetDownloadDirectory gets the download or extract directory for Thrust
19+
*/
20+
func GetDownloadPath() string {
21+
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
22+
}
23+
1924
/*
2025
GetExecutablePath returns the path to the Thrust Executable
2126
Differs between builds based on OS
@@ -25,10 +30,10 @@ func GetExecutablePath() string {
2530
}
2631

2732
/*
28-
GetDownloadUrl returns the interpolatable version of the Thrust download url
33+
GetDownloadURL returns the interpolatable version of the Thrust download url
2934
Differs between builds based on OS
3035
*/
31-
func GetDownloadUrl() string {
36+
func GetDownloadURL() string {
3237
//https://github.com/breach/thrust/releases/download/v0.7.5/thrust-v0.7.5-win32-ia32.zip
3338
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-win32-ia32.zip"
3439
}
@@ -49,13 +54,14 @@ func executableNotExist() bool {
4954
}
5055

5156
func prepareExecutable() error {
52-
common.Log.Print(base + "\\$V")
53-
_, err := downloadFromUrl(GetDownloadUrl(), base+"\\$V", thrustVersion)
57+
path, err := downloadFromUrl(GetDownloadURL(), base+"\\$V", thrustVersion)
5458
if err != nil {
5559
return err
5660
}
57-
if err = unzip(strings.Replace(base+"\\$V", "$V", thrustVersion, 1), GetThrustDirectory()); err != nil {
58-
return err
59-
}
60-
return nil
61+
62+
return UnzipExecutable(path)
63+
}
64+
65+
func UnzipExecutable(path string) error {
66+
return unzip(path, GetThrustDirectory())
6167
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/codegangsta/cli"
7+
"github.com/miketheprogrammer/go-thrust/Godeps/_workspace/src/github.com/codegangsta/cli"
88
"github.com/miketheprogrammer/go-thrust/lib/spawn"
99
)
1010

0 commit comments

Comments
 (0)