fix eventloop exit

This commit is contained in:
2025-08-06 02:15:37 +02:00
parent c203bfd1bb
commit 74b62c862f
3 changed files with 20 additions and 9 deletions

1
Cargo.lock generated
View File

@@ -2281,6 +2281,7 @@ version = "0.1.0"
dependencies = [
"eframe",
"egui",
"winit",
]
[[package]]

View File

@@ -6,3 +6,4 @@ edition = "2024"
[dependencies]
eframe = "0.32.0"
egui = "0.32.0"
winit = "0.30.12"

View File

@@ -3,6 +3,8 @@ use egui::{Key, RichText};
use std::collections::VecDeque;
use egui::{FontData, FontDefinitions, FontFamily};
use std::sync::{Arc, Mutex};
use winit::event_loop::{ControlFlow, EventLoop};
use eframe::UserEvent;
const MAX_KEYS: usize = 6;
const SECRET_COMBO: [Key; MAX_KEYS] = [
@@ -98,6 +100,7 @@ impl eframe::App for AdminGateApp {
// Run admin command
*self.should_run_admin_command.lock().unwrap() = true;
ctx.send_viewport_cmd(egui::ViewportCommand::Close); // This shuts down the GUI cleanly
ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false)); // This shuts down the GUI cleanly
}
}
Key::Escape => {
@@ -144,7 +147,7 @@ fn setup_custom_fonts(ctx: &egui::Context) {
fn main() -> eframe::Result<()> {
fn main() {
let should_run_admin_command = Arc::new(Mutex::new(false));
let shared_flag = should_run_admin_command.clone();
@@ -154,18 +157,23 @@ fn main() -> eframe::Result<()> {
should_run_admin_command: shared_flag,
};
{
let options = eframe::NativeOptions::default();
let result = eframe::run_native(
"Admin Gate",
options,
Box::new(|cc| {
let eventloop = EventLoop::<UserEvent>::with_user_event().build().unwrap();
let mut winit_app = eframe::create_native("Admin Gate", options, Box::new(|cc| {
// Setup fonts
setup_custom_fonts(&cc.egui_ctx);
Ok(Box::new(app))
}),
);
}), &eventloop);
eventloop.run_app(&mut winit_app).unwrap();
}
{
// After GUI closes
if *should_run_admin_command.lock().unwrap() {
println!("✅ Running admin command...");
@@ -183,6 +191,7 @@ fn main() -> eframe::Result<()> {
}
}
}
result
}
}