mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
notifications setting and now all gnotifications hide
This commit is contained in:
parent
cb17464d8f
commit
e55d5a7a55
6
Makefile
6
Makefile
@ -1,6 +1,8 @@
|
|||||||
.PHONY: clean build
|
.PHONY: clean build windows build
|
||||||
|
|
||||||
build: build/windows-x86_64 build/linux-x86_64
|
build: build/windows-x86_64 build/linux-x86_64
|
||||||
|
windows: build/windows-x86_64
|
||||||
|
linux: build/linux-x86_64
|
||||||
|
|
||||||
build/windows-x86_64:
|
build/windows-x86_64:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
@ -20,7 +22,7 @@ build/windows-x86_64:
|
|||||||
build/linux-x86_64:
|
build/linux-x86_64:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
cargo build -r -F libnotify --target x86_64-unknown-linux-gnu
|
cargo build -r --target x86_64-unknown-linux-gnu
|
||||||
# patchbin target/x86_64-unknown-linux-gnu/release/bRAC
|
# patchbin target/x86_64-unknown-linux-gnu/release/bRAC
|
||||||
cp target/x86_64-unknown-linux-gnu/release/bRAC $@
|
cp target/x86_64-unknown-linux-gnu/release/bRAC $@
|
||||||
cp ru.themixray.bRAC.png $@
|
cp ru.themixray.bRAC.png $@
|
||||||
|
@ -27,6 +27,7 @@ pub struct Config {
|
|||||||
#[serde(default = "default_true")] pub formatting_enabled: bool,
|
#[serde(default = "default_true")] pub formatting_enabled: bool,
|
||||||
#[serde(default = "default_true")] pub commands_enabled: bool,
|
#[serde(default = "default_true")] pub commands_enabled: bool,
|
||||||
#[serde(default)] pub proxy: Option<String>,
|
#[serde(default)] pub proxy: Option<String>,
|
||||||
|
#[serde(default = "default_true")] pub notifications_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_config_path() -> PathBuf {
|
pub fn get_config_path() -> PathBuf {
|
||||||
@ -115,6 +116,7 @@ pub struct Args {
|
|||||||
#[arg(long)] pub chunked_enabled: Option<bool>,
|
#[arg(long)] pub chunked_enabled: Option<bool>,
|
||||||
#[arg(long)] pub formatting_enabled: Option<bool>,
|
#[arg(long)] pub formatting_enabled: Option<bool>,
|
||||||
#[arg(long)] pub commands_enabled: Option<bool>,
|
#[arg(long)] pub commands_enabled: Option<bool>,
|
||||||
|
#[arg(long)] pub notifications_enabled: Option<bool>,
|
||||||
#[arg(long)] pub proxy: Option<String>,
|
#[arg(long)] pub proxy: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,14 +126,15 @@ impl Args {
|
|||||||
if let Some(v) = self.name.clone() { config.name = Some(v) }
|
if let Some(v) = self.name.clone() { config.name = Some(v) }
|
||||||
if let Some(v) = self.proxy.clone() { config.proxy = Some(v) }
|
if let Some(v) = self.proxy.clone() { config.proxy = Some(v) }
|
||||||
if let Some(v) = self.message_format.clone() { config.message_format = v }
|
if let Some(v) = self.message_format.clone() { config.message_format = v }
|
||||||
if let Some(v) = self.update_time.clone() { config.update_time = v }
|
if let Some(v) = self.update_time { config.update_time = v }
|
||||||
if let Some(v) = self.max_messages.clone() { config.max_messages = v }
|
if let Some(v) = self.max_messages { config.max_messages = v }
|
||||||
if let Some(v) = self.hide_my_ip.clone() { config.hide_my_ip = v }
|
if let Some(v) = self.hide_my_ip { config.hide_my_ip = v }
|
||||||
if let Some(v) = self.show_other_ip.clone() { config.show_other_ip = v }
|
if let Some(v) = self.show_other_ip { config.show_other_ip = v }
|
||||||
if let Some(v) = self.auth_enabled.clone() { config.auth_enabled = v }
|
if let Some(v) = self.auth_enabled { config.auth_enabled = v }
|
||||||
if let Some(v) = self.ssl_enabled.clone() { config.ssl_enabled = v }
|
if let Some(v) = self.ssl_enabled { config.ssl_enabled = v }
|
||||||
if let Some(v) = self.chunked_enabled.clone() { config.chunked_enabled = v }
|
if let Some(v) = self.chunked_enabled { config.chunked_enabled = v }
|
||||||
if let Some(v) = self.formatting_enabled.clone() { config.formatting_enabled = v }
|
if let Some(v) = self.formatting_enabled { config.formatting_enabled = v }
|
||||||
if let Some(v) = self.commands_enabled.clone() { config.commands_enabled = v }
|
if let Some(v) = self.commands_enabled { config.commands_enabled = v }
|
||||||
|
if let Some(v) = self.notifications_enabled { config.notifications_enabled = v }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,7 +35,9 @@ struct UiModel {
|
|||||||
app: Application,
|
app: Application,
|
||||||
window: ApplicationWindow,
|
window: ApplicationWindow,
|
||||||
#[cfg(feature = "libnotify")]
|
#[cfg(feature = "libnotify")]
|
||||||
notifications: Arc<RwLock<Vec<libnotify::Notification>>>
|
notifications: Arc<RwLock<Vec<libnotify::Notification>>>,
|
||||||
|
#[cfg(not(feature = "libnotify"))]
|
||||||
|
notifications: Arc<RwLock<Vec<String>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local!(
|
thread_local!(
|
||||||
@ -166,6 +168,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
let chunked_enabled_entry = gui_checkbox_setting!("Chunked Enabled", chunked_enabled, ctx, vbox);
|
let chunked_enabled_entry = gui_checkbox_setting!("Chunked Enabled", chunked_enabled, ctx, vbox);
|
||||||
let formatting_enabled_entry = gui_checkbox_setting!("Formatting Enabled", formatting_enabled, ctx, vbox);
|
let formatting_enabled_entry = gui_checkbox_setting!("Formatting Enabled", formatting_enabled, ctx, vbox);
|
||||||
let commands_enabled_entry = gui_checkbox_setting!("Commands Enabled", commands_enabled, ctx, vbox);
|
let commands_enabled_entry = gui_checkbox_setting!("Commands Enabled", commands_enabled, ctx, vbox);
|
||||||
|
let notifications_enabled_entry = gui_checkbox_setting!("Notifications Enabled", notifications_enabled, ctx, vbox);
|
||||||
|
|
||||||
let save_button = Button::builder()
|
let save_button = Button::builder()
|
||||||
.label("Save")
|
.label("Save")
|
||||||
@ -187,6 +190,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
#[weak] chunked_enabled_entry,
|
#[weak] chunked_enabled_entry,
|
||||||
#[weak] formatting_enabled_entry,
|
#[weak] formatting_enabled_entry,
|
||||||
#[weak] commands_enabled_entry,
|
#[weak] commands_enabled_entry,
|
||||||
|
#[weak] notifications_enabled_entry,
|
||||||
#[weak] proxy_entry,
|
#[weak] proxy_entry,
|
||||||
move |_| {
|
move |_| {
|
||||||
let config = Config {
|
let config = Config {
|
||||||
@ -230,6 +234,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
chunked_enabled: chunked_enabled_entry.is_active(),
|
chunked_enabled: chunked_enabled_entry.is_active(),
|
||||||
formatting_enabled: formatting_enabled_entry.is_active(),
|
formatting_enabled: formatting_enabled_entry.is_active(),
|
||||||
commands_enabled: commands_enabled_entry.is_active(),
|
commands_enabled: commands_enabled_entry.is_active(),
|
||||||
|
notifications_enabled: notifications_enabled_entry.is_active(),
|
||||||
proxy: {
|
proxy: {
|
||||||
let proxy = proxy_entry.text().to_string();
|
let proxy = proxy_entry.text().to_string();
|
||||||
|
|
||||||
@ -265,6 +270,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
#[weak] chunked_enabled_entry,
|
#[weak] chunked_enabled_entry,
|
||||||
#[weak] formatting_enabled_entry,
|
#[weak] formatting_enabled_entry,
|
||||||
#[weak] commands_enabled_entry,
|
#[weak] commands_enabled_entry,
|
||||||
|
#[weak] notifications_enabled_entry,
|
||||||
#[weak] proxy_entry,
|
#[weak] proxy_entry,
|
||||||
move |_| {
|
move |_| {
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
@ -283,6 +289,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
chunked_enabled_entry.set_active(config.chunked_enabled);
|
chunked_enabled_entry.set_active(config.chunked_enabled);
|
||||||
formatting_enabled_entry.set_active(config.formatting_enabled);
|
formatting_enabled_entry.set_active(config.formatting_enabled);
|
||||||
commands_enabled_entry.set_active(config.commands_enabled);
|
commands_enabled_entry.set_active(config.commands_enabled);
|
||||||
|
notifications_enabled_entry.set_active(config.notifications_enabled);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -295,6 +302,22 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
|
|||||||
.child(&vbox)
|
.child(&vbox)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
let controller = gtk::EventControllerKey::new();
|
||||||
|
controller.connect_key_pressed({
|
||||||
|
let window = window.clone();
|
||||||
|
|
||||||
|
move |_, key, _, _| {
|
||||||
|
if key == gtk::gdk::Key::Escape {
|
||||||
|
window.close();
|
||||||
|
gtk::glib::Propagation::Proceed
|
||||||
|
} else {
|
||||||
|
gtk::glib::Propagation::Stop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.add_controller(controller);
|
||||||
|
|
||||||
window.present();
|
window.present();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,7 +615,9 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
app: app.clone(),
|
app: app.clone(),
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
#[cfg(feature = "libnotify")]
|
#[cfg(feature = "libnotify")]
|
||||||
notifications: Arc::new(RwLock::new(Vec::<libnotify::Notification>::new()))
|
notifications: Arc::new(RwLock::new(Vec::<libnotify::Notification>::new())),
|
||||||
|
#[cfg(not(feature = "libnotify"))]
|
||||||
|
notifications: Arc::new(RwLock::new(Vec::<String>::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,6 +643,19 @@ fn setup(_: &Application, ctx: Arc<Context>, ui: UiModel) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(not(feature = "libnotify"))]
|
||||||
|
ui.window.connect_notify(Some("is-active"), move |a, _| {
|
||||||
|
if a.is_active() {
|
||||||
|
GLOBAL.with(|global| {
|
||||||
|
if let Some((ui, _)) = &*global.borrow() {
|
||||||
|
for i in ui.notifications.read().unwrap().clone() {
|
||||||
|
ui.app.withdraw_notification(&i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
GLOBAL.with(|global| {
|
GLOBAL.with(|global| {
|
||||||
*global.borrow_mut() = Some((ui, rx));
|
*global.borrow_mut() = Some((ui, rx));
|
||||||
});
|
});
|
||||||
@ -690,11 +728,21 @@ fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str)
|
|||||||
|
|
||||||
#[cfg(not(feature = "libnotify"))]
|
#[cfg(not(feature = "libnotify"))]
|
||||||
fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str) {
|
fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str) {
|
||||||
|
use std::{hash::{DefaultHasher, Hasher}, time::UNIX_EPOCH};
|
||||||
|
|
||||||
use gtk4::gio::Notification;
|
use gtk4::gio::Notification;
|
||||||
|
|
||||||
|
let mut hash = DefaultHasher::new();
|
||||||
|
hash.write(title.as_bytes());
|
||||||
|
hash.write(message.as_bytes());
|
||||||
|
|
||||||
|
let id = format!("bRAC-{}-{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), hash.finish());
|
||||||
|
|
||||||
let notif = Notification::new(title);
|
let notif = Notification::new(title);
|
||||||
notif.set_body(Some(&message));
|
notif.set_body(Some(&message));
|
||||||
ui.app.send_notification(None, ¬if);
|
ui.app.send_notification(Some(&id), ¬if);
|
||||||
|
|
||||||
|
ui.notifications.write().unwrap().push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_add_message(ctx: Arc<Context>, ui: &UiModel, message: String) {
|
fn on_add_message(ctx: Arc<Context>, ui: &UiModel, message: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user