More work on Network stage.

This commit is contained in:
2026-04-23 00:44:01 +02:00
parent 01617374a1
commit a83dbc27f2
8 changed files with 396 additions and 176 deletions
+3 -1
View File
@@ -10,6 +10,8 @@
"license.license": "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.\n\nThis 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.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.",
"license.accept_text": "By pressing 'Accept' button you agreening to terms described above.",
"license.button.accept": "Accept",
"license.button.decline": "Decline",
"network.reuse_checkbox_caption": "Reuse settings?",
"network.reuse_question": "Do you want to apply current network settings to installing system?"
"network.reuse_question": "Do you want to apply current network settings to installing system?",
"network.checking": "Checking network connectivity, please wait..."
}
+74 -79
View File
@@ -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"));
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

-1
View File
@@ -21,7 +21,6 @@
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub enum ConfigValue {
String(String),
+136 -63
View File
@@ -19,24 +19,27 @@
it needed for installation to process.
*/
use toml::Table;
use iced::{Alignment, widget};
use iced::{Alignment, Task, widget};
use iced_moving_picture::widget::apng;
use rust_i18n::t;
use smol;
use std::collections::HashMap;
use toml::Table;
use crate::stage;
use crate::stage::StageResult;
#[derive(Debug, Clone)]
pub enum State {
Init,
Cheking,
ConnOK,
ConnBad,
CheckFailed,
Normal,
}
#[derive(Debug, Clone)]
pub enum CheckResult {
Connected,
NoConnection,
CheckError,
}
#[derive(Debug, Clone)]
@@ -45,103 +48,173 @@ pub struct NetworkStage {
state: State,
use_net_settings: bool,
reqire_network: bool,
spinner_frames: apng::Frames,
}
#[derive(Debug, Clone)]
pub enum Message {
Next,
Back,
StateChange(State),
UseSettingsTogle(bool)
UseSettingsTogle(bool),
CheckNetwork,
CheckCompleted(CheckResult),
}
#[derive(Debug)]
pub enum UpdateResult {
StageAction(stage::StageAction),
Task(Task<Message>),
}
fn check_connection_blocking() -> CheckResult {
use std::process::Command;
match Command::new("nm-online").arg("-q").status() {
Ok(status) => {
if status.success() {
CheckResult::Connected
} else {
CheckResult::NoConnection
}
}
Err(ex) => {
println!("Exception while trying to chen net connectivity: {}", ex);
CheckResult::CheckError
}
}
}
async fn check_connected() -> CheckResult {
use blocking;
let chek_result = blocking::unblock(|| check_connection_blocking()).await;
return chek_result;
}
impl NetworkStage {
pub fn new(toml_config: &Table) -> Self {
let mut reqire_network = false;
if let Some(reqire_network_conf) = toml_config.get("network")
.and_then(|v|v.as_table())
.and_then(|v| v.get("reqire_network"))
.and_then(|v| v.as_bool())
if let Some(reqire_network_conf) = toml_config
.get("network")
.and_then(|v| v.as_table())
.and_then(|v| v.get("reqire_network"))
.and_then(|v| v.as_bool())
{
println!("Config value reqire_network read {}", reqire_network_conf);
reqire_network = reqire_network_conf;
}
else {
} else {
println!("Error parsing network config. Using default values.");
}
let spinner_frames =
apng::Frames::from_bytes(include_bytes!("spiner.apng").to_vec()).unwrap();
Self {
internet_active: false,
state: State::Init,
state: State::Cheking,
use_net_settings: false,
reqire_network: reqire_network
reqire_network: reqire_network,
spinner_frames: spinner_frames,
}
}
fn check_connected(&mut self) -> Result<bool, std::io::Error> {
use std::process::Command;
let status = Command::new("nm-online").arg("-q").status()?;
if status.success() {
self.internet_active = true;
Ok(true)
} else {
self.internet_active = false;
Ok(false)
}
}
fn gen_result(&self) -> StageResult {
StageResult {
name: "network".into(),
config: Some(HashMap::from([(
"accepted".to_string(),
stage::ConfigValue::Bool(true),
)])),
config: Some(HashMap::from([
(
"internet_active".to_string(),
stage::ConfigValue::Bool(self.internet_active),
),
(
"use_net_settings".to_string(),
stage::ConfigValue::Bool(self.use_net_settings),
),
])),
resuts: None,
error: None,
}
}
pub fn update(&mut self, message: Message) -> stage::StageAction {
pub fn update(&mut self, message: Message) -> UpdateResult {
match message {
Message::Next => stage::StageAction::Next(self.gen_result()),
Message::Back => stage::StageAction::Back,
Message::StateChange(new_state) => {
self.state = new_state;
stage::StageAction::None
},
Message::UseSettingsTogle(toggle) => {
self.use_net_settings = toggle;
stage::StageAction::None
Message::CheckNetwork => {
self.state = State::Cheking;
UpdateResult::Task(Task::perform(check_connected(), Message::CheckCompleted))
}
Message::CheckCompleted(check_status) => {
match check_status {
CheckResult::Connected => {
self.internet_active = true;
self.state = State::Normal;
}
CheckResult::NoConnection => {
self.internet_active = false;
self.state = State::Normal;
}
CheckResult::CheckError => {
self.internet_active = false;
self.state = State::Normal;
}
}
UpdateResult::StageAction(stage::StageAction::None)
}
Message::Next => UpdateResult::StageAction(stage::StageAction::Next(self.gen_result())),
Message::Back => UpdateResult::StageAction(stage::StageAction::Back),
Message::UseSettingsTogle(use_net_settings) => {
self.use_net_settings = use_net_settings;
UpdateResult::StageAction(stage::StageAction::None)
}
}
}
pub fn view(&self) -> iced::Element<'_, Message> {
let next_button =
widget::button(widget::text(t!("button.next"))).on_press(Message::Next);
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
let (next_button, back_button) = match self.state {
State::Cheking => (
widget::button(widget::text(t!("button.next"))),
widget::button(widget::text(t!("button.back"))),
),
State::Normal => (
widget::button(widget::text(t!("button.next"))).on_press(Message::Next),
widget::button(widget::text(t!("button.back"))).on_press(Message::Back),
),
};
let mut info_column = match self.state {
State::Cheking => widget::Column::new()
.push(
widget::container(apng(&self.spinner_frames))
.center_x(iced::Length::Fill)
.center_y(iced::Length::Fill),
)
.push(widget::text(t!("network.checking"))),
State::Normal => widget::Column::new(),
};
info_column = info_column.push(widget::text(t!("network.reuse_question")));
info_column = match self.state {
State::Cheking => info_column.push(
widget::checkbox(self.use_net_settings).label(t!("network.reuse_checkbox_caption")),
),
State::Normal => info_column.push(
widget::checkbox(self.use_net_settings)
.label(t!("network.reuse_checkbox_caption"))
.on_toggle(Message::UseSettingsTogle),
)
};
info_column = info_column
.align_x(Alignment::Center)
.padding(20)
.spacing(5);
widget::column![
widget::container(
widget::column![
widget::text(t!("network.reuse_question")),
widget::checkbox(self.use_net_settings)
.label(t!("network.reuse_checkbox_caption"))
.on_toggle(Message::UseSettingsTogle)
]
widget::container(info_column)
.height(iced::Length::Fill)
.width(iced::Length::Fill)
.align_x(Alignment::Center)
.padding(20)
.spacing(5)
)
.height(iced::Length::Fill)
.width(iced::Length::Fill)
.align_x(Alignment::Center)
.align_y(Alignment::Center),
.align_y(Alignment::Center),
widget::row![
back_button,
widget::space::horizontal(), // Pushes the right button to the far right
Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB