From c06b0a9823724929d17d2cb68a12b7934c26c81e Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Sun, 14 Jul 2024 11:14:05 +0200 Subject: [PATCH] better refresh control --- Cargo.toml | 1 + jiji.project | 2 +- src/app.rs | 9 +++++++++ src/main.rs | 10 +++++----- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e7f625..1817c80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ chrono = "0.4" serenity = { version = "0.9.0-rc.2", default-features = false, features = ["client", "gateway", "model", "builder", "rustls_backend", "cache", "http"] } tokio = {features = ["macros"], version = "0.2"} homedir = "0.2.1" +notify-rust = "4" diff --git a/jiji.project b/jiji.project index 20edb60..851be80 100644 --- a/jiji.project +++ b/jiji.project @@ -1 +1 @@ -{"categories":[{"name":"to do","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1},{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[{"name":"better ui error display","description":"handle the error packet for better display","id":1},{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"+","content":[]}]} \ No newline at end of file +{"categories":[{"name":"to do","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1},{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1},{"name":"better ui error display","description":"handle the error packet for better display","id":1}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"+","content":[]}]} \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index b241453..e337a09 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use notify_rust::Notification; use crate::state; use crate::save_path; @@ -69,6 +70,14 @@ impl Jiji { self.guilds[guild_index].unread = true; } + if self.guilds[guild_index].channels[channel_index].notify && message.new != "" { + let _ = Notification::new() + .summary(&message.author_name) + .body(&format!("{} - {}", self.guilds[guild_index].name, self.guilds[guild_index].channels[channel_index].name)) + .timeout(0) + .show(); + } + } else { println!("app : message guild issue : '{}'", message.guild_id); diff --git a/src/main.rs b/src/main.rs index 85b8b1d..34a0349 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::{sync::Arc, sync::mpsc, thread, time}; use tokio::runtime::Runtime; use std::sync::Mutex; use std::path::PathBuf; +use std::time::Duration; use homedir::get_my_home; mod bot; @@ -14,6 +15,7 @@ mod app; const MAX_FPS: f32 = 30.0; const RUNNING_REQUEST_REFRESH_DELAY: f32 = 0.2; +const BACKGROUND_REFRESH_DELAY: f32 = 2.0; fn main() { let (bot_tx, gui_rx) = mpsc::channel::(); //tx transmiter @@ -47,7 +49,6 @@ struct Jiji { next_frame: time::Instant, sender: mpsc::Sender, receiver: mpsc::Receiver, - show_token: bool, bot_token: String, guilds: Vec, selected_guild: Option, @@ -80,7 +81,6 @@ impl Jiji { next_frame: time::Instant::now(), sender, receiver, - show_token: false, bot_token: app_state.bot_token.clone(), guilds: vec![dms], selected_guild: None, @@ -111,10 +111,10 @@ impl eframe::App for Jiji { self.time_watch = self.next_frame.elapsed().as_micros() as f32 / 1000.0; - if self.pending_bot_requests > 0 && !ctx.input(|i| i.wants_repaint()) { - thread::sleep(time::Duration::from_secs_f32(RUNNING_REQUEST_REFRESH_DELAY)); - egui::Context::request_repaint(ctx); + if self.pending_bot_requests > 0 { + egui::Context::request_repaint_after(ctx, Duration::from_secs_f32(RUNNING_REQUEST_REFRESH_DELAY)); } + egui::Context::request_repaint_after(ctx, Duration::from_secs_f32(BACKGROUND_REFRESH_DELAY)); } fn on_exit(&mut self, _gl: std::option::Option<&eframe::glow::Context>) {