Files
kira-installer/src/main.rs
T

145 lines
3.9 KiB
Rust
Raw Normal View History

// <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 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 iced::{Element, Task};
use crate::stage::{StageAction, KiraConfig};
use crate::stages::license;
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),
}
enum Message {
Welcome(welcome::Message),
License(license::Message)
}
struct KiraState {
current_view: Views,
toml_config: toml::Table,
config: KiraConfig,
}
impl KiraState {
fn new(toml_config: toml::Table) -> Self {
Self {
current_view: Views::Start,
toml_config: toml_config,
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::Welcome(wellcome_stage) => wellcome_stage.view().map(Message::Welcome),
Views::License(license_stage) => license_stage.view().map(Message::License),
}
}
fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
match message {
Message::Welcome(wlc_msg) => {
if let Views::Welcome(wlc_view) = &mut k_state.current_view {
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{});
}
}
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);
iced::exit()
},
StageAction::Abort(_) => iced::exit(),
StageAction::Back => iced::exit(),
StageAction::None => Task::none()
}
}
else {
Task::none()
}
}
}
}
// pub fn main_interface() -> iced::Result {
// iced::run(WellcomeStage::update, WellcomeStage::view)
// }
pub fn main() -> iced::Result {
use toml;
let app_init = || {
let mut k_state = KiraState::new(toml::Table::new());
k_state.current_view = Views::Welcome(WelcomeStage::new());
k_state
};
iced::application(app_init, update, view)
.centered()
.theme(theme::main_theme())
.run()
}
// fn main() {
// println!("Hello, world!");
// println!("{}", t!("wellcome.text"));
// // Initialize the state
// let _res = main_interface();
// }