Konfi-Castle-Kasino/pkg/windows/windows.go

100 lines
2.7 KiB
Go
Raw Normal View History

2019-09-02 20:19:12 +00:00
package windows
import (
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/config"
"github.com/asticode/go-astilectron"
2019-09-04 20:11:13 +00:00
"github.com/labstack/gommon/log"
2019-09-02 20:19:12 +00:00
)
2019-09-05 19:35:07 +00:00
// OpenWindows opens electron windows
2019-09-02 20:19:12 +00:00
func OpenWindows() {
2019-09-04 20:11:13 +00:00
// Webview viewer
/* err := webview.Open("Konfi@Castle Viewer", "http://127.0.0.1:8080", 800, 600, true)
if err != nil {
log.Fatal(err)
}*/
// Astilectron Bootstrapper and bundler
/*if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: "Konfi@Castle Kasino",
AppIconDarwinPath: "gopher.icns",
AppIconDefaultPath: "gopher.png",
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "http://127.0.0.1:8080",
Options: &astilectron.WindowOptions{
BackgroundColor: astilectron.PtrStr("#333"),
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(700),
Width: astilectron.PtrInt(700),
},
}},
}); err != nil {
log.Fatal("running bootstrap failed ", err)
//astilog.Fatal(errors.Wrap(err, "running bootstrap failed"))
}*/
// Astilectron classic
a, err := astilectron.New(astilectron.Options{
AppName: "Konfi@Castle Kasino",
2019-09-02 20:19:12 +00:00
AppIconDefaultPath: "gopher.png",
AppIconDarwinPath: "gopher.icns",
BaseDirectoryPath: "astilectron-deps",
2019-09-04 20:11:13 +00:00
})
if err != nil {
log.Error("creating new astilectron failed", err)
2019-09-02 20:19:12 +00:00
}
defer a.Close()
a.HandleSignals()
// Start
if err = a.Start(); err != nil {
2019-09-04 20:11:13 +00:00
log.Error("starting failed", err)
2019-09-02 20:19:12 +00:00
}
// Create Frontend window
var wFrontend *astilectron.Window
wFrontend, err = a.NewWindow("http://"+config.GetInterface(), &astilectron.WindowOptions{
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(800),
Width: astilectron.PtrInt(1200),
})
if err != nil {
2019-09-04 20:11:13 +00:00
log.Error("new window failed", err)
2019-09-02 20:19:12 +00:00
}
if err = wFrontend.Create(); err != nil {
2019-09-04 20:51:06 +00:00
log.Error("creating window failed ", err)
2019-09-02 20:19:12 +00:00
}
// If several displays, move the window to the second display
var displays = a.Displays()
if len(displays) > 1 {
if displays[1].IsPrimary() {
wFrontend.MoveInDisplay(displays[0], 50, 50)
} else {
wFrontend.MoveInDisplay(displays[1], 50, 50)
}
wFrontend.Maximize()
}
// Create Admin window
var wAdmin *astilectron.Window
if wAdmin, err = a.NewWindow("http://"+config.GetInterface()+"/admin", &astilectron.WindowOptions{
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(700),
Width: astilectron.PtrInt(1200),
}); err != nil {
2019-09-04 20:11:13 +00:00
log.Error("new window failed", err)
2019-09-02 20:19:12 +00:00
}
if err = wAdmin.Create(); err != nil {
2019-09-04 20:51:06 +00:00
log.Error("creating window failed ", err)
2019-09-02 20:19:12 +00:00
}
// Blocking pattern
a.Wait()
}