storage in the system is now storing log in details properly well
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::config::binds::config::Config;
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::services::ui_service::UiService;
|
||||
use crate::config::storage::storage::load_auth_data;
|
||||
use crate::modes::common::commands::CommandHandler;
|
||||
use crate::modes::handlers::event::{EventHandler, EventOutcome};
|
||||
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
||||
@@ -68,6 +69,28 @@ pub async fn run_ui() -> Result<()> {
|
||||
let mut buffer_state = BufferState::default();
|
||||
let mut app_state = AppState::new().context("Failed to create initial app state")?;
|
||||
|
||||
// --- DATA: Load auth data from file at startup ---
|
||||
let mut auto_logged_in = false;
|
||||
match load_auth_data() {
|
||||
Ok(Some(stored_data)) => {
|
||||
// TODO: Optionally validate token with server here
|
||||
// For now, assume valid if successfully loaded
|
||||
auth_state.auth_token = Some(stored_data.access_token);
|
||||
auth_state.user_id = Some(stored_data.user_id);
|
||||
auth_state.role = Some(stored_data.role);
|
||||
auth_state.decoded_username = Some(stored_data.username);
|
||||
auto_logged_in = true;
|
||||
info!("Auth data loaded from file. User is auto-logged in.");
|
||||
}
|
||||
Ok(None) => {
|
||||
info!("No stored auth data found. User will see intro/login.");
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to load auth data: {}", e);
|
||||
}
|
||||
}
|
||||
// --- END DATA ---
|
||||
|
||||
// Initialize app state with profile tree and table structure
|
||||
let column_names =
|
||||
UiService::initialize_app_state(&mut grpc_client, &mut app_state)
|
||||
@@ -78,6 +101,16 @@ pub async fn run_ui() -> Result<()> {
|
||||
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state).await?;
|
||||
form_state.reset_to_empty();
|
||||
|
||||
// --- DATA2: Adjust initial view based on auth status ---
|
||||
if auto_logged_in {
|
||||
// User is auto-logged in, go to main app view
|
||||
buffer_state.history = vec![AppView::Form("Adresar".to_string())];
|
||||
buffer_state.active_index = 0;
|
||||
info!("Initial view set to Form due to auto-login.");
|
||||
}
|
||||
// If not auto-logged in, BufferState default (Intro) will be used
|
||||
// --- END DATA2 ---
|
||||
|
||||
// --- FPS Calculation State ---
|
||||
let mut last_frame_time = Instant::now();
|
||||
let mut current_fps = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user