Skip to content

Commit

Permalink
single binary refactoring and tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheprogrammer committed Feb 11, 2016
1 parent 09e4c1a commit 3e234a8
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 64 deletions.
15 changes: 13 additions & 2 deletions README.md
Expand Up @@ -51,6 +51,18 @@ Start Go Thrust using source and GoLang runtime
go run tutorials/basic_window/basic_window.go
```

For Single Binary Install please use the tutorial
```bash
cd tutorials/advanced_single_binary_distribution
mkdir vendor
cd vendor
wget https://github.com/breach/thrust/releases/download/v0.7.6/thrust-v0.7.6-darwin-x64.zip
cd ..
go-bindata -pkg provisioner -o provisioner/vendor.go vendor/
go run advanced_single_binary_distribution.go

```

Forward:
==================
Go-Thrust is a cross platform GUI Application development base. It aims to provide the
Expand Down Expand Up @@ -80,7 +92,7 @@ Helper methods receive the UpperCamelCase version of their relative names in Thr

i.e. insert_item_at == InsertItemAt

Please note that the intended use case of Application Menus is to only support
Please note that the intended use case of Application Menus is to only support
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


Expand All @@ -101,4 +113,3 @@ The Future of Go-Thrust
================
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.
```
8 changes: 7 additions & 1 deletion lib/spawn/download.go
Expand Up @@ -3,19 +3,25 @@ package spawn
import (
"errors"
"fmt"
"github.com/cheggaaa/pb"
"io"
"net/http"
"os"
"strings"
"time"

"github.com/cheggaaa/pb"

. "github.com/miketheprogrammer/go-thrust/lib/common"
)

