From 15d0f8b61b7e41ec34242a4e3c5311ef3bd6aeea Mon Sep 17 00:00:00 2001 From: Valentin Boulanger Date: Sun, 2 Nov 2025 10:57:53 +0100 Subject: [PATCH] clean up arch --- app.go | 34 +++- frontend/src/App.svelte | 6 - .../src/components/Settings/DeviceCard.svelte | 2 - .../Settings/InputsOutputsContent.svelte | 8 - .../src/components/Settings/Settings.svelte | 42 ++-- frontend/src/lang/en.json | 1 + hardware/FTDIFinder.go | 79 +++++--- hardware/FTDIPeripheral.go | 63 +++--- hardware/hardware.go | 79 ++++---- hardware/interfaces.go | 4 +- project.go | 191 ------------------ 11 files changed, 175 insertions(+), 334 deletions(-) delete mode 100644 project.go 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 @@ - -