some optimizations

This commit is contained in:
MeexReay 2025-04-21 01:18:20 +03:00
parent cc01dd1e49
commit 015d8fca59
2 changed files with 10 additions and 14 deletions

View File

@ -17,8 +17,8 @@ chrono = "0.4.40"
serde_default = "0.2.0"
socks = "0.3.4"
libnotify = { version = "1.0.3", optional = true }
gdk-pixbuf = "0.3.0"
gdk-pixbuf = { version = "0.3.0", optional = true }
[features]
default = ["libnotify"]
libnotify = ["dep:libnotify"]
libnotify = ["dep:libnotify", "dep:gdk-pixbuf"]

View File

@ -1,4 +1,4 @@
use std::{sync::{mpsc::{channel, Receiver}, Arc, RwLock}, time::UNIX_EPOCH};
use std::sync::{mpsc::{channel, Receiver}, Arc, RwLock};
use std::cell::RefCell;
use std::time::{Duration, SystemTime};
use std::thread;
@ -32,7 +32,7 @@ ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize
struct UiModel {
chat_box: GtkBox,
chat_scrolled: ScrolledWindow,
app: Application,
// app: Application,
window: ApplicationWindow,
#[cfg(feature = "libnotify")]
notifications: Arc<RwLock<Vec<libnotify::Notification>>>
@ -57,13 +57,6 @@ fn load_pixbuf(data: &[u8]) -> Pixbuf {
loader.pixbuf().unwrap()
}
fn load_gdk_pixbuf(data: &[u8]) -> gdk_pixbuf::Pixbuf {
let loader = gdk_pixbuf::PixbufLoader::new();
loader.loader_write(data).unwrap();
loader.close().unwrap();
loader.get_pixbuf().unwrap()
}
macro_rules! gui_entry_setting {
($e:expr, $i:ident, $ctx:ident, $vbox:ident) => {
{
@ -596,14 +589,14 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
UiModel {
chat_scrolled,
chat_box,
app: app.clone(),
// app: app.clone(),
window: window.clone(),
#[cfg(feature = "libnotify")]
notifications: Arc::new(RwLock::new(Vec::<libnotify::Notification>::new()))
}
}
fn setup(app: &Application, ctx: Arc<Context>, ui: UiModel) {
fn setup(_: &Application, ctx: Arc<Context>, ui: UiModel) {
let (sender, receiver) = channel();
*ctx.sender.write().unwrap() = Some(Arc::new(sender));
@ -686,7 +679,10 @@ fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str)
let notification = Notification::new(title, message, None);
notification.set_app_name("bRAC");
notification.set_image_from_pixbuf(&load_gdk_pixbuf(include_bytes!("images/icon.png")));
let pixbuf_loader = gdk_pixbuf::PixbufLoader::new();
pixbuf_loader.loader_write(include_bytes!("images/icon.png")).unwrap();
pixbuf_loader.close().unwrap();
notification.set_image_from_pixbuf(&pixbuf_loader.get_pixbuf().unwrap());
notification.show().expect("libnotify send error");
ui.notifications.write().unwrap().push(notification);