better refresh control

This commit is contained in:
WanderingPenwing 2024-07-14 11:14:05 +02:00
parent e8d6602ae1
commit c06b0a9823
4 changed files with 16 additions and 6 deletions

View file

@ -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"] } 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"} tokio = {features = ["macros"], version = "0.2"}
homedir = "0.2.1" homedir = "0.2.1"
notify-rust = "4"

View file

@ -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":[]}]} {"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":[]}]}

View file

@ -1,4 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use notify_rust::Notification;
use crate::state; use crate::state;
use crate::save_path; use crate::save_path;
@ -69,6 +70,14 @@ impl Jiji {
self.guilds[guild_index].unread = true; 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 { } else {
println!("app : message guild issue : '{}'", message.guild_id); println!("app : message guild issue : '{}'", message.guild_id);

View file

@ -3,6 +3,7 @@ use std::{sync::Arc, sync::mpsc, thread, time};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use std::sync::Mutex; use std::sync::Mutex;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration;
use homedir::get_my_home; use homedir::get_my_home;
mod bot; mod bot;
@ -14,6 +15,7 @@ mod app;
const MAX_FPS: f32 = 30.0; const MAX_FPS: f32 = 30.0;
const RUNNING_REQUEST_REFRESH_DELAY: f32 = 0.2; const RUNNING_REQUEST_REFRESH_DELAY: f32 = 0.2;
const BACKGROUND_REFRESH_DELAY: f32 = 2.0;
fn main() { fn main() {
let (bot_tx, gui_rx) = mpsc::channel::<postman::Packet>(); //tx transmiter let (bot_tx, gui_rx) = mpsc::channel::<postman::Packet>(); //tx transmiter
@ -47,7 +49,6 @@ struct Jiji {
next_frame: time::Instant, next_frame: time::Instant,
sender: mpsc::Sender<postman::Packet>, sender: mpsc::Sender<postman::Packet>,
receiver: mpsc::Receiver<postman::Packet>, receiver: mpsc::Receiver<postman::Packet>,
show_token: bool,
bot_token: String, bot_token: String,
guilds: Vec<discord_structure::Guild>, guilds: Vec<discord_structure::Guild>,
selected_guild: Option<usize>, selected_guild: Option<usize>,
@ -80,7 +81,6 @@ impl Jiji {
next_frame: time::Instant::now(), next_frame: time::Instant::now(),
sender, sender,
receiver, receiver,
show_token: false,
bot_token: app_state.bot_token.clone(), bot_token: app_state.bot_token.clone(),
guilds: vec![dms], guilds: vec![dms],
selected_guild: None, 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; 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()) { if self.pending_bot_requests > 0 {
thread::sleep(time::Duration::from_secs_f32(RUNNING_REQUEST_REFRESH_DELAY)); egui::Context::request_repaint_after(ctx, Duration::from_secs_f32(RUNNING_REQUEST_REFRESH_DELAY));
egui::Context::request_repaint(ctx);
} }
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>) { fn on_exit(&mut self, _gl: std::option::Option<&eframe::glow::Context>) {