diff --git a/app.go b/app.go index f55e03f..8708e62 100644 --- a/app.go +++ b/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 } diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 0b54732..b7d7ba7 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -92,12 +92,6 @@ }) } - // Instanciate a new project - CreateProject().then((showInfo) => { - showInformation.set(showInfo) - $needProjectSave = true - }) - // Handle window shortcuts document.addEventListener('keydown', function(event) { // Check the CTRL+S keys diff --git a/frontend/src/components/Settings/DeviceCard.svelte b/frontend/src/components/Settings/DeviceCard.svelte index 0c0a46e..8910208 100644 --- a/frontend/src/components/Settings/DeviceCard.svelte +++ b/frontend/src/components/Settings/DeviceCard.svelte @@ -57,8 +57,6 @@ - -