fix eventloop exit
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2281,6 +2281,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = "0.32.0"
|
eframe = "0.32.0"
|
||||||
egui = "0.32.0"
|
egui = "0.32.0"
|
||||||
|
winit = "0.30.12"
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -3,6 +3,8 @@ use egui::{Key, RichText};
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use egui::{FontData, FontDefinitions, FontFamily};
|
use egui::{FontData, FontDefinitions, FontFamily};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
|
use eframe::UserEvent;
|
||||||
|
|
||||||
const MAX_KEYS: usize = 6;
|
const MAX_KEYS: usize = 6;
|
||||||
const SECRET_COMBO: [Key; MAX_KEYS] = [
|
const SECRET_COMBO: [Key; MAX_KEYS] = [
|
||||||
@@ -98,6 +100,7 @@ impl eframe::App for AdminGateApp {
|
|||||||
// Run admin command
|
// Run admin command
|
||||||
*self.should_run_admin_command.lock().unwrap() = true;
|
*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::Close); // This shuts down the GUI cleanly
|
||||||
|
ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false)); // This shuts down the GUI cleanly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Key::Escape => {
|
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 should_run_admin_command = Arc::new(Mutex::new(false));
|
||||||
let shared_flag = should_run_admin_command.clone();
|
let shared_flag = should_run_admin_command.clone();
|
||||||
@@ -154,18 +157,23 @@ fn main() -> eframe::Result<()> {
|
|||||||
should_run_admin_command: shared_flag,
|
should_run_admin_command: shared_flag,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions::default();
|
||||||
let result = eframe::run_native(
|
let eventloop = EventLoop::<UserEvent>::with_user_event().build().unwrap();
|
||||||
"Admin Gate",
|
|
||||||
options,
|
let mut winit_app = eframe::create_native("Admin Gate", options, Box::new(|cc| {
|
||||||
Box::new(|cc| {
|
|
||||||
// Setup fonts
|
// Setup fonts
|
||||||
setup_custom_fonts(&cc.egui_ctx);
|
setup_custom_fonts(&cc.egui_ctx);
|
||||||
Ok(Box::new(app))
|
Ok(Box::new(app))
|
||||||
}),
|
}), &eventloop);
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
eventloop.run_app(&mut winit_app).unwrap();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
// After GUI closes
|
// After GUI closes
|
||||||
if *should_run_admin_command.lock().unwrap() {
|
if *should_run_admin_command.lock().unwrap() {
|
||||||
println!("✅ Running admin command...");
|
println!("✅ Running admin command...");
|
||||||
@@ -183,6 +191,7 @@ fn main() -> eframe::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user