Addin saving of previos stages for easy going back.

This commit is contained in:
2026-05-30 22:12:08 +02:00
parent b2f510e679
commit 3abbbe9abd
+25 -30
View File
@@ -71,6 +71,7 @@ struct KiraState {
current_view: Views,
toml_config: toml::Table,
config: KiraConfig,
stages_save: Vec<Views>,
}
const CONFIG_PATH_STR: &str = "kira_config.toml";
@@ -97,6 +98,7 @@ impl KiraState {
config: KiraConfig {
config_trail: Vec::new(),
},
stages_save: Vec::new(),
},
Task::done(Message::Start),
)
@@ -136,7 +138,8 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match wlc_view.update(wlc_msg) {
StageAction::Next(welcome_res) => {
k_state.config.config_trail.push(welcome_res);
k_state.current_view = Views::License(license::LicenseStage {});
let s_state = std::mem::replace(&mut k_state.current_view, Views::License(license::LicenseStage {}));
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Abort => iced::exit(),
@@ -152,13 +155,13 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match action {
StageAction::Next(license_res) => {
k_state.config.config_trail.push(license_res);
k_state.current_view =
Views::Network(network::NetworkStage::new(&k_state.toml_config));
let s_state = std::mem::replace(&mut k_state.current_view, Views::Network(network::NetworkStage::new(&k_state.toml_config)));
k_state.stages_save.push(s_state);
Task::done(Message::Network(network::Message::CheckNetwork))
}
StageAction::Abort => iced::exit(),
StageAction::Back => {
k_state.current_view = Views::Welcome(WelcomeStage::new());
k_state.current_view = k_state.stages_save.pop().unwrap();
k_state.config.config_trail.pop();
Task::none()
}
@@ -176,12 +179,12 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
network::UpdateResult::StageAction(action) => match action {
StageAction::Next(network_res) => {
k_state.config.config_trail.push(network_res);
k_state.current_view =
Views::TimeZone(stages::timezone::TimeZoneStage::new());
let s_state = std::mem::replace(&mut k_state.current_view,Views::TimeZone(stages::timezone::TimeZoneStage::new()));
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.current_view = Views::License(license::LicenseStage {});
k_state.current_view = k_state.stages_save.pop().unwrap();
k_state.config.config_trail.pop();
Task::none()
}
@@ -198,16 +201,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match action {
StageAction::Next(tz_res) => {
k_state.config.config_trail.push(tz_res);
k_state.current_view =
Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
let s_state = std::mem::replace(&mut k_state.current_view,Views::Locale(stages::locale::LocaleStage::new(&k_state.config)));
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 =
Views::Network(network::NetworkStage::new(&k_state.toml_config));
Task::done(Message::Network(network::Message::CheckNetwork))
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
StageAction::None => Task::none(),
}
@@ -220,14 +222,13 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match locale_view.update(locale_msg) {
StageAction::Next(locale_res) => {
k_state.config.config_trail.push(locale_res);
k_state.current_view =
Views::Keyboard(stages::keyboard::KeyboardStage::new());
let s_state = std::mem::replace(&mut k_state.current_view,Views::Keyboard(stages::keyboard::KeyboardStage::new()));
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view =
Views::TimeZone(stages::timezone::TimeZoneStage::new());
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
_ => Task::none(),
@@ -243,7 +244,8 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match stages::partition::PartitionStage::new(&k_state.toml_config) {
Ok(part_stage) => {
k_state.config.config_trail.push(keyboard_res);
k_state.current_view = Views::Partition(part_stage);
let s_state = std::mem::replace(&mut k_state.current_view,Views::Partition(part_stage));
k_state.stages_save.push(s_state);
}
Err(ex) => {
log::error!("Error, cannot init partition stage: {}", ex);
@@ -253,8 +255,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view =
Views::Locale(stages::locale::LocaleStage::new(&k_state.config));
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
_ => Task::none(),
@@ -268,13 +269,13 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match partition_view.update(partition_msg) {
StageAction::Next(partition_res) => {
k_state.config.config_trail.push(partition_res);
k_state.current_view = Views::Security(stages::security::SecurityStage::new());
let s_state = std::mem::replace(&mut k_state.current_view,Views::Security(stages::security::SecurityStage::new()));
k_state.stages_save.push(s_state);
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
k_state.current_view =
Views::Keyboard(stages::keyboard::KeyboardStage::new());
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
_ => Task::none(),
@@ -288,18 +289,12 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match security_view.update(security_msg) {
StageAction::Next(security_res) => {
k_state.config.config_trail.push(security_res);
//let s_state = std::mem::replace(&mut k_state.current_view,
Task::none()
}
StageAction::Back => {
k_state.config.config_trail.pop();
match stages::partition::PartitionStage::new(&k_state.toml_config) {
Ok(part_stage) => {
k_state.current_view = Views::Partition(part_stage);
}
Err(ex) => {
log::error!("Error, cannot init partition stage: {}", ex);
}
}
k_state.current_view = k_state.stages_save.pop().unwrap();
Task::none()
}
_ => Task::none(),