Skip to content

Commit

Permalink
Support for Linux/Windows, running in a web browser
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBanks committed Mar 24, 2017
1 parent 4ec1ca0 commit a5ca260
Show file tree
Hide file tree
Showing 59 changed files with 1,755 additions and 182 deletions.
81 changes: 46 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,60 +1,71 @@
VERSION = 0.2.0
VERSION = 0.3.0

BIN = ./bin

INSTALL_PKG = ./cmd/goggles
RELEASE_PLATFORMS = darwin/386 darwin/amd64 linux/386 linux/amd64 linux/arm windows/386 windows/amd64

BIN = ./bin
APP_INSTALL_PKG = ./cmd/goggles-app
APP_NAME = Goggles.app
APP_FOLDER = $(BIN)/$(APP_NAME)
APP_STATIC_FOLDER = $(APP_FOLDER)/Contents/MacOS/static
LOG_FILE = ~/Library/Logs/goggles.log

BUNDLE_ID = com.kylewbanks.goggles
BUNDLE_NAME = Goggles
APP_LOG_FILE = ~/Library/Logs/goggles.log
APP_BUNDLE_ID = com.kylewbanks.goggles
APP_BUNDLE_NAME = Goggles

# Runs goggles and opens the logs.
# Runs Goggles within a web browser.
#
# This is the default command.
run: | run.goggles
@tail -100f $(LOG_FILE)
.PHONY: run.logs
browser: | install
@goggles
.PHONY: browser

# Runs Goggles as a standalone app and opens the logs.
app: | build.app
@pkill Goggles || true
@open $(APP_FOLDER)
@tail -100f $(APP_LOG_FILE)
.PHONY: app

# Runs gulp on the static assets.
gulp:
@cd _static ; \
# Cleans, lints, and generates static assets.
assets:
@cd static ; \
npm install ; \
gulp
.PHONY: gulp

@go-bindata-assetfs -ignore=node_modules -pkg server static/... ; \
mv bindata_assetfs.go server/
.PHONY: assets

# Cleans any built artifacts.
clean:
@rm -rf $(BIN)
@rm -f $(LOG_FILE)
@rm -f $(APP_LOG_FILE)
.PHONY: clean

# Builds goggles to the ./bin directory.
build: | clean gulp
# Builds and installs Goggles as a browser application.
install: | clean assets
@go install -v $(INSTALL_PKG)
.PHONY: install

# Builds Goggles as a standalone app to the ./bin directory.
build.app: | clean assets
@mkdir -p $(BIN)
@go build -v -o $(BIN)/goggles $(INSTALL_PKG)
@gallium-bundle $(BIN)/goggles \
@go build -v -o $(BIN)/goggles-app $(APP_INSTALL_PKG)
@gallium-bundle $(BIN)/goggles-app \
--output $(APP_FOLDER) \
--identifier $(BUNDLE_ID) \
--name $(BUNDLE_NAME)
@mkdir -p $(APP_STATIC_FOLDER)
@cp -a ./_static/. $(APP_STATIC_FOLDER)
@rm -rf $(APP_STATIC_FOLDER)/node_modules
.PHONY: build

# Builds a release bundle.
release: | build
--identifier $(APP_BUNDLE_ID) \
--name $(APP_BUNDLE_NAME)
.PHONY: build.app

# Builds a release bundle for the standalone application, and
# binaries for the browser application.
release: | sanity build.app
@cd $(BIN) ; \
zip -r -y goggles.$(VERSION).zip $(APP_NAME)
.PHONY: release

# Runs the goggles application.
run.goggles: | build
@pkill Goggles || true
@open $(APP_FOLDER)
.PHONY: run
@gox -osarch="$(strip $(RELEASE_PLATFORMS))" \
-output "bin/{{.Dir}}_$(VERSION)_{{.OS}}_{{.Arch}}" $(INSTALL_PKG)
.PHONY: release

# Runs test cases in Docker.
test.docker:
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@

## Install

Goggles can be run in a web browser (cross-platform) or as a standalone application (Mac only).

### Stable

