-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathoptions.go
155 lines (137 loc) · 3.83 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package options
import (
"context"
"io/fs"
"log"
"net/http"
"runtime"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/imdario/mergo"
"github.com/wailsapp/wails/v2/pkg/logger"
)
type WindowStartState int
const (
Normal WindowStartState = 0
Maximised WindowStartState = 1
Minimised WindowStartState = 2
Fullscreen WindowStartState = 3
)
type Experimental struct {
// UseCSSDrag uses the `--wails-draggable` CSS variable to indicate drag regions
// Add `style="--wails-draggable:drag"` to your draggable elements
// `style="--wails-draggable:no-drag"` will disable dragging for that element + children
UseCSSDrag bool
}
// App contains options for creating the App
type App struct {
Title string
Width int
Height int
DisableResize bool
Fullscreen bool
Frameless bool
MinWidth int
MinHeight int
MaxWidth int
MaxHeight int
StartHidden bool
HideWindowOnClose bool
AlwaysOnTop bool
// BackgroundColour is the background colour of the window
// You can use the options.NewRGB and options.NewRGBA functions to create a new colour
BackgroundColour *RGBA
// RGBA is deprecated. Please use BackgroundColour
RGBA *RGBA
Assets fs.FS
AssetsHandler http.Handler
Menu *menu.Menu
Logger logger.Logger `json:"-"`
LogLevel logger.LogLevel
LogLevelProduction logger.LogLevel
OnStartup func(ctx context.Context) `json:"-"`
OnDomReady func(ctx context.Context) `json:"-"`
OnShutdown func(ctx context.Context) `json:"-"`
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
Bind []interface{}
WindowStartState WindowStartState
//ContextMenus []*menu.ContextMenu
//TrayMenus []*menu.TrayMenu
Windows *windows.Options
Mac *mac.Options
Linux *linux.Options
// Experimental options
Experimental *Experimental
}
type RGBA struct {
R uint8 `json:"r"`
G uint8 `json:"g"`
B uint8 `json:"b"`
A uint8 `json:"a"`
}
// NewRGBA creates a new RGBA struct with the given values
func NewRGBA(r, g, b, a uint8) *RGBA {
return &RGBA{
R: r,
G: g,
B: b,
A: a,
}
}
// NewRGB creates a new RGBA struct with the given values and Alpha set to 255
func NewRGB(r, g, b uint8) *RGBA {
return &RGBA{
R: r,
G: g,
B: b,
A: 255,
}
}
// MergeDefaults will set the minimum default values for an application
func MergeDefaults(appoptions *App) {
err := mergo.Merge(appoptions, Default)
if err != nil {
log.Fatal(err)
}
// Default colour. Doesn't work well with mergo
if appoptions.BackgroundColour == nil {
appoptions.BackgroundColour = &RGBA{
R: 255,
G: 255,
B: 255,
A: 255,
}
}
// Ensure max and min are valid
if appoptions.MinWidth > 0 && appoptions.MaxWidth > 0 {
if appoptions.MinWidth > appoptions.MaxWidth {
appoptions.MinWidth = appoptions.MaxWidth
}
}
if appoptions.MinHeight > 0 && appoptions.MaxHeight > 0 {
if appoptions.MinHeight > appoptions.MaxHeight {
appoptions.MinHeight = appoptions.MaxHeight
}
}
// Ensure width and height are limited if max/min is set
if appoptions.Width < appoptions.MinWidth {
appoptions.Width = appoptions.MinWidth
}
if appoptions.MaxWidth > 0 && appoptions.Width > appoptions.MaxWidth {
appoptions.Width = appoptions.MaxWidth
}
if appoptions.Height < appoptions.MinHeight {
appoptions.Height = appoptions.MinHeight
}
if appoptions.MaxHeight > 0 && appoptions.Height > appoptions.MaxHeight {
appoptions.Height = appoptions.MaxHeight
}
switch runtime.GOOS {
case "darwin":
if appoptions.Menu == nil {
appoptions.Menu = defaultMacMenu
}
}
}