From 198d206c46202669c266e3de994a8b743872e071 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 27 Feb 2021 14:07:27 +1100 Subject: [PATCH] Update basic template to new API --- .../templates/templates/vanilla/basic.tmpl.go | 11 +++--- .../templates/templates/vanilla/main.tmpl.go | 34 ++++++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/v2/internal/templates/templates/vanilla/basic.tmpl.go b/v2/internal/templates/templates/vanilla/basic.tmpl.go index da71d2da2..fa91fbb94 100644 --- a/v2/internal/templates/templates/vanilla/basic.tmpl.go +++ b/v2/internal/templates/templates/vanilla/basic.tmpl.go @@ -12,20 +12,19 @@ type Basic struct { } // newBasic creates a new Basic application struct -func newBasic() *Basic { +func NewBasic() *Basic { return &Basic{} } -// WailsInit is called at application startup -func (b *Basic) WailsInit(runtime *wails.Runtime) error { +// startup is called at application startup +func (b *Basic) startup(runtime *wails.Runtime) { // Perform your setup here b.runtime = runtime runtime.Window.SetTitle("{{.ProjectName}}") - return nil } -// WailsShutdown is called at application termination -func (b *Basic) WailsShutdown() { +// shutdown is called at application termination +func (b *Basic) shutdown() { // Perform your teardown here } diff --git a/v2/internal/templates/templates/vanilla/main.tmpl.go b/v2/internal/templates/templates/vanilla/main.tmpl.go index efceec4d3..bb69d682b 100644 --- a/v2/internal/templates/templates/vanilla/main.tmpl.go +++ b/v2/internal/templates/templates/vanilla/main.tmpl.go @@ -1,21 +1,39 @@ package main import ( - "github.com/wailsapp/wails/v2" "log" + + "github.com/wailsapp/wails/v2" + "github.com/wailsapp/wails/v2/pkg/logger" + "github.com/wailsapp/wails/v2/pkg/menu" + "github.com/wailsapp/wails/v2/pkg/options" + "github.com/wailsapp/wails/v2/pkg/options/mac" ) func main() { // Create application with options - app, err := wails.CreateApp("{{.ProjectName}}", 1024, 768) - if err != nil { - log.Fatal(err) - } + app := NewBasic() - app.Bind(newBasic()) - - err = app.Run() + err := wails.Run(&options.App{ + Title: "{{.ProjectName}}", + Width: 1280, + Height: 1024, + MinWidth: 800, + MinHeight: 600, + Mac: &mac.Options{ + WebviewIsTransparent: true, + WindowBackgroundIsTranslucent: true, + TitleBar: mac.TitleBarHiddenInset(), + Menu: menu.DefaultMacMenu(), + }, + LogLevel: logger.DEBUG, + Startup: app.startup, + Shutdown: app.shutdown, + Bind: []interface{}{ + app, + }, + }) if err != nil { log.Fatal(err) }