Grab the latest release from the [Releases](https://github.com/KyleBanks/goggles/releases) page.

### From Source

In order to build and run Goggles, there are a few steps you'll need to take:
Regardless, there are a few steps you'll need to take in order to build and run Goggles from source:

1. `go get github.com/KyleBanks/goggles/...`
2. Install [Gallium](https://github.com/alexflint/gallium), in order to bundle the `.app`.
3. Install [npm](https://www.npmjs.com/) and [Gulp](http://gulpjs.com/), in order to build the front-end assets.
4. Run `make` to build and launch the application.
2. Install [npm](https://www.npmjs.com/) and [Gulp](http://gulpjs.com/), in order to build the front-end assets.
3. Install [go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs) in order to bundle front-end assets into the Go binary.

#### Web Browser

1. Run `make` to build and run Goggles in your web browser.

#### Standalone (Mac Only)

1. Install [Gallium](https://github.com/alexflint/gallium), in order to bundle the `.app`.
2. Run `make app` to build and launch the application.

**Note:** Goggles is currently only available for Mac OS. If you'd like to see Goggles available on additional platforms, I encourage you to help contribute to the [Gallium](https://github.com/alexflint/gallium) project.
**Note:** If you'd like to see Goggles available as a standalone application on additional platforms, I encourage you to help contribute to the [Gallium](https://github.com/alexflint/gallium) project.

## Contributing

Expand All @@ -44,9 +54,9 @@ Goggles was developed by [Kyle Banks](https://twitter.com/kylewbanks).

## Thanks

The [Gopher](./_static/img) loading images were created by [Ashley McNamara](https://twitter.com/ashleymcnamara) and inspired by [Renee French](http://reneefrench.blogspot.co.uk/).
The [Gopher](./static/img) loading images were created by [Ashley McNamara](https://twitter.com/ashleymcnamara) and inspired by [Renee French](http://reneefrench.blogspot.co.uk/).

![Gopher](./_static/img/loader-1.png)
![Gopher](./static/img/loader-1.png)

## License

Expand Down
61 changes: 61 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Package cmd provides shared functionality for the multiple run-modes.
package cmd

import (
"fmt"
"log"
"net/http"
"os"

"github.com/KyleBanks/goggles"
"github.com/KyleBanks/goggles/conf"
"github.com/KyleBanks/goggles/pkg/sys"
"github.com/KyleBanks/goggles/server"
)

const (
aboutURL = "https://github.com/KyleBanks/goggles"
thanksURL = "https://github.com/KyleBanks/goggles#thanks"
)

var (
// port is the port number to listen on.
port = 10765

// Index is the URL of the root index.html file.
Index = fmt.Sprintf("http://127.0.0.1:%v/static/index.html", port)
)

func init() {
// Update the $GOPATH if a custom value is set.
c := conf.Get()
if c != nil && len(c.Gopath) > 0 {
sys.SetGopath(c.Gopath)
}

log.Printf("$GOPATH=%v, srcdir=%v", sys.Gopath(), sys.Srcdir())
}

// StartServer starts the application server.
func StartServer() {
p := provider{goggles.Service{}}
api := server.New(p)
addr := fmt.Sprintf(":%v", port)

log.Fatal(http.ListenAndServe(addr, api))
}

// OpenAbout opens the 'About' page in a web browser.
func OpenAbout() {
sys.OpenBrowser(aboutURL)
}

// OpenThanks opens the 'Thanks' page in a web browser.
func OpenThanks() {
sys.OpenBrowser(thanksURL)
}

// Quit terminates the running application.
func Quit() {
os.Exit(0)
}
24 changes: 24 additions & 0 deletions cmd/goggles-app/goggles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Package main handles running Goggles as a standalone native application.
package main

import (
"runtime"

"github.com/KyleBanks/goggles/cmd"
)

const (
title = "Goggles"
titleAbout = "About"
titleThanks = "Thanks"
titleDebug = "Debug"
titleQuit = "Quit"
)

func init() {
runtime.LockOSThread()
}

func startServer() {
cmd.StartServer()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"

"github.com/KyleBanks/goggles/cmd"
"github.com/alexflint/gallium"
)

Expand Down Expand Up @@ -34,11 +35,11 @@ var (
Entries: []gallium.MenuEntry{
gallium.MenuItem{
Title: titleAbout,
OnClick: openAbout,
OnClick: cmd.OpenAbout,
},
gallium.MenuItem{
Title: titleThanks,
OnClick: openThanks,
OnClick: cmd.OpenThanks,
},

gallium.Separator,
Expand All @@ -53,11 +54,13 @@ var (
gallium.MenuItem{
Title: titleQuit,
Shortcut: gallium.MustParseKeys("CMD+q"),
OnClick: quit,
OnClick: cmd.Quit,
},
},
},
}

logFile = os.ExpandEnv("$HOME/Library/Logs/goggles.log")
)

func main() {
Expand All @@ -67,7 +70,7 @@ func main() {

func onReady(app *gallium.App) {
var err error
window, err = app.OpenWindow(index, opts)
window, err = app.OpenWindow(cmd.Index, opts)
if err != nil {
log.Fatal(err)
}
Expand Down
File renamed without changes.
64 changes: 9 additions & 55 deletions cmd/goggles/goggles.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,18 @@
// Package main handles running Goggles in a web browser.
package main

import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"time"

"github.com/KyleBanks/goggles/conf"
"github.com/KyleBanks/goggles/goggles"
"github.com/KyleBanks/goggles/cmd"
"github.com/KyleBanks/goggles/pkg/sys"
"github.com/KyleBanks/goggles/server"
)

const (
port = 10765
func main() {
go func() {
time.Sleep(time.Millisecond * 500)
sys.OpenBrowser(cmd.Index)
}()

title = "Goggles"
titleAbout = "About"
titleThanks = "Thanks"
titleDebug = "Debug"
titleQuit = "Quit"

aboutURL = "https://github.com/KyleBanks/goggles"
thanksURL = "https://github.com/KyleBanks/goggles#thanks"
)

var (
logFile = os.ExpandEnv("$HOME/Library/Logs/goggles.log")
index = fmt.Sprintf("http://127.0.0.1:%v/static/index.html", port)
)

func init() {
runtime.LockOSThread()

// Update the $GOPATH if a custom value is set.
c := conf.Get()
if c != nil && len(c.Gopath) > 0 {
sys.SetGopath(c.Gopath)
}
}

func startServer() {
log.Printf("$GOPATH=%v, srcdir=%v", sys.Gopath(), sys.Srcdir())

p := provider{goggles.Service{}}
api := server.New(p, filepath.Dir(os.Args[0]))
addr := fmt.Sprintf(":%v", port)
log.Fatal(http.ListenAndServe(addr, api))
}

func openAbout() {
sys.OpenBrowser(aboutURL)
}

func openThanks() {
sys.OpenBrowser(thanksURL)
}

func quit() {
os.Exit(0)
cmd.StartServer()
}
6 changes: 4 additions & 2 deletions cmd/goggles/provider.go → cmd/provider.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main
package cmd

import (
"log"

"github.com/KyleBanks/goggles"
"github.com/KyleBanks/goggles/conf"
"github.com/KyleBanks/goggles/goggles"
"github.com/KyleBanks/goggles/pkg/sys"
)

// provider wraps the Goggles packages into a single type
// that can provide all functionality to the API.
type provider struct {
goggles.Service
}
Expand Down

0 comments on commit a5ca260

Please sign in to comment.