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

79 lines
2.0 KiB
Go
Raw Normal View History

2019-09-02 20:19:12 +00:00
package windows
import (
"fmt"
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/config"
"github.com/asticode/go-astilectron"
"github.com/asticode/go-astilog"
"github.com/pkg/errors"
)
func OpenWindows() {
// Create astilectron
var a *astilectron.Astilectron
var err error
if a, err = astilectron.New(astilectron.Options{
AppName: "Astilectron",
AppIconDefaultPath: "gopher.png",
AppIconDarwinPath: "gopher.icns",
BaseDirectoryPath: "astilectron-deps",
}); err != nil {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "creating new astilectron failed"))
}
defer a.Close()
a.HandleSignals()
// Start
if err = a.Start(); err != nil {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "starting failed"))
}
// 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 {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "new window failed"))
}
if err = wFrontend.Create(); err != nil {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "creating window failed"))
}
// 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 {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "new window failed"))
}
if err = wAdmin.Create(); err != nil {
fmt.Println(err)
astilog.Fatal(errors.Wrap(err, "creating window failed"))
}
// Blocking pattern
a.Wait()
}