Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions internal/ble/sensor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()

Expand All @@ -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 {

Expand All @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions internal/ble/sensor_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (m *Controller) BatteryService(ctx context.Context, device ServiceDiscovere
discoverServices(batteryServiceConfig, device, found, errChan)
},
)

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion internal/services/shutdown_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions internal/session/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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()

}
Expand Down
3 changes: 2 additions & 1 deletion internal/video/mpv_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 8 additions & 15 deletions ui/ui_session_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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)

}

Expand Down
4 changes: 2 additions & 2 deletions ui/ui_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand All @@ -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()
})

Expand Down
2 changes: 1 addition & 1 deletion ui/ui_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
)
Expand Down
Loading