// SPDX-License-Identifier: EUPL-1.2+ // SPDX-FileCopyrightText: 2025 Johannes Süllner use super::{ BUTTON_TEXT_SIZE, Event, MARGIN_LR, MARGIN_VERTICAL, Page, TITLE_TEXT_SIZE, UpdateResult, WINDOW_WIDTH, }; use crate::{center_horizontal_in_container, center_in_container}; use iced::{ Element, Task, widget::{ Scrollable, Space, column, scrollable::{Direction, Scrollbar}, text, }, window, }; use std::process::Command; const S6_HPR_PATH: &str = "/bin/s6-linux-init-hpr"; pub struct PageCompletion { install_result: super::InstallResult, } impl PageCompletion { pub fn new(install_result: super::InstallResult) -> Self { Self { install_result } } } #[derive(Clone, Debug)] pub enum PageCompletionEvent { Quit, Poweroff, Reboot, } impl PageCompletion { fn close(id: window::Id) -> Task { window::close(id) } fn spawn_s6_hpr(parameter: &str) { let _ = Command::new(S6_HPR_PATH).arg(parameter).spawn(); } } impl Page for PageCompletion { fn update(&mut self, event: Event) -> UpdateResult { if let Event::PageCompletion(page_completion_event) = event { match page_completion_event { PageCompletionEvent::Quit => { return (None, window::get_latest().and_then(Self::close)); } PageCompletionEvent::Poweroff => { Self::spawn_s6_hpr("-p"); } PageCompletionEvent::Reboot => { Self::spawn_s6_hpr("-r"); } } }; (None, Task::none()) } fn view(&self) -> Element<'_, Event> { let main_element = match &self.install_result { Ok(_) => { center_in_container!(text("Spectrum installation succeeded!").size(TITLE_TEXT_SIZE)).into() } Err((code, log)) => { column![ Space::with_height(MARGIN_VERTICAL), center_horizontal_in_container!(text("Spectrum installation failed :( ").size(TITLE_TEXT_SIZE)), Space::with_height(MARGIN_VERTICAL), center_horizontal_in_container!(Scrollable::new(text(format!("You can reach out to the team via Chat or the \"discuss\" mailing list.\n\ See https://spectrum-os.org/doc/contributing/communication.html for details.\n\ The following information may be relevant:\n\n\ Error code: {}\n\nError log:\n{}", code, log))) .width(WINDOW_WIDTH - 2.0 * MARGIN_LR) .height(500) .direction(Direction::Vertical(Scrollbar::new()))), ] .into() } }; super::layout::bottom_buttons_layout( [ vec![ ( text("Reboot").size(BUTTON_TEXT_SIZE).into(), Some(Event::PageCompletion(PageCompletionEvent::Reboot)), ), ( text("Poweroff").size(BUTTON_TEXT_SIZE).into(), Some(Event::PageCompletion(PageCompletionEvent::Poweroff)), ), ], vec![( text("Quit installer, stay in live environment") .size(BUTTON_TEXT_SIZE) .into(), Some(Event::PageCompletion(PageCompletionEvent::Quit)), )], ], main_element, ) } }