Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Updated debug handling
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Mar 10, 2018
1 parent cd4c8a6 commit 8955917
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/asticode/go-astilectron"
"github.com/asticode/go-astilectron-bundler"
"github.com/asticode/go-astilog"
"github.com/asticode/go-astitools/ptr"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -66,11 +67,6 @@ func Run(o Options) (err error) {
return errors.Wrap(err, "starting astilectron failed")
}

// Debug
if o.Debug {
o.WindowOptions.Width = astilectron.PtrInt(*o.WindowOptions.Width + 700)
}

// Init window
var w *astilectron.Window
if w, err = a.NewWindow(filepath.Join(a.Paths().BaseDirectory(), "resources", "app", o.Homepage), o.WindowOptions); err != nil {
Expand All @@ -89,8 +85,42 @@ func Run(o Options) (err error) {

// Debug
if o.Debug {
if err = w.OpenDevTools(); err != nil {
return errors.Wrap(err, "opening dev tools failed")
// Create menu item
var debug bool
width := *o.WindowOptions.Width
mi := &astilectron.MenuItemOptions{
Accelerator: astilectron.NewAccelerator("d"),
Label: astiptr.Str("Debug"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
if debug {
if err := w.CloseDevTools(); err != nil {
astilog.Error(errors.Wrap(err, "closing dev tools failed"))
}
if err := w.Resize(width, *o.WindowOptions.Height); err != nil {
astilog.Error(errors.Wrap(err, "resizing window failed"))
}
} else {
if err := w.OpenDevTools(); err != nil {
astilog.Error(errors.Wrap(err, "opening dev tools failed"))
}
if err := w.Resize(width+700, *o.WindowOptions.Height); err != nil {
astilog.Error(errors.Wrap(err, "resizing window failed"))
}
}
debug = !debug
return
},
Type: astilectron.MenuItemTypeCheckbox,
}

// Add menu item
if len(o.MenuOptions) == 0 {
o.MenuOptions = []*astilectron.MenuItemOptions{{SubMenu: []*astilectron.MenuItemOptions{mi}}}
} else {
if len(o.MenuOptions[0].SubMenu) > 0 {
o.MenuOptions[0].SubMenu = append(o.MenuOptions[0].SubMenu, &astilectron.MenuItemOptions{Type: astilectron.MenuItemTypeSeparator})
}
o.MenuOptions[0].SubMenu = append(o.MenuOptions[0].SubMenu, mi)
}
}

Expand Down

0 comments on commit 8955917

Please sign in to comment.