don't std::process::exit

This commit is contained in:
2025-04-08 09:02:16 +01:00
parent 807cb5242f
commit 99b6519ffb
2 changed files with 8 additions and 3 deletions
+6 -1
View File
@@ -47,6 +47,7 @@ pub enum Stage {
#[derive(Debug)] #[derive(Debug)]
pub struct App { pub struct App {
stage: Stage, stage: Stage,
closing: bool,
debug: bool, debug: bool,
initialized: bool, initialized: bool,
elevated: bool, elevated: bool,
@@ -63,6 +64,7 @@ impl Default for App {
fn default() -> Self { fn default() -> Self {
Self { Self {
stage: Stage::default(), stage: Stage::default(),
closing: false,
initialized: false, initialized: false,
debug: false, debug: false,
elevated: elevation::is_elevated(), elevated: elevation::is_elevated(),
@@ -100,7 +102,7 @@ impl eframe::App for App {
.on_hover_text("Relaunch ourselves as administrator.") .on_hover_text("Relaunch ourselves as administrator.")
.on_disabled_hover_text("We are already running elevated."); .on_disabled_hover_text("We are already running elevated.");
if button.clicked() { if button.clicked() {
elevation::elevate(); elevation::elevate(&mut self.closing);
} }
}); });
}); });
@@ -155,6 +157,9 @@ impl eframe::App for App {
) )
} }
ctx.request_repaint_after(Duration::from_millis(100)); ctx.request_repaint_after(Duration::from_millis(100));
if self.closing {
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
}
} }
} }
+2 -2
View File
@@ -6,7 +6,7 @@ use windows::{
core::{HSTRING, PCWSTR}, core::{HSTRING, PCWSTR},
}; };
pub fn elevate() { pub fn elevate(closing: &mut bool) {
let exe = std::env::current_exe().unwrap(); let exe = std::env::current_exe().unwrap();
unsafe { unsafe {
ShellExecuteW( ShellExecuteW(
@@ -18,7 +18,7 @@ pub fn elevate() {
SW_HIDE, SW_HIDE,
); );
} }
std::process::exit(0); *closing = true;
} }
pub fn is_elevated() -> bool { pub fn is_elevated() -> bool {