Skip to content

Commit 4f25cfe

Browse files
committed
Copy framework_tool to framework_gui
And rename Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 73745a3 commit 4f25cfe

7 files changed

Lines changed: 126 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ resolver = "2"
77
members = [
88
# Linux and Windows tool to inspect and customize the system
99
"framework_tool",
10+
# Linux and Windows GUI tool to inspect and customize the system
11+
"framework_gui",
1012
# UEFI tool to inspect and customize the system
1113
"framework_uefi",
1214
# Catchall library that we'll probably want to split up further

framework_gui/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "framework_gui"
3+
version = "0.4.2"
4+
description = "GUI Tool to control Framework Computer systems"
5+
homepage = "https://github.com/FrameworkComputer/framework-system"
6+
repository = "https://github.com/FrameworkComputer/framework-system"
7+
readme = "README.md"
8+
license = "BSD-3-Clause"
9+
edition = "2021"
10+
11+
[[bin]]
12+
name = "framework_gui"
13+
path = "src/main.rs"
14+
15+
[dependencies.framework_lib]
16+
path = "../framework_lib"
17+
18+
[build-dependencies]
19+
# Note: Only takes effect in release builds
20+
static_vcruntime = "2.0"
21+
embed-resource = "3.0"
22+
winresource = "0.1.17"
23+
24+
[target.'cfg(windows)'.dependencies.winapi]
25+
version = "0.3.9"
26+
features = [
27+
"wincon"
28+
]

framework_gui/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
fn main() {
2+
// Add app icon
3+
if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
4+
winresource::WindowsResource::new()
5+
.set_icon("..\\res\\framework_startmenuicon.ico")
6+
.compile()
7+
.unwrap();
8+
}
9+
10+
if !cfg!(debug_assertions) {
11+
// Statically link vcruntime to allow running on clean install
12+
static_vcruntime::metabuild();
13+
14+
// Embed resources file to force running as admin
15+
embed_resource::compile("framework_gui-manifest.rc", embed_resource::NONE)
16+
.manifest_optional()
17+
.unwrap();
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define RT_MANIFEST 24
2+
1 RT_MANIFEST "framework_gui.exe.manifest"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
4+
<security>
5+
<requestedPrivileges>
6+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
7+
</requestedPrivileges>
8+
</security>
9+
</trustInfo>
10+
</assembly>

framework_gui/src/main.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use framework_lib::commandline;
2+
3+
/// Get commandline arguments
4+
fn get_args() -> Vec<String> {
5+
std::env::args().collect()
6+
}
7+
8+
fn main() -> Result<(), &'static str> {
9+
let args = get_args();
10+
11+
// If the user double-clicks (opens from explorer/desktop),
12+
// then we want to have the default behavior of showing a report of
13+
// all firmware versions.
14+
#[cfg(windows)]
15+
let (args, double_clicked) = {
16+
let double_clicked = unsafe {
17+
// See https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922
18+
let mut plist: winapi::shared::minwindef::DWORD = 0;
19+
let processes = winapi::um::wincon::GetConsoleProcessList(&mut plist, 1);
20+
21+
// If we're the only process that means we're in a fresh terminal
22+
// without CMD or powershell. This happens in some cases, for example
23+
// if the user double-clicks the app from Explorer.
24+
processes == 1
25+
};
26+
// But it also happens if launched from the commandline and a UAC prompt is necessary,
27+
// for example with sudo set to open "In a new windows", therefore we also have to
28+
// check that no commandline arguments were provided.
29+
if double_clicked && args.len() == 1 {
30+
(
31+
vec![args[0].clone(), "--versions".to_string()],
32+
double_clicked,
33+
)
34+
} else {
35+
(args, double_clicked)
36+
}
37+
};
38+
39+
let args = commandline::parse(&args);
40+
if (commandline::run_with_args(&args, false)) != 0 {
41+
return Err("Fail");
42+
}
43+
44+
// Prevent command prompt from auto closing
45+
#[cfg(windows)]
46+
if double_clicked {
47+
println!();
48+
println!("Press ENTER to exit...");
49+
let mut line = String::new();
50+
let _ = std::io::stdin().read_line(&mut line).unwrap();
51+
}
52+
53+
Ok(())
54+
}

0 commit comments

Comments
 (0)