feat: complete application minimization and exit functions

This commit is contained in:
misitebao 2021-09-09 22:13:06 +08:00
parent 575c511c51
commit 87ffbfe791
3 changed files with 15 additions and 11 deletions

View File

@ -2,35 +2,38 @@ package main
import ( import (
"context" "context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
) )
// App struct // App struct
type App struct { type App struct {
runtime context.Context ctx context.Context
} }
// NewApp creates a new App application struct // NewApp creates a new App application struct
// NewApp 创建一个新的 App 应用程序
func NewApp() *App { func NewApp() *App {
return &App{} return &App{}
} }
// startup is called at application startup // startup is called at application startup
// startup 在应用程序启动时调用
func (b *App) startup(ctx context.Context) { func (b *App) startup(ctx context.Context) {
// Perform your setup here // Perform your setup here
//TODO: move to new runtime layout // 在这里执行初始化设置
b.ctx = ctx
//b.runtime = runtime
//runtime.Window.SetTitle("{{.ProjectName}}")
} }
// shutdown is called at application termination // shutdown is called at application termination
// 在应用程序终止时被调用 // 在应用程序终止时被调用
func (b *App) shutdown(ctx context.Context) { func (b *App) shutdown(ctx context.Context) {
// Perform your teardown here // Perform your teardown here
// 在此处做一些资源释放的操作
} }
// Greet returns a greeting for the given name // Quit Exit the application
func (b *App) Greet(name string) string { // Quit 退出应用
return fmt.Sprintf("Hello %s!", name) func (b *App) Quit() {
runtime.Quit(b.ctx)
} }

View File

@ -65,11 +65,11 @@ export default {
// it will be updated to be called directly when js is running. // it will be updated to be called directly when js is running.
// jsGojs // jsGojs
const onclickMinimise = () => { const onclickMinimise = () => {
alert(i18n.global.t("global.not-supported")) window.runtime.WindowMinimise()
} }
const onclickQuit = () => { const onclickQuit = () => {
alert(i18n.global.t("global.not-supported")) window.go.main.App.Quit()
} }

View File

@ -52,6 +52,7 @@ func main() {
app, app,
}, },
}) })
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }