Files
installer/iridium_installer/ui/window.py

292 lines
11 KiB
Python

import gi
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Adw, Gtk
from .pages.additional_modules import ModulesPage
from .pages.install_mode import InstallModePage
from .pages.partitioning import PartitioningPage, calculate_auto_partitions
from .pages.storage import StoragePage
from .pages.summary import SummaryPage
from .pages.user import UserPage
from .pages.welcome import WelcomePage
class InstallerWindow(Adw.ApplicationWindow):
def __init__(self, mock_mode=False, *args, **kwargs):
super().__init__(*args, **kwargs)
self.mock_mode = mock_mode
self.set_default_size(900, 650)
self.set_title("Iridium Installer" + (" (MOCK MODE)" if mock_mode else ""))
self.set_icon_name("org.iridium.Installer")
self.toolbar_view = Adw.ToolbarView()
self.set_content(self.toolbar_view)
# Header Bar (Top)
self.header_bar = Adw.HeaderBar()
self.toolbar_view.add_top_bar(self.header_bar)
# Content Stack
self.stack = Adw.ViewStack()
self.stack.set_vexpand(True)
self.toolbar_view.set_content(self.stack)
# Navigation Bar (Bottom)
self.bottom_bar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.bottom_bar.add_css_class("toolbar")
self.bottom_bar.set_margin_top(12)
self.bottom_bar.set_margin_bottom(12)
self.bottom_bar.set_margin_start(12)
self.bottom_bar.set_margin_end(12)
self.bottom_bar.set_spacing(12)
self.toolbar_view.add_bottom_bar(self.bottom_bar)
# Back Button
self.back_button = Gtk.Button(label="Back")
self.back_button.connect("clicked", self.on_back_clicked)
self.back_button.set_sensitive(False)
self.bottom_bar.append(self.back_button)
# Spacer to push Next button to the right
spacer = Gtk.Label()
spacer.set_hexpand(True)
self.bottom_bar.append(spacer)
# Next Button
self.next_button = Gtk.Button(label="Next")
self.next_button.add_css_class("suggested-action")
self.next_button.connect("clicked", self.on_next_clicked)
self.bottom_bar.append(self.next_button)
# Page Management
self.page_ids = []
self.current_page_index = 0
# Initialize Pages
self.welcome_page = WelcomePage()
self.storage_page = StoragePage()
self.storage_page.connect("disk-selected", self.on_disk_selected)
self.install_mode_page = InstallModePage()
self.partitioning_page = PartitioningPage()
self.modules_page = ModulesPage()
self.user_page = UserPage()
self.user_page.connect("validity-changed", self.on_user_validity_changed)
self.summary_page = SummaryPage()
# Add Pages
self.add_page(self.welcome_page, "welcome")
self.add_page(self.storage_page, "storage")
self.add_page(self.install_mode_page, "install_mode")
self.add_page(self.partitioning_page, "partitioning")
self.add_page(self.modules_page, "modules")
self.add_page(self.user_page, "user")
self.add_page(self.summary_page, "summary")
# Initialize view
if self.page_ids:
self.stack.set_visible_child_name(self.page_ids[0])
self.update_buttons()
def add_page(self, widget, name):
self.stack.add_named(widget, name)
self.page_ids.append(name)
def on_disk_selected(self, page, device_name):
self.update_buttons()
def on_user_validity_changed(self, page, valid):
self.update_buttons()
def update_buttons(self):
# Back button state
self.back_button.set_sensitive(self.current_page_index > 0)
# Next button label/state
current_page_name = self.page_ids[self.current_page_index]
# Forced selection logic
forced_selection = True
if current_page_name == "storage":
forced_selection = self.storage_page.get_selected_disk() is not None
elif current_page_name == "user":
forced_selection = self.user_page.is_valid()
self.next_button.set_sensitive(forced_selection)
if current_page_name == "summary":
self.next_button.set_label(
"Install" + (" (MOCK)" if self.mock_mode else "")
)
self.next_button.add_css_class("destructive-action")
self.next_button.remove_css_class("suggested-action")
else:
self.next_button.set_label("Next")
self.next_button.remove_css_class("destructive-action")
self.next_button.add_css_class("suggested-action")
def on_back_clicked(self, button):
current_page = self.page_ids[self.current_page_index]
# Default: go back one page
next_prev_index = self.current_page_index - 1
if current_page == "modules":
mode = self.install_mode_page.get_mode()
if mode == "automatic":
# Skip partitioning (which is immediately before modules)
next_prev_index = self.page_ids.index("install_mode")
if next_prev_index >= 0:
self.current_page_index = next_prev_index
self.stack.set_visible_child_name(self.page_ids[self.current_page_index])
self.update_buttons()
def show_progress_page(self, message):
prog_page = Adw.StatusPage()
prog_page.set_title(message)
prog_page.set_description("Please wait while we set up your system.")
spinner = Gtk.Spinner()
spinner.set_size_request(32, 32)
spinner.set_halign(Gtk.Align.CENTER)
spinner.start()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
box.append(spinner)
prog_page.set_child(box)
name = "progress_install"
self.stack.add_named(prog_page, name)
self.stack.set_visible_child_name(name)
# Hide navigation buttons during install
self.bottom_bar.set_visible(False)
def show_finish_page(self, message, success=True):
finish_page = Adw.StatusPage()
finish_page.set_title(message)
if success:
finish_page.set_icon_name("emblem-ok-symbolic")
finish_page.set_description("You can now restart your computer.")
btn_label = "Restart"
else:
finish_page.set_icon_name("dialog-error-symbolic")
finish_page.set_description("An error occurred during installation.")
btn_label = "Close"
btn = Gtk.Button(label=btn_label)
btn.set_halign(Gtk.Align.CENTER)
btn.add_css_class("suggested-action")
btn.connect("clicked", lambda b: self.close())
finish_page.set_child(btn)
name = "finish_install"
self.stack.add_named(finish_page, name)
self.stack.set_visible_child_name(name)
def on_next_clicked(self, button):
# Logic before transition
current_page_name = self.page_ids[self.current_page_index]
if current_page_name == "storage":
selected_disk = self.storage_page.get_selected_disk()
self.partitioning_page.load_partitions(selected_disk)
next_index = self.current_page_index + 1
if current_page_name == "install_mode":
mode = self.install_mode_page.get_mode()
if mode == "automatic":
# Skip partitioning page
next_index = self.page_ids.index("modules")
else:
# Go to partitioning page
next_index = self.page_ids.index("partitioning")
if current_page_name == "user":
# Prepare summary instead of installing immediately
disk = self.storage_page.get_selected_disk()
mode = self.install_mode_page.get_mode()
modules = self.modules_page.get_modules()
user_info = self.user_page.get_user_info()
mount_root = self.welcome_page.get_mount_root()
partitions_config = {}
if mode == "manual":
partitions_config = self.partitioning_page.get_config()
elif mode == "automatic":
partitions = calculate_auto_partitions(disk)
partitions_config = {"partitions": partitions}
# Update summary page
self.summary_page.update_summary(
disk_info=disk,
mode=mode,
partitions=partitions_config,
user_info=user_info,
modules=modules,
mount_root=mount_root,
)
# Proceed to summary page (which is next_index after user)
if current_page_name == "summary":
# THIS IS THE REAL INSTALL TRIGGER
print("Install process triggered!")
disk = self.storage_page.get_selected_disk()
mode = self.install_mode_page.get_mode()
modules = self.modules_page.get_modules()
user_info = self.user_page.get_user_info()
mount_root = self.welcome_page.get_mount_root()
if self.mock_mode:
print("!!! MOCK MODE ENABLED - NO CHANGES WILL BE MADE !!!")
print(f"Target Disk: {disk}")
print(f"Mode: {mode}")
print(f"Modules: {modules}")
print(f"User: {user_info}")
print(f"Mount Root: {mount_root}")
print("Simulation complete.")
# Show success in UI even in mock
self.show_finish_page("Mock Installation Complete!")
else:
from ..backend.disk import auto_partition_disk, mount_partitions
from ..backend.os_install import install_minimal_os, configure_system
# Simple progress UI transition
self.show_progress_page("Installing Iridium OS...")
# We should really run this in a thread to keep UI responsive,
# but for "barely bootable" requirement and simplicity:
try:
# Step 1: Partitioning
print("Step 1: Partitioning...")
parts = auto_partition_disk(disk)
# Step 2: Mounting
print("Step 2: Mounting...")
mount_partitions(parts, mount_root)
# Step 3: OS Installation
print("Step 3: OS Installation...")
install_minimal_os(mount_root)
# Step 4: Configure
print("Step 4: Configuration...")
configure_system(mount_root, parts)
self.show_finish_page("Installation Successful!")
except Exception as e:
print(f"Installation failed: {e}")
self.show_finish_page(f"Installation Failed: {e}", success=False)
return
if next_index < len(self.page_ids):
self.current_page_index = next_index
self.stack.set_visible_child_name(self.page_ids[self.current_page_index])
self.update_buttons()