Skip to content

Commit

Permalink
feat(pages/installation): progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Jun 27, 2024
1 parent ac0e8a8 commit 7bd2252
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn detect_os() -> Vec<DiskInit> {
.find(|(path, _)| path.starts_with(&disk.name))
.map(|(_, osname)| osname.to_string())
.unwrap_or(OSNAME_PLACEHOLDER.to_string()),
devpath: PathBuf::from(disk.name.clone()),
devpath: PathBuf::from(disk.fullname.clone()),
};
tracing::debug!(?ret, "Found disk");
ret
Expand Down
9 changes: 8 additions & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ pub enum InstallationType {
}

impl InstallationType {
#[tracing::instrument]
pub fn install(&self, state: &crate::InstallationState) -> Result<()> {
let blockdev = &state.destination_disk.as_ref().unwrap().devpath;
let cfgdir = self.cfgdir();
Self::systemd_repart(blockdev, &cfgdir)?;
if let Self::ChromebookInstall = self {
Self::set_cgpt_flags(blockdev)?;
}
tracing::info!("install() finished");
Ok(())
}
fn cfgdir(&self) -> PathBuf {
Expand All @@ -28,17 +30,22 @@ impl InstallationType {
}
.into()
}
#[tracing::instrument]
fn systemd_repart(blockdev: &Path, cfgdir: &Path) -> Result<()> {
let dry_run = if cfg!(debug_assertions) { "yes" } else { "no" };
tracing::debug!(?dry_run, "Running systemd-repart");
cmd_lib::run_cmd!(
systemd-repart
--dry-run=$dry_run
--definitions=$cfgdir
$blockdev
)?;
).map_err(|e| color_eyre::eyre::eyre!("systemd-repart failed").wrap_err(e))?;

tracing::debug!("systemd-repart finished");
Ok(())
}
fn set_cgpt_flags(blockdev: &Path) -> Result<()> {
tracing::debug!("Setting cgpt flags");
cmd_lib::run_cmd!(cgpt add -i 1 -t kernel -P 15 -T 1 -S 1 $blockdev)?;
Ok(())
}
Expand Down
14 changes: 8 additions & 6 deletions src/pages/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use gettextrs::gettext;
use libhelium::prelude::*;
use relm4::{ComponentParts, ComponentSender, SimpleComponent};

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InstallationPage {
progress: f64,
progress_bar: gtk::ProgressBar,
}

#[derive(Debug)]
Expand Down Expand Up @@ -48,9 +48,8 @@ impl SimpleComponent for InstallationPage {
set_label: &*gettext("Installing base system...")
},

gtk::ProgressBar {
#[watch]
set_fraction: model.progress
#[local_ref]
progress_bar -> gtk::ProgressBar {
}
}
}
Expand All @@ -61,7 +60,8 @@ impl SimpleComponent for InstallationPage {
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self { progress: 0.0 };
let model = Self::default();
let progress_bar = &model.progress_bar;

let widgets = view_output!();

Expand All @@ -72,13 +72,15 @@ impl SimpleComponent for InstallationPage {

#[tracing::instrument]
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
self.progress_bar.pulse();
// handle channel logics here
match message {
InstallationPageMsg::StartInstallation => sender.command(|_out, shutdown| {
shutdown
.register(async move {
let state = INSTALLATION_STATE.read();
tracing::debug!("Starting installation...");
// FIXME: all errors are ignored due to shutdown.register() not handling results
state.installation_type.as_ref().unwrap().install(&state)?;

color_eyre::Result::<_>::Ok(())
Expand Down

0 comments on commit 7bd2252

Please sign in to comment.