Skip to content

Commit

Permalink
Initializes firmware installation (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Dec 1, 2024
1 parent e66e2d0 commit c23fa96
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 68 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_executable(obliteration WIN32 MACOSX_BUNDLE
progress_dialog.cpp
resources.cpp
resources.qrc
screen.cpp
settings.cpp
system.cpp)

Expand Down
1 change: 1 addition & 0 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ path = "src/main.rs"
bitfield-struct = "0.9.2"
ciborium = "0.2.2"
clap = { version = "4.5.21", features = ["derive"] }
erdp = "0.1.1"
gdbstub = "0.7.3"
gdbstub_arch = "0.3.1"
humansize = "2.1.3"
Expand Down
4 changes: 1 addition & 3 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ int main(int argc, char *argv[])
// Parse arguments.
QCommandLineParser args;

args.setApplicationDescription("Virtualization stack for Obliteration");
args.addHelpOption();
args.addOption(Args::debug);
args.addOption(Args::kernel);
args.process(app);
Expand Down Expand Up @@ -165,7 +163,7 @@ int main(int argc, char *argv[])
#ifdef __APPLE__
MainWindow win(args);
#else
MainWindow win(args, &vulkan, std::move(vkDevices));
MainWindow win(args, std::move(vkDevices));
#endif

win.restoreGeometry();
Expand Down
12 changes: 0 additions & 12 deletions gui/main_window.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "main_window.hpp"
#include "launch_settings.hpp"
#include "resources.hpp"
#include "screen.hpp"
#include "settings.hpp"

#include <QAction>
Expand Down Expand Up @@ -41,13 +40,11 @@ MainWindow::MainWindow(const QCommandLineParser &args) :
#else
MainWindow::MainWindow(
const QCommandLineParser &args,
QVulkanInstance *vulkan,
QList<VkPhysicalDevice> &&vkDevices) :
#endif
m_args(args),
m_main(nullptr),
m_launch(nullptr),
m_screen(nullptr),
m_debugNoti(nullptr)
{
setWindowTitle("Obliteration");
Expand Down Expand Up @@ -92,15 +89,6 @@ MainWindow::MainWindow(
#endif

m_main->addWidget(m_launch);

// Screen.
m_screen = new Screen();

#ifndef __APPLE__
m_screen->setVulkanInstance(vulkan);
#endif

m_main->addWidget(createWindowContainer(m_screen));
}

MainWindow::~MainWindow()
Expand Down
4 changes: 0 additions & 4 deletions gui/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
#endif

class LaunchSettings;
class ProfileList;
class QCommandLineOption;
class QCommandLineParser;
class QSocketNotifier;
class QStackedWidget;
class Screen;

class MainWindow final : public QMainWindow {
public:
Expand All @@ -21,7 +19,6 @@ class MainWindow final : public QMainWindow {
#else
MainWindow(
const QCommandLineParser &args,
QVulkanInstance *vulkan,
QList<VkPhysicalDevice> &&vkDevices);
#endif
~MainWindow() override;
Expand All @@ -42,7 +39,6 @@ private slots:
const QCommandLineParser &m_args;
QStackedWidget *m_main;
LaunchSettings *m_launch;
Screen *m_screen;
QSocketNotifier *m_debugNoti;
};

Expand Down
23 changes: 0 additions & 23 deletions gui/screen.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions gui/screen.hpp

This file was deleted.

20 changes: 20 additions & 0 deletions gui/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::dialogs::{open_file, FileType};
use crate::ui::SetupWizard;
use erdp::ErrorDisplay;
use slint::{ComponentHandle, PlatformError};
use std::cell::Cell;
use std::fs::File;
use std::rc::Rc;
use thiserror::Error;

Expand All @@ -24,6 +26,12 @@ pub fn run_setup() -> Result<bool, SetupError> {
}
});

win.on_install_firmware({
let win = win.as_weak();

move || install_firmware(win.unwrap())
});

win.on_finish({
let win = win.as_weak();
let finish = finish.clone();
Expand Down Expand Up @@ -56,6 +64,18 @@ async fn browse_firmware(win: SetupWizard) {
win.set_firmware_dump(path.into_os_string().into_string().unwrap().into());
}

fn install_firmware(win: SetupWizard) {
// Open firmware dump.
let dump = win.get_firmware_dump();
let dump = match File::open(dump.as_str()) {
Ok(v) => v,
Err(e) => {
win.set_error_message(format!("Failed to open {}: {}.", dump, e.display()).into());
return;
}
};
}

/// Represents an error when [`run_setup()`] fails.
#[derive(Debug, Error)]
pub enum SetupError {
Expand Down
29 changes: 27 additions & 2 deletions gui/ui/error.slint
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Palette, HorizontalBox, StandardButton, VerticalBox } from "std-widgets.slint";

component Content {
component Content inherits Rectangle {
in property <string> message;

background: Palette.background;

HorizontalBox {
VerticalLayout {
alignment: start;
Expand All @@ -23,7 +25,7 @@ component Content {
}

component ActionBar inherits Rectangle {
pure callback close();
callback close();

background: Palette.alternate-background;

Expand All @@ -39,6 +41,29 @@ component ActionBar inherits Rectangle {
}
}

export component ErrorPopup inherits PopupWindow {
in property <string> message;

callback close-clicked <=> ab.close;

close-on-click: false;

Rectangle {
border-color: Palette.border;
border-width: 1px;
clip: true;

VerticalLayout {
Content {
message: message;
vertical-stretch: 1;
}

ab := ActionBar { }
}
}
}

export component ErrorWindow inherits Window {
in property <string> message;

Expand Down
57 changes: 49 additions & 8 deletions gui/ui/setup.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Firmware, InstallFirmware } from "setup/firmware.slint";
import { Conclusion } from "setup/conclusion.slint";
import { NavBar } from "setup/nav.slint";
import { Palette } from "std-widgets.slint";
import { ErrorPopup } from "error.slint";

// https://github.com/slint-ui/slint/issues/6880
enum WizardPage {
Expand All @@ -11,18 +12,28 @@ enum WizardPage {
Conclusion
}

export component SetupWizard inherits Window {
title: "Setup Obliteration";
icon: @image-url("icon.png");
width: 500px; // PopupWindow does not resize with the window somehow.
height: 400px; // Same here.
export enum FirmwareInstaller {
Stopped,
Running
}

export component SetupWizard inherits Window {
in-out property <string> firmware-dump;
in-out property <FirmwareInstaller> firmware-installer;
in property <string> firmware-status;
in property <float> firmware-progress;
in-out property <string> error-message;

pure callback cancel <=> nav.cancel;
pure callback browse-firmware();
pure callback install-firmware();
pure callback finish();

title: "Setup Obliteration";
icon: @image-url("icon.png");
width: 500px; // PopupWindow does not resize with the window somehow.
height: 400px; // Same here.

private property <WizardPage> page: WizardPage.Intro;

states [
Expand All @@ -37,12 +48,16 @@ export component SetupWizard inherits Window {
}

if page == WizardPage.Firmware: Firmware {
firmware-dump: root.firmware-dump;
firmware-dump: firmware-dump;
vertical-stretch: 1;

browse => {
browse-firmware();
}

changed firmware-dump => {
firmware-dump = self.firmware-dump;
}
}

if page == WizardPage.Conclusion: Conclusion {
Expand All @@ -62,18 +77,44 @@ export component SetupWizard inherits Window {
if root.page == WizardPage.Intro {
root.page = WizardPage.Firmware;
} else if root.page == WizardPage.Firmware {
install-firmware.show();
install-firmware();
} else if root.page == WizardPage.Conclusion {
finish();
}
}
}
}

install-firmware := InstallFirmware {
firmware-popup := InstallFirmware {
x: 10px;
y: 150px;
width: parent.width - 20px;
height: parent.height - 300px;
status: firmware-status;
progress: firmware-progress;
}

error-popup := ErrorPopup {
x: 10px;
y: (parent.height / 2) - 50px;
width: parent.width - 20px;
message: error-message;
close-clicked => {
error-message = "";
}
}

changed firmware-installer => {
if firmware-installer == FirmwareInstaller.Running {
firmware-popup.show();
}
}

changed error-message => {
if error-message == "" {
error-popup.close();
} else {
error-popup.show();
}
}
}
8 changes: 7 additions & 1 deletion gui/ui/setup/firmware.slint
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export component Firmware {
}

export component InstallFirmware inherits PopupWindow {
in property <string> status;
in property <float> progress;

close-on-click: false;

Rectangle {
Expand All @@ -50,9 +53,12 @@ export component InstallFirmware inherits PopupWindow {
horizontal-alignment: center;
}

ProgressIndicator { }
ProgressIndicator {
progress: progress;
}

Text {
text: status;
horizontal-alignment: center;
}
}
Expand Down

0 comments on commit c23fa96

Please sign in to comment.