Unverified Commit 2f8d7cb1 authored by bryanl's avatar bryanl
Browse files

Configure go app to boot in electron

This is the minimum amount of effort to make the application boot
parent 5b636f29
Showing with 136 additions and 0 deletions
+136 -0
......@@ -17,3 +17,11 @@ rice-box.go
/build
/dist
# electron bundling
/vendor/astilectron*
/vendor/electron*
/vendor/status.json
/output
/cmd/devdash/bind*.go
/cmd/devdash/windows.syso
package main
import (
"encoding/json"
"time"
astilectron "github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
astilog "github.com/asticode/go-astilog"
"github.com/pkg/errors"
)
var (
AppName string
BuiltAt string
w *astilectron.Window
)
const htmlAbout = `Welcome on <b>Astilectron</b> demo!<br>
This is using the bootstrap and the bundler.`
func main() {
astilog.FlagInit()
// Run bootstrap
astilog.Debugf("Running app built at %s", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: AppName,
AppIconDarwinPath: "resources/icon.icns",
AppIconDefaultPath: "resources/icon.png",
},
Debug: true,
MenuOptions: []*astilectron.MenuItemOptions{{
Label: astilectron.PtrStr("File"),
SubMenu: []*astilectron.MenuItemOptions{
{
Label: astilectron.PtrStr("About"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
if err := bootstrap.SendMessage(w, "about", htmlAbout, func(m *bootstrap.MessageIn) {
// Unmarshal payload
var s string
if err := json.Unmarshal(m.Payload, &s); err != nil {
astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
return
}
astilog.Infof("About modal has been displayed and payload is %s!", s)
}); err != nil {
astilog.Error(errors.Wrap(err, "sending about event failed"))
}
return
},
},
{Role: astilectron.MenuItemRoleClose},
},
}},
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
w = ws[0]
go func() {
time.Sleep(5 * time.Second)
if err := bootstrap.SendMessage(w, "check.out.menu", "Don't forget to check out the menu!"); err != nil {
astilog.Error(errors.Wrap(err, "sending check.out.menu event failed"))
}
}()
return nil
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "http://localhost:3001",
MessageHandler: handleMessages,
Options: &astilectron.WindowOptions{
BackgroundColor: astilectron.PtrStr("#333"),
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(1280),
Width: astilectron.PtrInt(1024),
},
}},
}); err != nil {
astilog.Fatal(errors.Wrap(err, "running bootstrap failed"))
}
}
func handleMessages(_ *astilectron.Window, m bootstrap.MessageIn) (payload interface{}, err error) {
switch m.Name {
case "explore":
// Unmarshal payload
var path string
if len(m.Payload) > 0 {
// Unmarshal payload
if err = json.Unmarshal(m.Payload, &path); err != nil {
payload = err.Error()
return
}
}
// Explore
}
return
}
{
"app_name": "Test",
"icon_path_darwin": "configs/electron/icon.icns",
"icon_path_linux": "configs/electron/icon.png",
"icon_path_windows": "configs/electron/icon.ico",
"input_path": "cmd/devdash",
"resources_path": "../../configs/electron",
"environments": [
{"arch": "amd64", "os": "darwin"},
{"arch": "amd64", "os": "linux"},
{"arch": "amd64", "os": "windows"}
]
}
File added
cmd/devdash/resources/icon.ico

32.9 KB

cmd/devdash/resources/icon.png

20.3 KB

{
"app_name": "Test",
"icon_path_darwin": "cmd/devdash/resources/icon.icns",
"icon_path_linux": "cmd/devdash/resources/icon.png",
"icon_path_windows": "cmd/devdash/resources/icon.ico",
"input_path": "cmd/devdash",
"environments": [
{"arch": "amd64", "os": "darwin"},
{"arch": "amd64", "os": "linux"},
{"arch": "amd64", "os": "windows"}
]
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment