From c56da21eab1792f1f77317824486885a8814ddd06ffeca97977f11b5ca30d95e Mon Sep 17 00:00:00 2001 From: Kira Date: Sat, 6 Jun 2026 00:28:29 +0200 Subject: [PATCH] Adding initial stuff for install stage. --- src/stages/install/mod.rs | 181 ++++++++++++++++++++++++++++++++++++++ src/stages/mod.rs | 3 +- 2 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 src/stages/install/mod.rs diff --git a/src/stages/install/mod.rs b/src/stages/install/mod.rs new file mode 100644 index 0000000..4a54f9b --- /dev/null +++ b/src/stages/install/mod.rs @@ -0,0 +1,181 @@ +// +// Copyright (C) <2026> + +// 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 . + +/* + Actual installation script. +*/ + +/// +/// So. I am goind to make dir structure lile this +/// /bzz/root +/// /bzz/home +/// Mount root from it and binmount home +/// + +use log; +use crate::{ + kira_theming, + stage::{KiraConfig, StageAction, StageResult}, +}; +use iced::{Alignment, Task, futures, widget}; +use rust_i18n::t; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum InstallationState { + UserConfirmDialog, + Partitionning, + CopyFiles, + Configuring, + Finish, + Error, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct InstallStage { + state: InstallationState, + progress: f32, + progress_message: String, +} + +#[derive(Debug, Clone)] +pub enum Message { + UserConfirms, + UserDenies, + StartPartitioning, + UpdateProgress(Result<(f32, String), String>), + PartitioningFinish(Result<(), String>), + Back, + Cancel, + Finish, +} + +#[derive(Debug)] +pub enum Update { + StgAct(StageAction), + Task(Task), +} + + + + +impl InstallStage { + pub fn new(config: &KiraConfig) -> Self { + Self { + state: InstallationState::UserConfirmDialog, + progress: 0.0, + progress_message: String::new(), + } + } + + fn gen_result(&self) -> StageResult { + StageResult::new("install") + } + + pub fn update(&mut self, message: Message) -> Update { + match message { + Message::UserDenies => Update::StgAct(StageAction::Back), + Message::UserConfirms => { + // starting installation process here + self.state = InstallationState::Partitionning; + Update::Task(Task::run(disk_part::check_connected(), Message::UpdateProgress)) + //Update::Task(Task::perform(, Message::PartitioningFinish)) + } + Message::StartPartitioning => Update::StgAct(StageAction::None), + Message::PartitioningFinish(res) => Update::StgAct(StageAction::None), + Message::UpdateProgress(maybe_msg) => { + match maybe_msg { + Ok((progress, msg))=> { + self.progress = progress; + self.progress_message = msg; + Update::StgAct(StageAction::None) + } + Err(ex) => { + log::error!("{}", &ex); + self.state = InstallationState::Error; + Update::StgAct(StageAction::None) + } + } + //Update::StgAct(StageAction::None) + + }, + Message::Cancel => Update::StgAct(StageAction::Abort), + Message::Back => Update::StgAct(StageAction::Back), + Message::Finish => Update::StgAct(StageAction::None), + } + } + + pub fn view(&self) -> iced::Element<'_, Message> { + let action_button = if self.state == InstallationState::Finish { + widget::button(widget::text(t!("button.finish"))).on_press(Message::Finish) + } else { + widget::button(widget::text(t!("button.cancel"))).on_press(Message::Cancel) + }; + + // Embed the image bytes into the executable + let welcom_logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes()); + + let main_content = widget::column![ + widget::container( + widget::column![ + widget::image(welcom_logo_handle) + .width(iced::Pixels(128.0)) + .height(iced::Pixels(128.0)), + widget::text(t!("install.caption")), + widget::progress_bar(0.0..=100.0, self.progress), + widget::text(self.progress_message.clone()), + ] + .padding(10) + .spacing(10) + .align_x(Alignment::Center) + ) + .height(iced::Length::Fill) + .width(iced::Length::Fill) + .align_x(Alignment::Center) + .align_y(Alignment::Center), + widget::container(action_button) + .width(iced::Length::Fill) + .align_y(Alignment::End) + .padding(10), + ] + .align_x(Alignment::Center) + .spacing(10); + + let page_stack = widget::Stack::with_capacity(2).push(main_content); + + if self.state == InstallationState::UserConfirmDialog { + page_stack + .push( + widget::column![ + widget::text(t!("install.warning")), + widget::row![ + widget::button(widget::text(t!("button.no"))) + .on_press(Message::UserDenies), + widget::space::horizontal(), // Pushes the right button to the far right + widget::button(widget::text(t!("button.yes"))) + .on_press(Message::UserConfirms) + ] + .width(iced::Length::Fill) + .align_y(Alignment::End) + .padding(10) + ] + .align_x(Alignment::Center), + ) + .into() + } else { + page_stack.into() + } + } +} diff --git a/src/stages/mod.rs b/src/stages/mod.rs index b112d03..1857875 100644 --- a/src/stages/mod.rs +++ b/src/stages/mod.rs @@ -22,4 +22,5 @@ pub mod timezone; pub mod locale; pub mod keyboard; pub mod partition; -pub mod security; \ No newline at end of file +pub mod security; +pub mod install; \ No newline at end of file