More work on Network stage.
This commit is contained in:
+74
-79
@@ -1,64 +1,54 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
This file is the main application file.
|
||||
Main logic and stuff is located here. Including config loading.
|
||||
stages loading, switching between stages, and stuff.
|
||||
*/
|
||||
|
||||
|
||||
This file is the main application file.
|
||||
Main logic and stuff is located here. Including config loading.
|
||||
stages loading, switching between stages, and stuff.
|
||||
*/
|
||||
|
||||
|
||||
use iced::widget;
|
||||
use iced::Alignment;
|
||||
use std::collections::{HashMap};
|
||||
use std::path::{PathBuf,Path};
|
||||
use std::str::FromStr;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use iced::{Element, Task};
|
||||
|
||||
use crate::stage::{StageAction, KiraConfig};
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use crate::stages::license;
|
||||
use crate::stages::network;
|
||||
use crate::stages::welcome;
|
||||
use crate::stages::welcome::WelcomeStage;
|
||||
|
||||
|
||||
rust_i18n::i18n!("src/locales", fallback = "en");
|
||||
mod stage;
|
||||
mod stages;
|
||||
mod theme;
|
||||
|
||||
|
||||
enum Views {
|
||||
Start,
|
||||
Welcome(welcome::WelcomeStage),
|
||||
License(license::LicenseStage),
|
||||
Network(stages::network::NetworkStage),
|
||||
|
||||
}
|
||||
|
||||
enum Message {
|
||||
Start,
|
||||
Welcome(welcome::Message),
|
||||
License(license::Message),
|
||||
Network(stages::network::Message)
|
||||
Welcome(welcome::Message),
|
||||
License(license::Message),
|
||||
Network(stages::network::Message),
|
||||
}
|
||||
|
||||
struct KiraState {
|
||||
@@ -84,11 +74,16 @@ fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error
|
||||
|
||||
impl KiraState {
|
||||
fn boot() -> (Self, Task<Message>) {
|
||||
(Self {
|
||||
current_view: Views::Start,
|
||||
toml_config: toml::Table::new(),
|
||||
config: KiraConfig { config_trail: Vec::new() }
|
||||
}, Task::done(Message::Start))
|
||||
(
|
||||
Self {
|
||||
current_view: Views::Start,
|
||||
toml_config: toml::Table::new(),
|
||||
config: KiraConfig {
|
||||
config_trail: Vec::new(),
|
||||
},
|
||||
},
|
||||
Task::done(Message::Start),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,14 +96,12 @@ impl KiraState {
|
||||
// config: KiraConfig { config_trail: Vec::new() }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
fn view(k_state: &KiraState) -> Element<'_, Message> {
|
||||
match &k_state.current_view {
|
||||
Views::Start => Element::new(widget::space()) ,
|
||||
Views::Start => Element::new(widget::space()),
|
||||
Views::Welcome(wellcome_stage) => wellcome_stage.view().map(Message::Welcome),
|
||||
Views::License(license_stage) => license_stage.view().map(Message::License),
|
||||
Views::Network(network_stage) => network_stage.view().map(Message::Network),
|
||||
@@ -117,18 +110,16 @@ 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) => {
|
||||
println!("Config loaded!");
|
||||
k_state.toml_config = conf;
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
Task::none()
|
||||
},
|
||||
Err(ex) => {
|
||||
println!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
|
||||
iced::exit()
|
||||
}
|
||||
Message::Start => match load_kira_config(CONFIG_PATH_STR) {
|
||||
Ok(conf) => {
|
||||
println!("Config loaded!");
|
||||
k_state.toml_config = conf;
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
Task::none()
|
||||
}
|
||||
Err(ex) => {
|
||||
println!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
|
||||
iced::exit()
|
||||
}
|
||||
},
|
||||
Message::Welcome(wlc_msg) => {
|
||||
@@ -136,48 +127,57 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
let action = wlc_view.update(wlc_msg);
|
||||
if let StageAction::Next(welcome_res) = action {
|
||||
k_state.config.config_trail.push(welcome_res);
|
||||
k_state.current_view = Views::License(license::LicenseStage{});
|
||||
k_state.current_view = Views::License(license::LicenseStage {});
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
},
|
||||
}
|
||||
Message::License(license_message) => {
|
||||
if let Views::License(license_view) = &mut k_state.current_view {
|
||||
let action = license_view.update(license_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));
|
||||
Task::none()
|
||||
},
|
||||
k_state.current_view =
|
||||
Views::Network(network::NetworkStage::new(&k_state.toml_config));
|
||||
Task::done(Message::Network(network::Message::CheckNetwork))
|
||||
}
|
||||
StageAction::Abort(_) => iced::exit(),
|
||||
StageAction::Back => iced::exit(),
|
||||
StageAction::None => Task::none()
|
||||
StageAction::None => Task::none(),
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
},
|
||||
}
|
||||
Message::Network(network_message) => {
|
||||
if let Views::Network(network_view) = &mut k_state.current_view {
|
||||
let update_result = network_view.update(network_message);
|
||||
match update_result {
|
||||
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);
|
||||
iced::exit()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = Views::License(license::LicenseStage {});
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
else {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// pub fn main_interface() -> iced::Result {
|
||||
// iced::run(WellcomeStage::update, WellcomeStage::view)
|
||||
// }
|
||||
pub fn main() -> ExitCode {
|
||||
|
||||
|
||||
// let app_init = || {
|
||||
// let mut k_state = KiraState::default()
|
||||
// k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
@@ -185,16 +185,13 @@ pub fn main() -> ExitCode {
|
||||
// };
|
||||
|
||||
let iced_result = iced::application(KiraState::boot, update, view)
|
||||
.window(iced::window::Settings {
|
||||
icon: Some(
|
||||
iced::window::icon::from_file_data(
|
||||
include_bytes!("icon.png"),
|
||||
None,
|
||||
)
|
||||
.expect("icon should be a valid PNG"),
|
||||
),
|
||||
..Default::default()
|
||||
})
|
||||
.window(iced::window::Settings {
|
||||
icon: Some(
|
||||
iced::window::icon::from_file_data(include_bytes!("icon.png"), None)
|
||||
.expect("icon should be a valid PNG"),
|
||||
),
|
||||
..Default::default()
|
||||
})
|
||||
.centered()
|
||||
.theme(theme::main_theme())
|
||||
.run();
|
||||
@@ -203,10 +200,8 @@ pub fn main() -> ExitCode {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(_) => ExitCode::from(42), // Custom error code
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// fn main() {
|
||||
// println!("Hello, world!");
|
||||
// println!("{}", t!("wellcome.text"));
|
||||
|
||||
Reference in New Issue
Block a user