patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 2ea973472c8de8ef9e9cc94cb013e3fc6aef640a 3708 bytes (raw)
name: tools/spectrum-installer/src/pages/completion.rs 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
 
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2025 Johannes Süllner <johannes.suellner@mailbox.org>

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<Event> {
        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,
        )
    }
}

debug log:

solving 2ea9734 ...
found 2ea9734 in https://inbox.spectrum-os.org/spectrum-devel/20260104140102.106960-5-johannes.suellner@mailbox.org/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20260104140102.106960-5-johannes.suellner@mailbox.org/
diff --git a/tools/spectrum-installer/src/pages/completion.rs b/tools/spectrum-installer/src/pages/completion.rs
new file mode 100644
index 0000000..2ea9734

Checking patch tools/spectrum-installer/src/pages/completion.rs...
Applied patch tools/spectrum-installer/src/pages/completion.rs cleanly.

index at:
100644 2ea973472c8de8ef9e9cc94cb013e3fc6aef640a	tools/spectrum-installer/src/pages/completion.rs

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).