参数选项
应用程序参数选项
该 Options.App 结构包含应用程序配置。 它被传递给 wails.Run() 方法:
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,
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. 这是匹配 Edge 用户激活放大或缩小的选项
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,
},
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,
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,
},
})
if err != nil {
log.Fatal(err)
}
}
标题
窗口标题栏中显示的文本。
名称:Title
类型:string
宽度
窗口的初始宽度。
名称:Width
类型:int
默认值:1024.
高度
窗口的初始高度。
名称:Height
类型:int
默认值:768
禁用调整窗口尺寸
默认情况下,主窗口可调整大小。 将此设置为 true 将使其保持固定大小。
名称:DisableResize
类型:bool
全屏
已弃用:请使用 窗口启动状态.
窗口启动状态
定义窗口在启动时应如何呈现。
| 值 | Win | Mac | Lin |
|---|---|---|---|
| Fullscreen(全屏) | ✅ | ✅ | ✅ |
| Maximised(最大化) | ✅ | ✅ | ✅ |
| Minimised(最小化) | ✅ | ❌ | ✅ |
名称:WindowStartState
类型:options.WindowStartState
无边框
设置为true时,窗口将没有边框或标题栏。 另请参阅 无边框窗口。
名称:Frameless
类型:bool
最小宽度
这将设置窗口的最小宽度。 如果给出的值 Width 小于这个值,窗口将被设置为 MinWidth 默认值。
名称:MinWidth
类型:int
最小高度
这将设置窗口的最小高度。 如果给出的值 Height 小于这个值,窗口将被设置为 MinHeight 默认值。
名称:MinHeight
类型:int
最大宽度
这将设置窗口的最大宽度。 如果给出的值 Width 大于这个值,窗口将被设置为 MaxWidth 默认值。
名称:MaxWidth
类型:int
最大高度
这将设置窗口的最大高度。 如果给出的值 Height 大于这个值,窗口将被设置为 MaxHeight 默认值。
名称:MaxHeight
类型:int
启动时隐藏窗口
设置为 true 时,应用程序将被隐藏,直到调用 显示窗口。
名称:StartHidden
类型:bool
关闭时隐藏窗口
默认情况下,关闭窗口将关闭应用程序。 将此设置为 true 意味着关闭窗口将隐藏窗口。
隐藏窗口。
名称:HideWindowOnClose
类型:bool
背景颜色
此值是窗口的默认背景颜色。 示例:options.NewRGBA(255,0,0,128) - 红色,透明度为 50%
名称:BackgroundColour
类型:*options.RGBA
默认值:white