func downloadFromUrl(url, filepath, version string) (fileName string, err error) {
url = strings.Replace(url, "$V", version, 2)
fileName = strings.Replace(filepath, "$V", version, 1)
if PathNotExist(fileName) == false {
fmt.Println("Thrust already exists on filesystem .... skipping")
return
}
fmt.Println("Extract directory was", GetDownloadPath())
fmt.Println("Downloading", url, "to", fileName)

output, err := os.Create(fileName)
Expand Down
98 changes: 57 additions & 41 deletions lib/spawn/helper_darwin.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

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

func GetAppDirectory() string {
/*
GetDownloadPath gets the download or extract directory for Thrust
*/
func GetDownloadPath() string {
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
}

/*
Get the path to the .app directory (only OSX)
*/
func getAppDirectory() string {
return base + "/vendor/darwin/x64/v" + thrustVersion + "/" + ApplicationName + ".app"
}

Expand All @@ -28,18 +39,18 @@ func GetExecutablePath() string {
}

/*
GetDownloadUrl returns the interpolatable version of the Thrust download url
GetDownloadURL returns the interpolatable version of the Thrust download url
Differs between builds based on OS
*/
func GetDownloadUrl() string {
func GetDownloadURL() string {
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-darwin-x64.zip"
}

/*
SetThrustApplicationTitle sets the title in the Info.plist. This method only exists on Darwin.
*/
func Bootstrap() error {
if executableNotExist() == true {
if ExecutableNotExist() == true {
var err error
if err = prepareExecutable(); err != nil {
return err
Expand All @@ -55,14 +66,15 @@ func Bootstrap() error {
}

/*
executableNotExist checks if the executable does not exist
ExecutableNotExist checks if the executable does not exist
*/
func executableNotExist() bool {
func ExecutableNotExist() bool {
_, err := os.Stat(GetExecutablePath())
fmt.Println(err)
return os.IsNotExist(err)
}

func pathNotExist(path string) bool {
func PathNotExist(path string) bool {
_, err := os.Stat(path)
return os.IsNotExist(err)
}
Expand All @@ -71,19 +83,23 @@ func pathNotExist(path string) bool {
prepareExecutable dowloads, unzips and does alot of other magic to prepare our thrust core build.
*/
func prepareExecutable() error {
path, err := downloadFromUrl(GetDownloadUrl(), base+"/$V", thrustVersion)
path, err := downloadFromUrl(GetDownloadURL(), base+"/$V", thrustVersion)
if err != nil {
return err
}
if err = unzip(path, GetThrustDirectory()); err != nil {

return UnzipExecutable(path)
}

func UnzipExecutable(path string) error {
if err := unzip(path, GetThrustDirectory()); err != nil {
return err
}
os.Rename(GetThrustDirectory()+"/ThrustShell.app/Contents/MacOS/ThrustShell", GetThrustDirectory()+"/ThrustShell.app/Contents/MacOS/"+ApplicationName)
os.Rename(GetThrustDirectory()+"/ThrustShell.app", GetThrustDirectory()+"/"+ApplicationName+".app")

if err = applySymlinks(); err != nil {
if err := applySymlinks(); err != nil {
panic(err)
return err
}

return nil
Expand All @@ -95,88 +111,88 @@ ApplySymLinks exists because our unzip utility does not respect deferred symlink
func applySymlinks() error {
fmt.Println("Removing bad symlinks")
var err error
if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == false {
if err = os.Remove(GetAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == false {
if err = os.Remove(getAppDirectory() + "/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
return err
}
}

fmt.Println("Applying Symlinks")

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Frameworks",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Frameworks",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Frameworks"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Libraries"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Resources",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Resources",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Resources"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/ThrustShell Framework",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/ThrustShell Framework",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/ThrustShell Framework"); err != nil {
return err
}
}

if pathNotExist(GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == true {
if PathNotExist(getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries") == true {
if err = os.Symlink(
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A/Libraries/Libraries",
GetAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/A/Libraries/Libraries",
getAppDirectory()+"/Contents/Frameworks/ThrustShell Framework.framework/Versions/Current/Libraries"); err != nil {
return err
}
}
Expand Down
23 changes: 19 additions & 4 deletions lib/spawn/helper_linux.go
Expand Up @@ -14,6 +14,13 @@ func GetThrustDirectory() string {
return filepath.Join(base, "vendor", "linux", "x64", thrustVersion)
}

/*
GetDownloadDirectory gets the download or extract directory for Thrust
*/
func GetDownloadPath() string {
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
}

/*
GetExecutablePath returns the path to the Thrust Executable
Differs between builds based on OS
Expand All @@ -23,13 +30,16 @@ func GetExecutablePath() string {
}

/*
GetDownloadUrl returns the interpolatable version of the Thrust download url
GetDownloadURL returns the interpolatable version of the Thrust download url
Differs between builds based on OS
*/
func GetDownloadUrl() string {
func GetDownloadURL() string {
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-linux-x64.zip"
}

/*
Bootstrap executes the default bootstrapping plan for this system and returns an error if failed
*/
func Bootstrap() error {
if executableNotExist() == true {
return prepareExecutable()
Expand All @@ -43,9 +53,14 @@ func executableNotExist() bool {
}

func prepareExecutable() error {
_, err := downloadFromUrl(GetDownloadUrl(), base+"/$V", thrustVersion)
path, err := downloadFromUrl(GetDownloadURL(), base+"/$V", thrustVersion)
if err != nil {
return err
}
return unzip(strings.Replace(base+"/$V", "$V", thrustVersion, 1), GetThrustDirectory())

return UnzipExecutable(path)
}

func UnzipExecutable(path string) error {
return unzip(path, GetThrustDirectory())
}
26 changes: 16 additions & 10 deletions lib/spawn/helper_windows.go
Expand Up @@ -4,8 +4,6 @@ import (
"os"
"path/filepath"
"strings"

"github.com/miketheprogrammer/go-thrust/lib/common"
)

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

/*
GetDownloadDirectory gets the download or extract directory for Thrust
*/
func GetDownloadPath() string {
return strings.Replace(filepath.Join(base, "$V"), "$V", thrustVersion, 1)
}

/*
GetExecutablePath returns the path to the Thrust Executable
Differs between builds based on OS
Expand All @@ -25,10 +30,10 @@ func GetExecutablePath() string {
}

/*
GetDownloadUrl returns the interpolatable version of the Thrust download url
GetDownloadURL returns the interpolatable version of the Thrust download url
Differs between builds based on OS
*/
func GetDownloadUrl() string {
func GetDownloadURL() string {
//https://github.com/breach/thrust/releases/download/v0.7.5/thrust-v0.7.5-win32-ia32.zip
return "https://github.com/breach/thrust/releases/download/v$V/thrust-v$V-win32-ia32.zip"
}
Expand All @@ -49,13 +54,14 @@ func executableNotExist() bool {
}

func prepareExecutable() error {
common.Log.Print(base + "\\$V")
_, err := downloadFromUrl(GetDownloadUrl(), base+"\\$V", thrustVersion)
path, err := downloadFromUrl(GetDownloadURL(), base+"\\$V", thrustVersion)
if err != nil {
return err
}
if err = unzip(strings.Replace(base+"\\$V", "$V", thrustVersion, 1), GetThrustDirectory()); err != nil {
return err
}
return nil

return UnzipExecutable(path)
}

func UnzipExecutable(path string) error {
return unzip(path, GetThrustDirectory())
}
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/codegangsta/cli"
"github.com/miketheprogrammer/go-thrust/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/miketheprogrammer/go-thrust/lib/spawn"
)

Expand Down

0 comments on commit 3e234a8

Please sign in to comment.