Skip to content

Instantly share code, notes, and snippets.

@lloeki
Created May 1, 2015 10:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lloeki/78ae29ef865efaa42af3 to your computer and use it in GitHub Desktop.
Save lloeki/78ae29ef865efaa42af3 to your computer and use it in GitHub Desktop.
Using GopherJS and Electron together
// Electron's quick start sample, naively ported to Go
// https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md
//
// go get -u gopherjs
// gopherjs build main.go
// electron $(pwd)
package main
import (
"fmt"
"github.com/gopherjs/gopherjs/js"
"path"
"runtime"
)
func main() {
fmt.Printf("js: %v\n", js.Global.Get("process").Get("version"))
fmt.Printf("electron: %v\n", js.Global.Get("process").Get("versions").Get("electron"))
app := js.Global.Call("require", "app")
browserWindow := js.Global.Call("require", "browser-window")
crashReporter := js.Global.Call("require", "crash-reporter")
crashReporter.Call("start")
var mainWindow *js.Object
app.Call("on", "window-all-closed", func() {
if js.Global.Get("process").Get("platform").String() != "darwin" {
app.Call("quit")
}
})
app.Call("on", "ready", func() {
geom := map[string]int{"width": 800, "height": 600}
mainWindow = browserWindow.New(geom)
// and load the index.html of the app.
_, filename, _, _ := runtime.Caller(1)
url := "file://" + path.Join(path.Dir(filename), "index.html")
mainWindow.Call("loadUrl", url)
// Emitted when the window is closed.
mainWindow.Call("on", "closed", func() {
mainWindow = nil
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment