5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

Update basic template to new API

This commit is contained in:
Lea Anthony 2021-02-27 14:07:27 +11:00
parent bb8e848ef6
commit 198d206c46
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 31 additions and 14 deletions

View File

@ -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
}

View File

@ -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)
}