Refactor of stages results handling

This commit is contained in:
kira committed 2026-09-25 17:33:10 +02:00
1 parent dda9288e23
commit fa5c3d3aec
15 files changed
+709 -316

No files matched your search

+32 -51
View File
@@ -72,35 +72,31 @@ enum Message {
struct KiraState {
current_view: Views,
toml_config: toml::Table,
config: KiraConfig,
k_config: KiraConfig,
stages_save: Vec<Views>,
}
const CONFIG_PATH_STR: &str = "kira_config.toml";
// const CONFIG_PATH_STR: &str = "kira_config.toml";
fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error::Error>> {
use std::fs;
use toml::Table;
// 1. Read the file content into a String
let content = fs::read_to_string(config_path)?;
// fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error::Error>> {
// use std::fs;
// use toml::Table;
// // 1. Read the file content into a String
// let content = fs::read_to_string(config_path)?;
// 2. Parse the string into a Table
let table: Table = content.parse()?;
// // 2. Parse the string into a Table
// let table: Table = content.parse()?;
log::info!("{:?}", table);
Ok(table)
}
// log::info!("{:?}", table);
// Ok(table)
// }
impl KiraState {
fn boot() -> (Self, Task<Message>) {
(
Self {
current_view: Views::Start,
toml_config: toml::Table::new(),
config: KiraConfig {
config_trail: Vec::new(),
},
k_config: KiraConfig ::default(),
stages_save: Vec::new(),
},
Task::done(Message::Start),
@@ -125,26 +121,19 @@ fn view(k_state: &KiraState) -> Element<'_, Message> {
fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match message {
Message::Start => match load_kira_config(CONFIG_PATH_STR) {
Ok(conf) => {
log::info!("Config loaded!");
k_state.toml_config = conf;
k_state.current_view = Views::Welcome(WelcomeStage::new());
Message::Start => {
log::info!("Starting!");
k_state.current_view = Views::Welcome(WelcomeStage::new(k_state.k_config.clone()));
Task::none()
}
Err(ex) => {
log::error!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
iced::exit()
}
},
Message::Welcome(wlc_msg) => {
if let Views::Welcome(wlc_view) = &mut k_state.current_view {
match wlc_view.update(wlc_msg) {
StageAction::Next(welcome_res) => {
k_state.config.config_trail.push(welcome_res);
k_state.k_config = welcome_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::License(license::LicenseStage {}),
Views::License(license::LicenseStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
@@ -161,10 +150,10 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
let action = license_view.update(license_message);
match action {
StageAction::Next(license_res) => {
k_state.config.config_trail.push(license_res);
k_state.k_config = license_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Network(network::NetworkStage::new(&k_state.toml_config)),
Views::Network(network::NetworkStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::done(Message::Network(network::Message::CheckNetwork))
@@ -172,7 +161,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
StageAction::Abort => iced::exit(),
StageAction::Back => {
k_state.current_view = k_state.stages_save.pop().unwrap();
k_state.config.config_trail.pop();
Task::none()
}
StageAction::None => Task::none(),
@@ -188,17 +176,16 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
network::UpdateResult::Task(t) => t.map(Message::Network),
network::UpdateResult::StageAction(action) => match action {
StageAction::Next(network_res) => {
k_state.config.config_trail.push(network_res);
k_state.k_config = network_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::TimeZone(stages::timezone::TimeZoneStage::new()),
Views::TimeZone(stages::timezone::TimeZoneStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.current_view = k_state.stages_save.pop().unwrap();
k_state.config.config_trail.pop();
Task::none()
}
_ => Task::none(),
@@ -213,17 +200,16 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
let action = timezone_view.update(timezone_message);
match action {
StageAction::Next(tz_res) => {
k_state.config.config_trail.push(tz_res);
k_state.k_config = tz_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Locale(stages::locale::LocaleStage::new(&k_state.config)),
Views::Locale(stages::locale::LocaleStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Abort => iced::exit(),
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
@@ -237,16 +223,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
if let Views::Locale(locale_view) = &mut k_state.current_view {
match locale_view.update(locale_msg) {
StageAction::Next(locale_res) => {
k_state.config.config_trail.push(locale_res);
k_state.k_config = locale_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Keyboard(stages::keyboard::KeyboardStage::new()),
Views::Keyboard(stages::keyboard::KeyboardStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
@@ -260,9 +245,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
if let Views::Keyboard(keyboard_view) = &mut k_state.current_view {
match keyboard_view.update(keyboard_msg) {
StageAction::Next(keyboard_res) => {
match stages::partition::PartitionStage::new(&k_state.toml_config) {
match stages::partition::PartitionStage::new(k_state.k_config.clone()) {
Ok(part_stage) => {
k_state.config.config_trail.push(keyboard_res);
k_state.k_config = keyboard_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Partition(part_stage),
@@ -276,7 +261,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
@@ -290,16 +274,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
if let Views::Partition(partition_view) = &mut k_state.current_view {
match partition_view.update(partition_msg) {
StageAction::Next(partition_res) => {
k_state.config.config_trail.push(partition_res);
k_state.k_config = partition_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Security(stages::security::SecurityStage::new()),
Views::Security(stages::security::SecurityStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
@@ -313,16 +296,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
if let Views::Security(security_view) = &mut k_state.current_view {
match security_view.update(security_msg) {
StageAction::Next(security_res) => {
k_state.config.config_trail.push(security_res);
k_state.k_config = security_res;
let s_state = std::mem::replace(
&mut k_state.current_view,
Views::Install(stages::install::InstallStage::new(&k_state.config)),
Views::Install(stages::install::InstallStage::new(k_state.k_config.clone())),
);
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
@@ -339,7 +321,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
stages::install::Update::Task(t) => t.map(Message::Install),
stages::install::Update::StgAct(stage_action) => match stage_action {
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}