From f8ec903a2c2211b3c066fd2798effcbda6bf147f Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Fri, 8 Mar 2024 08:11:28 +0100 Subject: [PATCH] parralellllll start --- src/main.rs | 99 ++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/src/main.rs b/src/main.rs index 639fe3a..944c623 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,81 +8,78 @@ mod bot; const MAX_FPS: f32 = 30.0; fn main() { - println!("hello there"); + println!("hello there"); - // Create a separate Tokio runtime for the bot - let bot_runtime = Runtime::new().unwrap(); - let bot_handle = bot_runtime.handle().clone(); - - // Spawn the bot task onto the separate runtime - bot_handle.spawn(async move { - bot::start_discord_bot().await; + let handle = thread::spawn(|| { + println!("general kenobi"); + let mut rt = Runtime::new().unwrap(); + rt.block_on(bot::start_discord_bot()); }); - // Run the GUI on the main thread - gui(); + // Run the GUI on the main thread + gui(); } fn gui() { - let icon_data = load_icon().unwrap_or_default(); + let icon_data = load_icon().unwrap_or_default(); - let options = eframe::NativeOptions { - viewport: egui::ViewportBuilder::default() - .with_inner_size([1200.0, 800.0]) - .with_icon(Arc::new(icon_data)), - ..Default::default() - }; + let options = eframe::NativeOptions { + viewport: egui::ViewportBuilder::default() + .with_inner_size([1200.0, 800.0]) + .with_icon(Arc::new(icon_data)), + ..Default::default() + }; - let _ = eframe::run_native("Jiji", options, Box::new(move |_cc| Box::from(Jiji::new()))); + let _ = eframe::run_native("Jiji", options, Box::new(move |_cc| Box::from(Jiji::new()))); } struct Jiji { - next_frame: time::Instant, + next_frame: time::Instant, } impl Jiji { - fn new() -> Self { - Self { - next_frame: time::Instant::now(), - } - } + fn new() -> Self { + Self { + next_frame: time::Instant::now(), + } + } } impl eframe::App for Jiji { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - thread::sleep(time::Duration::from_secs_f32( - ((1.0 / MAX_FPS) - self.next_frame.elapsed().as_secs_f32()).max(0.0), - )); - self.next_frame = time::Instant::now(); + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + thread::sleep(time::Duration::from_secs_f32( + ((1.0 / MAX_FPS) - self.next_frame.elapsed().as_secs_f32()).max(0.0), + )); + self.next_frame = time::Instant::now(); - self.draw_feed(ctx); - } + self.draw_feed(ctx); + } - fn on_exit(&mut self, _gl: std::option::Option<&eframe::glow::Context>) { - //self.runtime.shutdown_background(); - } + fn on_exit(&mut self, _gl: std::option::Option<&eframe::glow::Context>) { + //self.runtime.shutdown_background(); + } } impl Jiji { - pub fn draw_feed(&mut self, ctx: &egui::Context) { - egui::CentralPanel::default().show(ctx, |ui| { - ui.label("Hello there"); - }); - } + pub fn draw_feed(&mut self, ctx: &egui::Context) { + egui::CentralPanel::default().show(ctx, |ui| { + ui.label("Hello there"); + }); + } } pub fn load_icon() -> Result> { - let (icon_rgba, icon_width, icon_height) = { - let icon = include_bytes!("../assets/icon.png"); - let image = image::load_from_memory(icon)?; - let rgba = image.clone().into_rgba8().to_vec(); - let (width, height) = image.dimensions(); - (rgba, width, height) - }; + let (icon_rgba, icon_width, icon_height) = { + let icon = include_bytes!("../assets/icon.png"); + let image = image::load_from_memory(icon)?; + let rgba = image.clone().into_rgba8().to_vec(); + let (width, height) = image.dimensions(); + (rgba, width, height) + }; - Ok(egui::IconData { - rgba: icon_rgba, - width: icon_width, - height: icon_height, - }) + Ok(egui::IconData { + rgba: icon_rgba, + width: icon_width, + height: icon_height, + }) }