Skip to content

Commit

Permalink
Moves Slint files to ui directory (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Nov 18, 2024
1 parent 8aba08a commit 98f1b5f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 90 deletions.
26 changes: 17 additions & 9 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ path = "src/main.rs"
required-features = ["slint"]

[features]
slint = [
"dep:slint",
"dep:clap",
"dep:rfd",
"dep:open",
]
slint = ["dep:slint", "dep:clap", "dep:rfd", "dep:open"]
qt = []

[dependencies]
Expand All @@ -29,7 +24,10 @@ gdbstub_arch = "0.3.1"
humansize = "2.1.3"
libc = "0.2.155"
obconf = { path = "../src/obconf", features = ["serde", "virt"] }
obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = ["read", "std"] }
obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = [
"read",
"std",
] }
param = { path = "../src/param" }
pkg = { path = "../src/pkg" }
ciborium = "0.2.2"
Expand All @@ -48,12 +46,22 @@ x86-64 = { path = "../arch/x86-64" }
[dependencies.slint]
git = "https://github.com/slint-ui/slint"
rev = "875ca075fb5b2dfe4c3ab0a499d5759412fc1395"
features = ["compat-1-2", "std", "accessibility", "raw-window-handle-06", "backend-winit", "renderer-skia"]
features = [
"compat-1-2",
"std",
"accessibility",
"raw-window-handle-06",
"backend-winit",
"renderer-skia",
]
default-features = false
optional = true

[target.'cfg(not(target_os = "macos"))'.dependencies]
ash = { version = "0.38.0", features = ["linked", "std"], default-features = false }
ash = { version = "0.38.0", features = [
"linked",
"std",
], default-features = false }

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.52.0"
Expand Down
4 changes: 2 additions & 2 deletions gui/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fn main() {
}

fn build_bin() {
// Compile main
// Compile Slint.
slint_build::compile_with_config(
"slint/main.slint",
"ui/main.slint",
CompilerConfiguration::new().with_style(String::from("fluent-dark")),
)
.unwrap();
Expand Down
115 changes: 36 additions & 79 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use self::ui::ErrorDialog;
use args::CliArgs;
use clap::Parser;
use debug::DebugServer;
use graphics::{GraphicsApi, PhysicalDevice};
use slint::{ComponentHandle, Global, ModelExt, ModelRc, SharedString, VecModel};
use std::path::Path;
use std::process::{ExitCode, Termination};
use std::process::ExitCode;
use thiserror::Error;

mod args;
Expand All @@ -22,39 +23,21 @@ mod system;
mod ui;
mod vmm;

fn main() -> AppExit {
let res = run().inspect_err(|e| {
ui::ErrorDialog::new()
.and_then(|error_dialog| {
error_dialog.set_message(SharedString::from(format!(
"Error running application: {}",
full_error_reason(e)
)));

error_dialog.run()
})
.unwrap();
});

AppExit::from(res)
fn main() -> ExitCode {
match run() {
Ok(_) => ExitCode::SUCCESS,
Err(e) => {
display_error(e);
ExitCode::FAILURE
}
}
}

fn run() -> Result<(), ApplicationError> {
let args = CliArgs::try_parse().map_err(ApplicationError::ParseArgs)?;

#[cfg(unix)]
if let Err(e) = rlim::set_rlimit_nofile() {
ui::ErrorDialog::new()
.and_then(|error_dialog| {
error_dialog.set_message(SharedString::from(format!(
"Error setting rlimit: {}",
full_error_reason(e)
)));

error_dialog.run()
})
.unwrap();
}
rlim::set_rlimit_nofile().map_err(ApplicationError::FdLimit)?;

// TODO: check if already configured and skip wizard
run_wizard().map_err(ApplicationError::RunWizard)?;
Expand Down Expand Up @@ -107,6 +90,25 @@ fn run_main_app() -> Result<(), ApplicationError> {
Ok(())
}

fn display_error(e: impl std::error::Error) {
use std::fmt::Write;

// Get full message.
let mut msg = e.to_string();
let mut src = e.source();

while let Some(e) = src {
write!(&mut msg, " -> {e}").unwrap();
src = e.source();
}

// Show error window.
let win = ErrorDialog::new().unwrap();

win.set_message(format!("An unexpected error has occurred: {msg}.").into());
win.run().unwrap();
}

fn setup_global_callbacks<'a, T>(component: &'a T)
where
ui::Globals<'a>: Global<'a, T>,
Expand All @@ -130,16 +132,7 @@ where
let url = url.as_str();

if let Err(e) = open::that(url) {
ui::ErrorDialog::new()
.and_then(|error_dialog| {
error_dialog.set_message(SharedString::from(format!(
"Error opening {url}: {}",
full_error_reason(e)
)));

error_dialog.show()
})
.unwrap();
// TODO: Show a modal dialog.
}
});
}
Expand Down Expand Up @@ -178,51 +171,15 @@ fn run_wizard() -> Result<(), slint::PlatformError> {
})
}

fn full_error_reason<T>(e: T) -> String
where
T: std::error::Error,
{
use std::fmt::Write;

let mut msg = format!("{e}");
let mut src = e.source();

while let Some(e) = src {
write!(&mut msg, " -> {e}").unwrap();
src = e.source();
}

msg
}

pub enum AppExit {
Ok,
Err(ApplicationError),
}

impl Termination for AppExit {
fn report(self) -> ExitCode {
match self {
AppExit::Ok => ExitCode::SUCCESS,
AppExit::Err(e) => ExitCode::FAILURE,
}
}
}

impl From<Result<(), ApplicationError>> for AppExit {
fn from(v: Result<(), ApplicationError>) -> Self {
match v {
Ok(_) => AppExit::Ok,
Err(e) => AppExit::Err(e),
}
}
}

#[derive(Debug, Error)]
pub enum ApplicationError {
enum ApplicationError {
#[error(transparent)]
ParseArgs(clap::Error),

#[cfg(unix)]
#[error("couldn't increase file descriptor limit")]
FdLimit(#[source] self::rlim::RlimitError),

#[error("failed to run wizard")]
RunWizard(#[source] slint::PlatformError),

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 98f1b5f

Please sign in to comment.