Options
Application Options
The Options.App struct contains the application configuration.
It is passed to the wails.Run() method:
import (
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
func main() {
err := wails.Run(&options.App{
Title: "Menus Demo",
Width: 800,
Height: 600,
DisableResize: false,
Fullscreen: false,
WindowStartState: options.Maximised,
Frameless: true,
MinWidth: 400,
MinHeight: 400,
MaxWidth: 1280,
MaxHeight: 1024,
StartHidden: false,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
AlwaysOnTop: false,
AssetServer: &assetserver.Options{
Assets: assets,
Handler: assetsHandler,
Middleware: assetsMidldeware,
},
Menu: app.applicationMenu(),
Logger: nil,
LogLevel: logger.DEBUG,
LogLevelProduction: logger.ERROR,
OnStartup: app.startup,
OnDomReady: app.domready,
OnShutdown: app.shutdown,
OnBeforeClose: app.beforeClose,
CSSDragProperty: "--wails-draggable",
CSSDragValue: "drag",
EnableDefaultContextMenu: false,
EnableFraudulentWebsiteDetection: false,
Bind: []interface{}{
app,
},
EnumBind: []interface{}{
AllWeekdays,
},
ErrorFormatter: func(err error) any { return err.Error() },
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: "c9c8fd93-6758-4144-87d1-34bdb0a8bd60",
OnSecondInstanceLaunch: app.onSecondInstanceLaunch,
},
DragAndDrop: &options.DragAndDrop{
EnableFileDrop: false,
DisableWebViewDrop: false,
CSSDropProperty: "--wails-drop-target",
CSSDropValue: "drop",
},
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowIsTranslucent: false,
ContentProtection: false,
BackdropType: windows.Mica,
DisablePinchZoom: false,
DisableWindowIcon: false,
DisableFramelessWindowDecorations: false,
WebviewUserDataPath: "",
WebviewBrowserPath: "",
Theme: windows.SystemDefault,
CustomTheme: &windows.ThemeSettings{
DarkModeTitleBar: windows.RGB(20, 20, 20),
DarkModeTitleText: windows.RGB(200, 200, 200),
DarkModeBorder: windows.RGB(20, 0, 20),
LightModeTitleBar: windows.RGB(200, 200, 200),
LightModeTitleText: windows.RGB(20, 20, 20),
LightModeBorder: windows.RGB(200, 200, 200),
},
// ZoomFactor is the zoom factor for the WebView2. This is the option matching the Edge user activated zoom in or out.
ZoomFactor: float64,
// IsZoomControlEnabled enables the zoom factor to be changed by the user.
IsZoomControlEnabled: bool,
// User messages that can be customised
Messages: *windows.Messages
// OnSuspend is called when Windows enters low power mode
OnSuspend: func()
// OnResume is called when Windows resumes from low power mode
OnResume: func(),
// Disable GPU hardware acceleration for the webview
WebviewGpuDisabled: false,
// Class name for the window. If empty, 'wailsWindow' will be used.
WindowClassName: "MyWindow",
},
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: true,
HideTitle: false,
HideTitleBar: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: true,
OnFileOpen: app.onFileOpen,
OnUrlOpen: app.onUrlOpen,
},
Appearance: mac.NSAppearanceNameDarkAqua,
WebviewIsTransparent: true,
WindowIsTranslucent: false,
ContentProtection: false,
About: &mac.AboutInfo{
Title: "My Application",
Message: "© 2021 Me",
Icon: icon,
},
},
Linux: &linux.Options{
Icon: icon,
WindowIsTranslucent: false,
WebviewGpuPolicy: linux.WebviewGpuPolicyAlways,
ProgramName: "wails"
},
Debug: options.Debug{
OpenInspectorOnStartup: false,
},
BindingsAllowedOrigins: "https://my.topapp,https://*.wails.isgreat",
})
if err != nil {
log.Fatal(err)
}
}
Title
The text shown in the window's title bar.
Name: Title
Type: string
Width
The initial width of the window.
Name: Width
Type: int
Default: 1024.
Height
The initial height of the window.
Name: Height
Type: int
Default: 768
DisableResize
By default, the main window is resizable. Setting this to true will keep it a fixed size.
Name: DisableResize
Type: bool
Fullscreen
Deprecated: Please use WindowStartState.
WindowStartState
Defines how the window should present itself at startup.
| Value | Win | Mac | Lin |
|---|---|---|---|
| Fullscreen | ✅ | ✅ | ✅ |
| Maximised | ✅ | ✅ | ✅ |
| Minimised | ✅ | ❌ | ✅ |
Name: WindowStartState
Type: options.WindowStartState
Frameless
When set to true, the window will have no borders or title bar.
Also see Frameless Windows.
Name: Frameless
Type: bool
MinWidth
This sets the minimum width for the window. If the value given in Width is less than this value,
the window will be set to MinWidth by default.
Name: MinWidth
Type: int
MinHeight
This sets the minimum height for the window. If the value given in Height is less than this value,
the window will be set to MinHeight by default.
Name: MinHeight
Type: int
MaxWidth
This sets the maximum width for the window. If the value given in Width is more than this value,
the window will be set to MaxWidth by default.
Name: MaxWidth
Type: int
MaxHeight
This sets the maximum height for the window. If the value given in Height is more than this value,
the window will be set to MaxHeight by default.
Name: MaxHeight
Type: int
StartHidden
When set to true, the application will be hidden until WindowShow
is called.
Name: StartHidden
Type: bool
HideWindowOnClose
By default, closing the window will close the application. Setting this to true means closing the window will
hide the window instead.
Name: HideWindowOnClose
Type: bool
BackgroundColour
This value is the default background colour of the window. Example: options.NewRGBA(255,0,0,128) - Red at 50% transparency
Name: BackgroundColour
Type: *options.RGBA
Default: white
AlwaysOnTop
Indicates that the window should stay above other windows when losing focus.
Name: AlwaysOnTop
Type: bool
Assets
Deprecated: Please use Assets on AssetServer specific options.
AssetsHandler
Deprecated: Please use AssetsHandler on AssetServer specific options.
AssetServer
This defines AssetServer specific options. It allows to customize the AssetServer with static assets, serving assets
dynamically with an http.Handler or hook into the request chain with an assetserver.Middleware.
Not all features of an http.Request are currently supported, please see the following feature matrix:
| Feature | Win | Mac | Lin |
|---|---|---|---|
| GET | ✅ | ✅ | ✅ |
| POST | ✅ | ✅ | ✅ 1 |
| PUT | ✅ | ✅ | ✅ 1 |
| PATCH | ✅ | ✅ | ✅ 1 |
| DELETE | ✅ | ✅ | ✅ 1 |
| Request Headers | ✅ | ✅ | ✅ 1 |
| Request Body | ✅ | ✅ | ✅ 2 |
| Request Body Streaming | ✅ | ✅ | ✅ 2 |
| Response StatusCodes | ✅ | ✅ | ✅ 1 |
| Response Headers | ✅ | ✅ | ✅ 1 |
| Response Body | ✅ | ✅ | ✅ |
| Response Body Streaming | ❌ | ✅ | ✅ |
| WebSockets | ❌ | ❌ | ❌ |
| HTTP Redirects 30x | ✅ | ❌ | ❌ |
Name: AssetServer
Type: *assetserver.Options
Assets
The static frontend assets to be used by the application.
A GET request is first tried to be served from this fs.FS. If the fs.FS returns os.ErrNotExist for that file,
the request handling will fallback to the Handler and tries to serve the GET request from it.
If set to nil, all GET requests will be forwarded to Handler.
Name: Assets
Type: fs.FS
Handler
The assets handler is a generic http.Handler for fallback handling of assets that can't be found.
The handler will be called for every GET request that can't be served from Assets, due to os.ErrNotExist.
Furthermore all non GET requests will always be served from this Handler.
If not defined, the result is the following in cases where the Handler would have been called:
- GET request:
http.StatusNotFound - Other request:
http.StatusMethodNotAllowed
This does not work with vite v5.0.0+ and wails v2 due to changes in vite. Changes are planned in v3 to support similar functionality under vite v5.0.0+. If you need this feature, stay with vite v4.0.0+. See issue 3240 for details
NOTE: When used in combination with a Frontend DevServer there might be limitations, eg. Vite serves the index.html on every path, that does not contain a file extension.
Name: AssetsHandler
Type: http.Handler
Middleware
Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default
request handler dynamically, e.g. implement specialized Routing etc.
The Middleware is called to build a new http.Handler used by the AssetSever and it also receives the default
handler used by the AssetServer as an argument.
If not defined, the default AssetServer request chain is executed.
Name: Middleware
Type: assetserver.Middleware
Menu
The menu to be used by the application. More details about Menus in the Menu Reference.
On Mac, if no menu is specified, a default menu will be created.
Name: Menu
Type: *menu.Menu
Logger
The logger to be used by the application. More details about logging in the Log Reference.
Name: Logger
Type: logger.Logger
Default: Logs to Stdout
LogLevel
The default log level. More details about logging in the Log Reference.
Name: LogLevel
Type: logger.LogLevel
Default: Info in dev mode, Error in production mode
LogLevelProduction
The default log level for production builds. More details about logging in the Log Reference.
Name: LogLevelProduction
Type: logger.LogLevel
Default: Error
OnStartup
This callback is called after the frontend has been created, but before index.html has been loaded. It is given
the application context.
Name: OnStartup
Type: func(ctx context.Context)
OnDomReady
This callback is called after the frontend has loaded index.html and its resources. It is given
the application context.
Name: OnDomReady
Type: func(ctx context.Context)