Work on Network stage and toml config.
This commit is contained in:
+2
-1
@@ -16,4 +16,5 @@
|
||||
|
||||
|
||||
pub mod welcome;
|
||||
pub mod license;
|
||||
pub mod license;
|
||||
pub mod network;
|
||||
@@ -0,0 +1,158 @@
|
||||
// <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 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 is Network stage. Chiking if internet is active and propose to configure it if
|
||||
it needed for installation to process.
|
||||
*/
|
||||
|
||||
use toml::Table;
|
||||
use iced::{Alignment, widget};
|
||||
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::stage;
|
||||
use crate::stage::StageResult;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum State {
|
||||
Init,
|
||||
Cheking,
|
||||
ConnOK,
|
||||
ConnBad,
|
||||
CheckFailed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NetworkStage {
|
||||
internet_active: bool,
|
||||
state: State,
|
||||
use_net_settings: bool,
|
||||
reqire_network: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
Next,
|
||||
Back,
|
||||
StateChange(State),
|
||||
UseSettingsTogle(bool)
|
||||
}
|
||||
|
||||
|
||||
|
||||
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())
|
||||
{
|
||||
println!("Config value reqire_network read {}", reqire_network_conf);
|
||||
reqire_network = reqire_network_conf;
|
||||
}
|
||||
else {
|
||||
println!("Error parsing network config. Using default values.");
|
||||
}
|
||||
|
||||
Self {
|
||||
internet_active: false,
|
||||
state: State::Init,
|
||||
use_net_settings: false,
|
||||
reqire_network: reqire_network
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
)])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> stage::StageAction {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.padding(20)
|
||||
.spacing(5)
|
||||
)
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center),
|
||||
widget::row![
|
||||
back_button,
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
next_button
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10)
|
||||
.spacing(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,12 @@ impl WelcomeStage {
|
||||
self.locale = Some(loc);
|
||||
StageAction::None
|
||||
}
|
||||
Message::Exit => StageAction::Back,
|
||||
Message::Exit => StageAction::Abort(StageResult {
|
||||
name: "welcome".to_string(),
|
||||
config: None,
|
||||
resuts: None,
|
||||
error: None,
|
||||
}),
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user