clean up arch

This commit is contained in:
2025-11-02 10:57:53 +01:00
parent abcc3e0b5e
commit 15d0f8b61b
11 changed files with 175 additions and 334 deletions

34
app.go
View File

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