diff --git a/Cargo.lock b/Cargo.lock index 756cbe3..3e2004e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2281,6 +2281,7 @@ version = "0.1.0" dependencies = [ "eframe", "egui", + "winit", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4b8c8bd..17c704f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2024" [dependencies] eframe = "0.32.0" egui = "0.32.0" +winit = "0.30.12" diff --git a/src/main.rs b/src/main.rs index 707bfb3..29a5902 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::::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 +} + + }