generated from thinkode/modelRepository
clean up arch
This commit is contained in:
34
app.go
34
app.go
@@ -16,12 +16,15 @@ import (
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
cancelFunc context.CancelFunc
|
||||
ctx context.Context
|
||||
cancelFunc context.CancelFunc
|
||||
wait sync.WaitGroup
|
||||
|
||||
hardwareManager *hardware.HardwareManager // For managing all the hardware
|
||||
wmiMutex sync.Mutex // Avoid some WMI operations at the same time
|
||||
projectInfo ProjectInfo // The project information structure
|
||||
projectSave string // The file name of the project
|
||||
projectCancel context.CancelFunc // The project cancel function
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
@@ -44,11 +47,17 @@ func NewApp() *App {
|
||||
// so we can call the runtime methods
|
||||
func (a *App) onStartup(ctx context.Context) {
|
||||
a.ctx, a.cancelFunc = context.WithCancel(ctx)
|
||||
err := a.hardwareManager.Start(a.ctx)
|
||||
if err != nil {
|
||||
log.Err(err).Str("file", "app").Msg("unable to start the hardware manager")
|
||||
return
|
||||
}
|
||||
|
||||
// Starting the hardware manager
|
||||
a.wait.Add(1)
|
||||
go func() {
|
||||
defer a.wait.Done()
|
||||
err := a.hardwareManager.Start(a.ctx)
|
||||
if err != nil {
|
||||
log.Err(err).Str("file", "app").Msg("unable to start the hardware manager")
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// onReady is called when the DOM is ready
|
||||
@@ -69,10 +78,13 @@ func (a *App) onShutdown(ctx context.Context) {
|
||||
log.Trace().Str("file", "app").Msg("app is closing")
|
||||
// Explicitly close the context
|
||||
a.cancelFunc()
|
||||
err := a.hardwareManager.Stop()
|
||||
if err != nil {
|
||||
log.Err(err).Str("file", "app").Msg("unable to stop the hardware manager")
|
||||
}
|
||||
// Wait for application to close properly
|
||||
a.hardwareManager.WaitStop()
|
||||
// a.cancelFunc()
|
||||
// err := a.hardwareManager.Stop()
|
||||
// if err != nil {
|
||||
// log.Err(err).Str("file", "app").Msg("unable to stop the hardware manager")
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user