diff --git a/internal/ble/sensor_controller.go b/internal/ble/sensor_controller.go index 548fcab..0a9a3c1 100644 --- a/internal/ble/sensor_controller.go +++ b/internal/ble/sensor_controller.go @@ -142,7 +142,7 @@ func (m *Controller) ConnectToBLEPeripheral(ctx context.Context, device bluetoot return bluetooth.Device{}, err } - logger.Info(ctx, logger.BLE, "BLE peripheral device connected") + logger.Info(ctx, logger.BLE, "BLE peripheral connected") return result, nil } @@ -181,13 +181,14 @@ func performBLEAction[T any](ctx context.Context, m *Controller, params actionPa return zero, err case <-scanCtx.Done(): + var zero T err := handleActionTimeout(scanCtx, m, params.stopAction) logger.Debug(ctx, logger.BLE, "waiting for BLE peripheral disconnect...") <-done // Wait for the action to complete - logger.Debug(ctx, logger.BLE, "BLE peripheral device disconnected") + logger.Debug(ctx, logger.BLE, "BLE peripheral disconnected") return zero, err } @@ -252,11 +253,6 @@ func (m *Controller) connectAction(device bluetooth.ScanResult, found chan<- blu // startScanning starts the BLE peripheral scan and handles device discovery func (m *Controller) startScanning(ctx context.Context, found chan<- bluetooth.ScanResult) error { - // Check if already canceled before starting scanning operation - if err := ctx.Err(); err != nil { - return fmt.Errorf("session stop requested before BLE scan: %w", err) - } - AdapterMu.Lock() defer AdapterMu.Unlock() @@ -265,13 +261,6 @@ func (m *Controller) startScanning(ctx context.Context, found chan<- bluetooth.S err := m.blePeripheralDetails.bleAdapter.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) { - // Check if context canceled before continuing scanning operation - if ctx.Err() != nil { - _ = adapter.StopScan() - - return - } - // Address comparison if result.Address.String() == m.blePeripheralDetails.bleConfig.SensorBDAddr { @@ -281,7 +270,7 @@ func (m *Controller) startScanning(ctx context.Context, found chan<- bluetooth.S select { case found <- result: - logger.Debug(ctx, logger.BLE, "scan result sent to controller") + logger.Debug(ctx, logger.BLE, "scan completed") default: logger.Warn(ctx, logger.BLE, "controller object no longer listening; scan results ignored") } diff --git a/internal/ble/sensor_services.go b/internal/ble/sensor_services.go index e4797c8..9747a2d 100644 --- a/internal/ble/sensor_services.go +++ b/internal/ble/sensor_services.go @@ -199,6 +199,7 @@ func (m *Controller) BatteryService(ctx context.Context, device ServiceDiscovere discoverServices(batteryServiceConfig, device, found, errChan) }, ) + if err != nil { return nil, err } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index f723180..e0d8b55 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -98,7 +98,7 @@ func AddWriter(w io.Writer) { } // SetLogLevel dynamically updates the logging level of the running application -func SetLogLevel(ctx context.Context, levelStr string) { +func SetLogLevel(levelStr string) { newLevel := parseLogLevel(levelStr) logLevelVar.Set(newLevel) diff --git a/internal/services/shutdown_manager.go b/internal/services/shutdown_manager.go index b8f5346..cf6921e 100644 --- a/internal/services/shutdown_manager.go +++ b/internal/services/shutdown_manager.go @@ -153,9 +153,17 @@ func (sm *ShutdownManager) Wait() { } +// drawLine outputs a line to the console +func drawLine(ctx context.Context) { + logger.Info(ctx, logger.APP, "---------------------------------------------------") +} + // WaveHello outputs a welcome message func WaveHello(ctx context.Context) { + drawLine(ctx) logger.Info(ctx, logger.APP, config.GetFullVersion()+" starting...") + drawLine(ctx) + } // WaveGoodbye outputs a goodbye message and exits the program @@ -165,9 +173,11 @@ func WaveGoodbye(ctx context.Context) { // shutdown message is visible regardless of application mode (CLI or GUI) logger.SetOutputToStdout() logger.ClearCLILine() - logger.SetLogLevel(ctx, "debug") + logger.SetLogLevel("debug") + drawLine(ctx) logger.Info(ctx, logger.APP, config.GetFullVersion()+" shutdown complete. Goodbye") + drawLine(ctx) os.Exit(0) diff --git a/internal/session/controllers.go b/internal/session/controllers.go index 641794b..f0c3372 100644 --- a/internal/session/controllers.go +++ b/internal/session/controllers.go @@ -96,7 +96,7 @@ func (m *StateManager) performSessionStartup(ctx context.Context, shutdownMgr *s } logger.Debug(ctx, logger.APP, "controllers initialized OK") - logger.Debug(ctx, logger.APP, "connecting BLE...") + logger.Debug(ctx, logger.APP, "establishing connection to BLE peripheral...") // Connect to the BLE peripheral device, err := m.connectBLE(ctx, controllers) @@ -108,7 +108,7 @@ func (m *StateManager) performSessionStartup(ctx context.Context, shutdownMgr *s controllers.bleDevice = device - logger.Debug(ctx, logger.APP, "BLE connected OK") + logger.Debug(ctx, logger.APP, "BLE peripheral now connected") m.mu.Lock() m.controllers = controllers @@ -174,7 +174,7 @@ func (m *StateManager) StopSession() error { if wasPending { logger.Debug(ctx, logger.APP, "stopped pending session startup") } else { - logger.Debug(ctx, logger.APP, "session stopped") + logger.Debug(ctx, logger.APP, "active session stopped") } return nil diff --git a/internal/session/session.go b/internal/session/session.go index e2075be..b4dfde1 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -104,7 +104,7 @@ func (m *StateManager) LoadTargetSession(configPath string) error { } if cfg.App.LogLevel != "" { - logger.SetLogLevel(logger.BackgroundCtx, cfg.App.LogLevel) + logger.SetLogLevel(cfg.App.LogLevel) } return nil @@ -332,7 +332,6 @@ func (m *StateManager) prepareStart() error { m.PendingStart = true m.state = StateConnecting - logger.Debug(logger.BackgroundCtx, logger.APP, "set PendingStart=true, state=Connecting") return nil } @@ -342,7 +341,7 @@ func (m *StateManager) storeShutdownMgr(s *services.ShutdownManager) { m.mu.Lock() m.shutdownMgr = s - logger.Debug(logger.BackgroundCtx, logger.APP, "shutdownMgr stored") + logger.Debug(logger.BackgroundCtx, logger.APP, "shutdown manager object state stored") m.mu.Unlock() } diff --git a/internal/video/mpv_player.go b/internal/video/mpv_player.go index e1fbbda..0a12f84 100644 --- a/internal/video/mpv_player.go +++ b/internal/video/mpv_player.go @@ -140,7 +140,8 @@ func (m *mpvPlayer) handleEndFile(event *mpv.Event) error { logger.Debug(logger.BackgroundCtx, logger.VIDEO, "EventEnd received during loading") endFile := event.EndFile() - logger.Debug(logger.BackgroundCtx, logger.VIDEO, fmt.Sprintf("EndFile reason: %s, error: %v", endFile.Reason.String(), endFile.Error)) + + logger.Debug(logger.BackgroundCtx, logger.VIDEO, fmt.Sprintf("mpv EndFile event trigger: %v", endFile.Error)) var validationErr error diff --git a/ui/ui_session_status.go b/ui/ui_session_status.go index 2370c39..59027b7 100644 --- a/ui/ui_session_status.go +++ b/ui/ui_session_status.go @@ -36,7 +36,7 @@ func (sc *SessionController) setupSessionControlSignals() { } -// handleSessionControl processes clicks on the session control button +// handleSessionControl processes clicks on the session start/stop button func (sc *SessionController) handleSessionControl() error { // Debounce session control button @@ -49,7 +49,7 @@ func (sc *SessionController) handleSessionControl() error { }) currentState := sc.SessionManager.SessionState() - logger.Debug(logger.BackgroundCtx, logger.GUI, fmt.Sprintf("button clicked: State=%s", currentState)) + logger.Debug(logger.BackgroundCtx, logger.GUI, fmt.Sprintf("Session Start/Stop button clicked: session status: %s", currentState)) if currentState >= session.StateConnecting || sc.starting.Load() { @@ -127,14 +127,11 @@ func (sc *SessionController) handleStartError(err error) { // handleStop processes stopping the session func (sc *SessionController) handleStop() error { - logger.Debug(logger.BackgroundCtx, logger.GUI, "stop branch entered") - if err := sc.SessionManager.StopSession(); err != nil { - return fmt.Errorf(errFormat, "unable to stop services", err) + return fmt.Errorf(errFormat, "unable to stop session services", err) } - logger.Debug(logger.BackgroundCtx, logger.GUI, "stop session returned") - logger.Debug(logger.BackgroundCtx, logger.GUI, "updating UI for stop") + logger.Debug(logger.BackgroundCtx, logger.GUI, "session services stopped") safeUpdateUI(func() { sc.updateSessionControlButton(false) @@ -156,11 +153,8 @@ func (sc *SessionController) handleStop() error { // startSessionGUI runs the StartSession method and updates UI based on result func (sc *SessionController) startSessionGUI() { - logger.Debug(logger.BackgroundCtx, logger.GUI, "start goroutine launched") - defer func() { - logger.Debug(logger.BackgroundCtx, logger.GUI, "start goroutine exiting") - logger.Debug(logger.BackgroundCtx, logger.GUI, "updating UI post-start") + logger.Debug(logger.BackgroundCtx, logger.GUI, "session services stopped") safeUpdateUI(func() { // Re-toggle to Start if success/error, but only if stopped @@ -173,7 +167,7 @@ func (sc *SessionController) startSessionGUI() { }() // Start the session - logger.Debug(logger.BackgroundCtx, logger.GUI, "calling StartSession()") + logger.Debug(logger.BackgroundCtx, logger.GUI, "session services starting...") err := sc.SessionManager.StartSession() if err != nil { sc.handleStartError(err) @@ -182,8 +176,7 @@ func (sc *SessionController) startSessionGUI() { } // Update UI to show success state - logger.Debug(logger.BackgroundCtx, logger.GUI, "StartSession() successful") - logger.Debug(logger.BackgroundCtx, logger.GUI, "updating UI for successful start") + logger.Debug(logger.BackgroundCtx, logger.GUI, "session services started") safeUpdateUI(func() { battery := fmt.Sprintf("%d%%", sc.SessionManager.BatteryLevel()) @@ -221,7 +214,7 @@ func (sc *SessionController) updatePage2WithSession(sess Session) { // Enable the button now that session is loaded sc.UI.Page2.SessionControlRow.SetSensitive(true) - logger.Debug(logger.BackgroundCtx, logger.GUI, "page 2 updated with session: "+sess.Title) + logger.Debug(logger.BackgroundCtx, logger.GUI, "Session Status page updated with session: "+sess.Title) } diff --git a/ui/ui_setup.go b/ui/ui_setup.go index f0b1b15..f1b8103 100644 --- a/ui/ui_setup.go +++ b/ui/ui_setup.go @@ -43,7 +43,7 @@ func setupGUIApplication(app *gtk.Application, shutdownMgr *services.ShutdownMan // Create the "Exit" menu item action handler exitAction := gio.NewSimpleAction("exit", nil) exitAction.ConnectActivate(func(_ *glib.Variant) { - logger.Debug(logger.BackgroundCtx, logger.GUI, "Exit action triggered from app menu item") + logger.Debug(logger.BackgroundCtx, logger.GUI, "exit action triggered from GUI app menu item") ui.createExitDialog() }) @@ -53,7 +53,7 @@ func setupGUIApplication(app *gtk.Application, shutdownMgr *services.ShutdownMan ui.Window.ConnectCloseRequest(func() bool { safeUpdateUI(func() { - logger.Debug(logger.BackgroundCtx, logger.GUI, "exit action triggered from window manager close button") + logger.Debug(logger.BackgroundCtx, logger.GUI, "exit action triggered from GUI close button") ui.createExitDialog() }) diff --git a/ui/ui_utils.go b/ui/ui_utils.go index c155fea..890e81a 100644 --- a/ui/ui_utils.go +++ b/ui/ui_utils.go @@ -105,7 +105,7 @@ func (ui *AppUI) createExitDialog() { "Are you sure you want to exit?", adw.ResponseDestructive, func() { - logger.Info(logger.BackgroundCtx, logger.GUI, "user confirmed exit") + logger.Info(logger.BackgroundCtx, logger.GUI, "user confirmed application exit, so...") ui.shutdownMgr.Shutdown() }, )