结构调整

This commit is contained in:
Shikong 2023-07-20 17:13:06 +08:00
parent 3f8f6d5e81
commit 536c12b280
7 changed files with 55 additions and 13 deletions

View File

@ -1,5 +1,8 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {context} from '../models';
export function Ctx():Promise<context.Context>;
export function ForceClose():Promise<void>; export function ForceClose():Promise<void>;

View File

@ -2,10 +2,14 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
export function Ctx() {
return window['go']['app']['App']['Ctx']();
}
export function ForceClose() { export function ForceClose() {
return window['go']['main']['App']['ForceClose'](); return window['go']['app']['App']['ForceClose']();
} }
export function ReloadApp() { export function ReloadApp() {
return window['go']['main']['App']['ReloadApp'](); return window['go']['app']['App']['ReloadApp']();
} }

View File

@ -0,0 +1,5 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {frontend} from '../models';
export function OpenFileDialog(arg1:frontend.OpenDialogOptions):Promise<string>;

View File

@ -0,0 +1,7 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function OpenFileDialog(arg1) {
return window['go']['dialog']['Support']['OpenFileDialog'](arg1);
}

View File

@ -2,6 +2,8 @@ package main
import ( import (
"embed" "embed"
app2 "skapp/pkg/app"
"skapp/pkg/app/dialog"
"skapp/pkg/env" "skapp/pkg/env"
"skapp/pkg/sdk/system" "skapp/pkg/sdk/system"
systemUtils "skapp/pkg/system" systemUtils "skapp/pkg/system"
@ -20,7 +22,7 @@ func main() {
system.DestroyFileManager() system.DestroyFileManager()
}() }()
// Create an instance of the app structure // Create an instance of the app structure
app := NewApp() app := app2.NewApp()
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
@ -31,14 +33,15 @@ func main() {
Assets: assets, Assets: assets,
}, },
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1}, BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
OnStartup: app.startup, OnStartup: app.Startup,
OnBeforeClose: app.beforeClose, OnBeforeClose: app.BeforeClose,
OnShutdown: app.shutdown, OnShutdown: app.Shutdown,
Bind: []interface{}{ Bind: []interface{}{
app, app,
&env.Env{}, &env.Env{},
&utils.Utils{}, &utils.Utils{},
&systemUtils.InfoUtils{}, &systemUtils.InfoUtils{},
dialog.New(app),
}, },
Debug: options.Debug{ Debug: options.Debug{
OpenInspectorOnStartup: true, OpenInspectorOnStartup: true,

View File

@ -1,4 +1,4 @@
package main package app
import ( import (
"context" "context"
@ -32,13 +32,16 @@ func NewApp() *App {
app.load() app.load()
return app return app
} }
func (a *App) Ctx() context.Context {
return a.ctx
}
func (a *App) ReloadApp() { func (a *App) ReloadApp() {
runtime.WindowReloadApp(a.ctx) runtime.WindowReloadApp(a.ctx)
} }
func (a *App) ForceClose() { func (a *App) ForceClose() {
a.shutdown(a.ctx) a.Shutdown(a.ctx)
os.Exit(0) os.Exit(0)
} }
@ -68,9 +71,7 @@ func (a *App) load() {
a.Handler = engine.Handler() a.Handler = engine.Handler()
} }
// startup is called when the app starts. The context is saved func (a *App) Startup(ctx context.Context) {
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
if !global.Config.HasDebug() || !global.Config.Debug.Enable { if !global.Config.HasDebug() || !global.Config.Debug.Enable {
err := a.pidLock.Lock() err := a.pidLock.Lock()
if err != nil { if err != nil {
@ -105,11 +106,11 @@ func (a *App) startup(ctx context.Context) {
}() }()
} }
func (a *App) beforeClose(ctx context.Context) bool { func (a *App) BeforeClose(ctx context.Context) bool {
return false return false
} }
func (a *App) shutdown(ctx context.Context) { func (a *App) Shutdown(ctx context.Context) {
ctx2, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx2, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()

View File

@ -0,0 +1,19 @@
package dialog
import (
"github.com/wailsapp/wails/v2/pkg/runtime"
"skapp/pkg/app"
)
func New(app *app.App) *Support {
return &Support{app}
}
type Support struct {
app *app.App
}
func (s *Support) OpenFileDialog(dialogOptions runtime.OpenDialogOptions) string {
path, _ := runtime.OpenFileDialog(s.app.Ctx(), dialogOptions)
return path
}