feat: add domReady application option parameters

This commit is contained in:
misitebao 2021-09-23 01:30:36 +08:00
parent 025fe8de7d
commit f6b0dffa53
2 changed files with 23 additions and 13 deletions

View File

@ -17,15 +17,22 @@ func NewApp() *App {
// startup is called at application startup
// startup 在应用程序启动时调用
func (b *App) startup(ctx context.Context) {
func (a *App) startup(ctx context.Context) {
// Perform your setup here
// 在这里执行初始化设置
b.ctx = ctx
a.ctx = ctx
}
// domReady is called after the front-end dom has been loaded
// domReady 在前端Dom加载完毕后调用
func (a App) domReady(ctx context.Context) {
// Add your action here
// 在这里添加你的操作
}
// shutdown is called at application termination
// 在应用程序终止时被调用
func (b *App) shutdown(ctx context.Context) {
func (a *App) shutdown(ctx context.Context) {
// Perform your teardown here
// 在此处做一些资源释放的操作
}

View File

@ -4,22 +4,22 @@ import (
"embed"
"log"
"github.com/wailsapp/wails/v2/pkg/options/windows"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed frontend/dist
var assets embed.FS
func main() {
// Create an instance of the app structure
// 创建一个App结构体实例
app := NewApp()
// Create application with options
// 使用选项创建应用
app := NewApp()
err := wails.Run(&options.App{
Title: "{{.ProjectName}}",
Width: 1600,
@ -35,6 +35,15 @@ func main() {
HideWindowOnClose: false,
RGBA: &options.RGBA{255,255,255,0},
Assets: assets,
LogLevel: logger.DEBUG,
OnStartup: app.startup,
OnDomReady: app.domReady,
OnShutdown: app.shutdown,
Bind: []interface{}{
app,
},
// Windows platform specific options
// Windows平台特定选项
Windows: &windows.Options{
WebviewIsTransparent: true,
WindowIsTranslucent: true,
@ -45,12 +54,6 @@ func main() {
// WindowBackgroundIsTranslucent: true,
// TitleBar: mac.TitleBarHiddenInset(),
// },
LogLevel: logger.DEBUG,
OnStartup: app.startup,
OnShutdown: app.shutdown,
Bind: []interface{}{
app,
},
})
if err != nil {