not much progress, but refactored
This commit is contained in:
parent
2317a41bba
commit
8988bbd180
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
eframe = "0.26.2"
|
||||
futures = "0.3.30"
|
||||
image = "0.24.9"
|
||||
tokio = { version = "0.2", features = ["macros"] }
|
||||
serenity = { default-features = false, features = ["client", "gateway", "model", "rustls_backend"], version = "0.9.0-rc.2"}
|
||||
tokio = {features = ["macros"], version = "0.2"}
|
||||
|
|
11
src/bot.rs
11
src/bot.rs
|
@ -27,18 +27,21 @@ impl EventHandler for Handler {
|
|||
}
|
||||
|
||||
pub async fn start_discord_bot() {
|
||||
println!("Creation process started");
|
||||
let maybe_client = Client::builder(token::TOKEN)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.map_err(|why| format!("Client error: {:?}", why));
|
||||
|
||||
println!("Got a result");
|
||||
|
||||
if let Ok(mut client) = maybe_client {
|
||||
if let Err(why) = client.start().await {
|
||||
eprintln!("Client error: {:?}", why);
|
||||
return
|
||||
println!("Client error: {:?}", why);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
eprintln!("No Client");
|
||||
return
|
||||
println!("No Client");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -1,11 +1,29 @@
|
|||
use eframe::egui;
|
||||
use image::GenericImageView;
|
||||
use std::{error::Error, sync::Arc, thread, time};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
mod bot;
|
||||
|
||||
const MAX_FPS: f32 = 30.0;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
fn main() {
|
||||
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;
|
||||
});
|
||||
|
||||
// Run the GUI on the main thread
|
||||
gui();
|
||||
}
|
||||
|
||||
fn gui() {
|
||||
let icon_data = load_icon().unwrap_or_default();
|
||||
|
||||
let options = eframe::NativeOptions {
|
||||
|
@ -15,25 +33,17 @@ fn main() -> Result<(), eframe::Error> {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
eframe::run_native(
|
||||
"Jiji",
|
||||
options,
|
||||
Box::new(move |_cc| Box::from(Jiji::default())),
|
||||
)
|
||||
let _ = eframe::run_native("Jiji", options, Box::new(move |_cc| Box::from(Jiji::new())));
|
||||
}
|
||||
|
||||
struct Jiji {
|
||||
next_frame: time::Instant,
|
||||
bot: thread::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Default for Jiji {
|
||||
fn default() -> Self {
|
||||
impl Jiji {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
next_frame: time::Instant::now(),
|
||||
bot: thread::spawn(|| {
|
||||
bot::start_discord_bot();
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +57,10 @@ impl eframe::App for Jiji {
|
|||
|
||||
self.draw_feed(ctx);
|
||||
}
|
||||
|
||||
fn on_exit(&mut self, _gl: std::option::Option<&eframe::glow::Context>) {
|
||||
//self.runtime.shutdown_background();
|
||||
}
|
||||
}
|
||||
|
||||
impl Jiji {
|
||||
|
@ -55,7 +69,6 @@ impl Jiji {
|
|||
ui.label("Hello there");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn load_icon() -> Result<egui::IconData, Box<dyn Error>> {
|
||||
|
|
Loading…
Reference in a new issue