From a021c9807431539c6b3dce66453120770acf813e Mon Sep 17 00:00:00 2001 From: KeyffMS <124252104+KeyffMS@users.noreply.github.com> Date: Mon, 21 Sep 2026 13:06:08 +0200 Subject: [PATCH 1/2] refactor: move application session helpers (R2l) --- crates/lantern-app/src/application/session.rs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 crates/lantern-app/src/application/session.rs diff --git a/crates/lantern-app/src/application/session.rs b/crates/lantern-app/src/application/session.rs new file mode 100644 index 00000000..8c8d8103 --- /dev/null +++ b/crates/lantern-app/src/application/session.rs @@ -0,0 +1,85 @@ +use lantern_domain::SessionId; + +use crate::{ + ConnectionAttemptKind, ConnectionEffect, ConnectionFailure, CsvLoggingFaultSummary, + CsvLoggingStateView, MonitoringEffect, SessionEffect, +}; + +use super::{ApplicationEffect, ApplicationState}; + +impl ApplicationState { + pub(super) fn csv_stop_effect( + &self, + session_id: Option, + ) -> Option { + if !matches!( + self.monitoring.csv_status.state, + CsvLoggingStateView::Starting | CsvLoggingStateView::Running + ) { + return None; + } + let session_id = session_id?; + let fault_view = self.faults.view(); + Some(ApplicationEffect::Monitoring( + MonitoringEffect::StopCsvLogging { + session_id, + faults: CsvLoggingFaultSummary { + events: u64::try_from(fault_view.events.len()).unwrap_or(u64::MAX), + acknowledged: u64::try_from( + fault_view + .events + .iter() + .filter(|event| event.event.acknowledged) + .count(), + ) + .unwrap_or(u64::MAX), + evicted: fault_view.evicted_events, + }, + }, + )) + } + + pub(super) fn translate_session_effects( + &mut self, + effects: Vec, + ) -> Vec { + let mut translated = Vec::with_capacity(effects.len() + 1); + if effects.contains(&SessionEffect::StopPlanner) + && let Some(effect) = self.csv_stop_effect(self.session.session_id()) + { + translated.push(effect); + } + for effect in effects { + match effect { + SessionEffect::ClosePort => { + translated.push(ApplicationEffect::Connection(ConnectionEffect::ClosePort)) + } + SessionEffect::ScheduleReconnect { at } => translated.push( + ApplicationEffect::Connection(ConnectionEffect::ScheduleReconnect { at }), + ), + SessionEffect::CancelReconnect => translated.push(ApplicationEffect::Connection( + ConnectionEffect::CancelReconnect, + )), + SessionEffect::OpenPort => { + if let Some(profile) = self.selected_profile() { + match self + .connection + .open_effect(&profile, ConnectionAttemptKind::Reconnect) + { + Ok(effect) => translated.push(ApplicationEffect::Connection(effect)), + Err(error) => self.connection.failure = Some(error), + } + } + } + SessionEffect::StartIdentification + | SessionEffect::StartReconnectIdentification => { + self.connection.failure = Some(ConnectionFailure::Validation( + "identification start lacked an opened adapter result".to_owned(), + )); + } + other => translated.push(ApplicationEffect::Session(other)), + } + } + translated + } +} From 167764250e7284aa8d9294d2645c343b0bc5721c Mon Sep 17 00:00:00 2001 From: KeyffMS <124252104+KeyffMS@users.noreply.github.com> Date: Mon, 21 Sep 2026 13:06:11 +0200 Subject: [PATCH 2/2] refactor: wire application session helpers (R2l) --- crates/lantern-app/src/application.rs | 74 ++------------------------- 1 file changed, 3 insertions(+), 71 deletions(-) diff --git a/crates/lantern-app/src/application.rs b/crates/lantern-app/src/application.rs index 54d94ae8..9df508f5 100644 --- a/crates/lantern-app/src/application.rs +++ b/crates/lantern-app/src/application.rs @@ -1,11 +1,10 @@ use std::sync::Arc; -use lantern_domain::{DriveState, ProfileId, SessionId}; +use lantern_domain::{DriveState, ProfileId}; use crate::{ AuditHealth, Authorization, BackupCaptureRequest, BackupRestoreAction, BackupRestoreEffect, - BackupRestoreState, ConnectionAttemptKind, ConnectionEffect, ConnectionFailure, ConnectionStep, - ConnectionWizardState, Connectivity, CsvLoggingFaultSummary, CsvLoggingStateView, FaultTracker, + BackupRestoreState, ConnectionStep, ConnectionWizardState, Connectivity, FaultTracker, MAX_PARAMETER_BROWSER_VISIBLE, MonitoringEffect, OperationState, ParameterAction, ParameterIntentContext, ProfileRegistry, RestoreConfirmation, SessionEffect, SessionState, SessionStateMachine, WriteConfirmation, WriteConfirmationModel, WriteEffect, @@ -16,6 +15,7 @@ mod connection; mod faults; mod monitoring; mod runtime; +mod session; mod state; mod view; @@ -468,74 +468,6 @@ impl ApplicationState { } } - fn csv_stop_effect(&self, session_id: Option) -> Option { - if !matches!( - self.monitoring.csv_status.state, - CsvLoggingStateView::Starting | CsvLoggingStateView::Running - ) { - return None; - } - let session_id = session_id?; - let fault_view = self.faults.view(); - Some(ApplicationEffect::Monitoring( - MonitoringEffect::StopCsvLogging { - session_id, - faults: CsvLoggingFaultSummary { - events: u64::try_from(fault_view.events.len()).unwrap_or(u64::MAX), - acknowledged: u64::try_from( - fault_view - .events - .iter() - .filter(|event| event.event.acknowledged) - .count(), - ) - .unwrap_or(u64::MAX), - evicted: fault_view.evicted_events, - }, - }, - )) - } - - fn translate_session_effects(&mut self, effects: Vec) -> Vec { - let mut translated = Vec::with_capacity(effects.len() + 1); - if effects.contains(&SessionEffect::StopPlanner) - && let Some(effect) = self.csv_stop_effect(self.session.session_id()) - { - translated.push(effect); - } - for effect in effects { - match effect { - SessionEffect::ClosePort => { - translated.push(ApplicationEffect::Connection(ConnectionEffect::ClosePort)) - } - SessionEffect::ScheduleReconnect { at } => translated.push( - ApplicationEffect::Connection(ConnectionEffect::ScheduleReconnect { at }), - ), - SessionEffect::CancelReconnect => translated.push(ApplicationEffect::Connection( - ConnectionEffect::CancelReconnect, - )), - SessionEffect::OpenPort => { - if let Some(profile) = self.selected_profile() { - match self - .connection - .open_effect(&profile, ConnectionAttemptKind::Reconnect) - { - Ok(effect) => translated.push(ApplicationEffect::Connection(effect)), - Err(error) => self.connection.failure = Some(error), - } - } - } - SessionEffect::StartIdentification - | SessionEffect::StartReconnectIdentification => { - self.connection.failure = Some(ConnectionFailure::Validation( - "identification start lacked an opened adapter result".to_owned(), - )); - } - other => translated.push(ApplicationEffect::Session(other)), - } - } - translated - } } #[cfg(test)]