Fix race condition in closing window during navigating

Add sane defaults
This commit is contained in:
Lea Anthony 2022-12-09 08:22:17 +11:00
commit d5e21d5003
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
7 changed files with 147 additions and 145 deletions

View file

@ -2,7 +2,4 @@ module github.com/wailsapp/wails/exp
go 1.19
require (
github.com/gofrs/uuid v4.3.1+incompatible
github.com/leaanthony/clir v1.3.0
)
require github.com/leaanthony/clir v1.3.0

View file

@ -1,4 +1,2 @@
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/leaanthony/clir v1.3.0 h1:L9nPDWrmc/qU9UWZZvRaFajWYuO0np9V5p+5gxyYno0=
github.com/leaanthony/clir v1.3.0/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=

View file

@ -33,6 +33,14 @@ func (a *App) On(s string, callback func()) {
}
func (a *App) NewWindow(options *options.Window) *Window {
// Ensure we have sane defaults
if options.Width == 0 {
options.Width = 1024
}
if options.Height == 0 {
options.Height = 768
}
newWindow := NewWindow(options)
id := newWindow.id
if a.windows == nil {

View file

@ -497,9 +497,6 @@ func (w *macosWindow) run() {
w.setResizable(!w.options.DisableResize)
w.setMinSize(w.options.MinWidth, w.options.MinHeight)
w.setMaxSize(w.options.MaxWidth, w.options.MaxHeight)
if w.options.URL != "" {
w.navigateToURL(w.options.URL)
}
if w.options.EnableDevTools {
w.enableDevTools()
}
@ -540,6 +537,9 @@ func (w *macosWindow) run() {
}
}
if w.options.URL != "" {
w.navigateToURL(w.options.URL)
}
C.windowShow(w.nsWindow)
})
}

View file

@ -3,139 +3,3 @@ package options
type Application struct {
Mac *Mac
}
// Mac contains macOS specific options
type ActivationPolicy int
const (
ActivationPolicyRegular ActivationPolicy = iota
ActivationPolicyAccessory
ActivationPolicyProhibited
)
type Mac struct {
// ActivationPolicy is the activation policy for the application. Defaults to
// applicationActivationPolicyRegular.
ActivationPolicy ActivationPolicy
}
type Window struct {
Title string
Width, Height int
AlwaysOnTop bool
URL string
DisableResize bool
Resizable bool
MinWidth int
MinHeight int
MaxWidth int
MaxHeight int
EnableDevTools bool
StartState WindowState
Mac *MacWindow
BackgroundColour *RGBA
}
type RGBA struct {
Red, Green, Blue, Alpha uint8
}
type MacBackdrop int
const (
MacBackdropNormal MacBackdrop = iota
MacBackdropTransparent
MacBackdropTranslucent
)
type WindowState int
const (
WindowStateNormal WindowState = iota
WindowStateMinimised
WindowStateMaximised
WindowStateFullscreen
)
// MacWindow contains macOS specific options
type MacWindow struct {
Backdrop MacBackdrop
TitleBar *TitleBar
Appearance MacAppearanceType
}
// TitleBar contains options for the Mac titlebar
type TitleBar struct {
AppearsTransparent bool
Hide bool
HideTitle bool
FullSizeContent bool
UseToolbar bool
HideToolbarSeparator bool
}
// TitleBarDefault results in the default Mac Titlebar
func TitleBarDefault() *TitleBar {
return &TitleBar{
AppearsTransparent: false,
Hide: false,
HideTitle: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: false,
}
}
// Credit: Comments from Electron site
// TitleBarHidden results in a hidden title bar and a full size content window,
// yet the title bar still has the standard window controls (“traffic lights”)
// in the top left.
func TitleBarHidden() *TitleBar {
return &TitleBar{
AppearsTransparent: true,
Hide: false,
HideTitle: true,
FullSizeContent: true,
UseToolbar: false,
HideToolbarSeparator: false,
}
}
// TitleBarHiddenInset results in a hidden title bar with an alternative look where
// the traffic light buttons are slightly more inset from the window edge.
func TitleBarHiddenInset() *TitleBar {
return &TitleBar{
AppearsTransparent: true,
Hide: false,
HideTitle: true,
FullSizeContent: true,
UseToolbar: true,
HideToolbarSeparator: true,
}
}
// MacAppearanceType is a type of Appearance for Cocoa windows
type MacAppearanceType string
const (
// DefaultAppearance uses the default system value
DefaultAppearance MacAppearanceType = ""
// NSAppearanceNameAqua - The standard light system appearance.
NSAppearanceNameAqua MacAppearanceType = "NSAppearanceNameAqua"
// NSAppearanceNameDarkAqua - The standard dark system appearance.
NSAppearanceNameDarkAqua MacAppearanceType = "NSAppearanceNameDarkAqua"
// NSAppearanceNameVibrantLight - The light vibrant appearance
NSAppearanceNameVibrantLight MacAppearanceType = "NSAppearanceNameVibrantLight"
// NSAppearanceNameAccessibilityHighContrastAqua - A high-contrast version of the standard light system appearance.
NSAppearanceNameAccessibilityHighContrastAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastAqua"
// NSAppearanceNameAccessibilityHighContrastDarkAqua - A high-contrast version of the standard dark system appearance.
NSAppearanceNameAccessibilityHighContrastDarkAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastDarkAqua"
// NSAppearanceNameAccessibilityHighContrastVibrantLight - A high-contrast version of the light vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantLight MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantLight"
// NSAppearanceNameAccessibilityHighContrastVibrantDark - A high-contrast version of the dark vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantDark MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantDark"
)

