don't std::process::exit
This commit is contained in:
+6
-1
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user