105
exp/pkg/options/mac.go Normal file
View file

@ -0,0 +1,105 @@
package options
type ActivationPolicy int
const (
ActivationPolicyRegular ActivationPolicy = iota
ActivationPolicyAccessory
ActivationPolicyProhibited
)
type Mac struct {
// ActivationPolicy is the activation policy for the application. Defaults to
// applicationActivationPolicyRegular.
ActivationPolicy ActivationPolicy
}
type MacBackdrop int
const (
MacBackdropNormal MacBackdrop = iota
MacBackdropTransparent
MacBackdropTranslucent
)
// MacWindow contains macOS specific options
type MacWindow struct {
Backdrop MacBackdrop
TitleBar *TitleBar
Appearance MacAppearanceType
}
// TitleBar contains options for the Mac titlebar
type TitleBar struct {
AppearsTransparent bool
Hide bool
HideTitle bool
FullSizeContent bool
UseToolbar bool
HideToolbarSeparator bool
}
// TitleBarDefault results in the default Mac Titlebar
func TitleBarDefault() *TitleBar {
return &TitleBar{
AppearsTransparent: false,
Hide: false,
HideTitle: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: false,
}
}
// Credit: Comments from Electron site
// TitleBarHidden results in a hidden title bar and a full size content window,
// yet the title bar still has the standard window controls (“traffic lights”)
// in the top left.
func TitleBarHidden() *TitleBar {
return &TitleBar{
AppearsTransparent: true,
Hide: false,
HideTitle: true,
FullSizeContent: true,
UseToolbar: false,
HideToolbarSeparator: false,
}
}
// TitleBarHiddenInset results in a hidden title bar with an alternative look where
// the traffic light buttons are slightly more inset from the window edge.
func TitleBarHiddenInset() *TitleBar {
return &TitleBar{
AppearsTransparent: true,
Hide: false,
HideTitle: true,
FullSizeContent: true,
UseToolbar: true,
HideToolbarSeparator: true,
}
}
// MacAppearanceType is a type of Appearance for Cocoa windows
type MacAppearanceType string
const (
// DefaultAppearance uses the default system value
DefaultAppearance MacAppearanceType = ""
// NSAppearanceNameAqua - The standard light system appearance.
NSAppearanceNameAqua MacAppearanceType = "NSAppearanceNameAqua"
// NSAppearanceNameDarkAqua - The standard dark system appearance.
NSAppearanceNameDarkAqua MacAppearanceType = "NSAppearanceNameDarkAqua"
// NSAppearanceNameVibrantLight - The light vibrant appearance
NSAppearanceNameVibrantLight MacAppearanceType = "NSAppearanceNameVibrantLight"
// NSAppearanceNameAccessibilityHighContrastAqua - A high-contrast version of the standard light system appearance.
NSAppearanceNameAccessibilityHighContrastAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastAqua"
// NSAppearanceNameAccessibilityHighContrastDarkAqua - A high-contrast version of the standard dark system appearance.
NSAppearanceNameAccessibilityHighContrastDarkAqua MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastDarkAqua"
// NSAppearanceNameAccessibilityHighContrastVibrantLight - A high-contrast version of the light vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantLight MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantLight"
// NSAppearanceNameAccessibilityHighContrastVibrantDark - A high-contrast version of the dark vibrant appearance.
NSAppearanceNameAccessibilityHighContrastVibrantDark MacAppearanceType = "NSAppearanceNameAccessibilityHighContrastVibrantDark"
)

30
exp/pkg/options/window.go Normal file
View file

@ -0,0 +1,30 @@
package options
type WindowState int
const (
WindowStateNormal WindowState = iota
WindowStateMinimised
WindowStateMaximised
WindowStateFullscreen
)
type Window struct {
Title string
Width, Height int
AlwaysOnTop bool
URL string
DisableResize bool
MinWidth int
MinHeight int
MaxWidth int
MaxHeight int
EnableDevTools bool
StartState WindowState
Mac *MacWindow
BackgroundColour *RGBA
}
type RGBA struct {
Red, Green, Blue, Alpha uint8
}