Compare commits

...

9 Commits

Author SHA1 Message Date
efc202153f add gui settings 2025-06-16 07:02:10 +03:00
97948aa420 make out-of-focus update time setting 2025-06-16 06:27:58 +03:00
01b3643c14 add messages as markup label instead of many labels 2025-06-16 06:05:24 +03:00
9ef7560963 add debug logs setting 2025-06-16 04:18:11 +03:00
b206f18829 fix desktop files 2025-06-16 03:44:13 +03:00
2c35c0a18f fix images 2025-06-16 03:25:27 +03:00
89147235dc lfs 2025-06-16 03:17:03 +03:00
d390c1f28b fix makefile install 2025-06-16 02:46:08 +03:00
8c5dad7aa5 add new rules to makefile 2025-06-16 02:22:35 +03:00
16 changed files with 303 additions and 204 deletions

2
.gitattributes vendored
View File

@ -1,3 +1,3 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text

6
Cargo.lock generated
View File

@ -90,7 +90,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "bRAC"
version = "0.1.4+2.0"
version = "0.1.5+2.0"
dependencies = [
"chrono",
"clap",
@ -1494,9 +1494,9 @@ dependencies = [
[[package]]
name = "tungstenite"
version = "0.26.2"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13"
checksum = "eadc29d668c91fcc564941132e17b28a7ceb2f3ebf0b9dae3e03fd7a6748eb0d"
dependencies = [
"bytes",
"data-encoding",

View File

@ -1,15 +1,42 @@
.PHONY: clean install uninstall
.PHONY: clean install uninstall build_linux build_windows build_all
TARGETS = \
i686-unknown-linux-gnu \
i686-unknown-linux-musl \
x86_64-unknown-linux-none \
x86_64-unknown-linux-gnu \
x86_64-unknown-linux-musl \
aarch64-unknown-linux-gnu \
aarch64-unknown-linux-musl
install: target/release/bRAC
mkdir -p ~/.local
mkdir -p ~/.local/bin
mkdir -p ~/.local/share
cp $< ~/.local/bin/bRAC
chmod +x ~/.local/bin/bRAC
mkdir ~/.local/share/bRAC -p
cp misc/bRAC.png ~/.local/share/bRAC/icon.png
cp misc/bRAC.desktop ~/.local/share/applications/ru.themixray.bRAC.desktop
./misc/create-desktop.sh > ~/.local/share/applications/ru.themixray.bRAC.desktop
uninstall:
rm -rf ~/.config/bRAC ~/.local/share/bRAC
rm -f ~/.local/share/applications/ru.themixray.bRAC.desktop
target/release/bRAC:
cargo build -r
build_all: build_linux build_windows
build_linux:
mkdir -p build
mkdir -p build/linux
for target in $(TARGETS); do \
cargo build -r --target $$target; \
cp target/$$target/bRAC build/linux/$$target-bRAC; \
done
build_windows:
echo "Windows build is in development!!!"
clean:
cargo clean
cargo clean
rm -rf build

View File

@ -1,12 +0,0 @@
[Desktop Entry]
Name=bRAC
Version=0.1.4
Type=Application
Comment=better RAC client
Icon=~/.local/share/bRAC/icon.png
Exec=~/.local/bin/bRAC
Categories=Network;
StartupNotify=true
DBusActivatable=true
Terminal=false
X-GNOME-UsesNotifications=true

15
misc/create-desktop.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
version=$(grep -m1 '^version' Cargo.toml | sed -E 's/version *= *"(.*)"/\1/')
echo "[Desktop Entry]"
echo "Name=bRAC"
echo "Version=$version"
echo "Type=Application"
echo "Comment=better RAC client"
echo "Icon=$HOME/.local/share/bRAC/icon.png"
echo "Exec=$HOME/.local/bin/bRAC"
echo "Categories=Network;"
echo "StartupNotify=true"
echo "Terminal=false"
echo "X-GNOME-UsesNotifications=true"

View File

@ -27,4 +27,4 @@ set "v=%TEMP%\_s.vbs"
>>"%v%" echo l.Save
wscript "%v%" >nul
del "%v%" >nul
exit /b
exit /b

View File

@ -1,5 +1,7 @@
#!/bin/bash
echo "this script is deprecated, fix it yourself if you wanna to"; exit
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
@ -8,4 +10,4 @@ fi
cp bRAC /bin/bRAC
chmod +x /bin/bRAC
cp ru.themixray.bRAC.png /usr/share/pixmaps
cp ru.themixray.bRAC.desktop /usr/share/applications
cp ru.themixray.bRAC.desktop /usr/share/applications

View File

@ -1,5 +1,7 @@
#!/bin/bash
echo "this script is deprecated, fix it yourself if you wanna to"; exit
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
@ -11,4 +13,4 @@ done
rm -f /bin/bRAC
rm -f /usr/share/pixmaps/ru.themixray.bRAC.png
rm -f /usr/share/applications/ru.themixray.bRAC.desktop
rm -f /usr/share/applications/ru.themixray.bRAC.desktop

View File

@ -4,4 +4,4 @@ cp bRAC ~/.local/bin/bRAC
chmod +x ~/.local/bin/bRAC
mkdir ~/.local/share/bRAC -p
cp misc/bRAC.png ~/.local/share/bRAC/icon.png
cp misc/bRAC.desktop ~/.local/share/applications/ru.themixray.bRAC.desktop
./misc/create-desktop.sh > ~/.local/share/applications/ru.themixray.bRAC.desktop

View File

@ -8,7 +8,9 @@ const MESSAGE_FORMAT: &str = "\u{B9AC}\u{3E70}<{name}> {text}";
fn default_true() -> bool { true }
pub fn default_max_messages() -> usize { 200 }
pub fn default_update_time() -> usize { 50 }
pub fn default_update_time() -> usize { 100 }
pub fn default_oof_update_time() -> usize { 10000 }
pub fn default_konata_size() -> usize { 100 }
pub fn default_host() -> String { "meex.lol:11234".to_string() }
pub fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
@ -18,7 +20,10 @@ pub struct Config {
#[serde(default)] pub name: Option<String>,
#[serde(default = "default_message_format")] pub message_format: String,
#[serde(default = "default_update_time")] pub update_time: usize,
#[serde(default = "default_oof_update_time")] pub oof_update_time: usize,
#[serde(default = "default_max_messages")] pub max_messages: usize,
#[serde(default = "default_konata_size")] pub konata_size: usize,
#[serde(default)] pub remove_gui_shit: bool,
#[serde(default = "default_true")] pub hide_my_ip: bool,
#[serde(default)] pub show_other_ip: bool,
#[serde(default)] pub auth_enabled: bool,
@ -29,6 +34,7 @@ pub struct Config {
#[serde(default)] pub wrac_enabled: bool,
#[serde(default)] pub proxy: Option<String>,
#[serde(default = "default_true")] pub notifications_enabled: bool,
#[serde(default)] pub debug_logs: bool,
}
pub fn get_config_path() -> PathBuf {
@ -109,17 +115,21 @@ pub struct Args {
#[arg(short='n', long)] pub name: Option<String>,
#[arg(long)] pub message_format: Option<String>,
#[arg(long)] pub update_time: Option<usize>,
#[arg(long)] pub oof_update_time: Option<usize>,
#[arg(long)] pub max_messages: Option<usize>,
#[arg(long)] pub konata_size: Option<usize>,
#[arg(long)] pub hide_my_ip: Option<bool>,
#[arg(long)] pub show_other_ip: Option<bool>,
#[arg(long)] pub auth_enabled:Option <bool>,
#[arg(long)] pub ssl_enabled: Option<bool>,
#[arg(long)] pub remove_gui_shit: Option<bool>,
#[arg(long)] pub chunked_enabled: Option<bool>,
#[arg(long)] pub formatting_enabled: Option<bool>,
#[arg(long)] pub commands_enabled: Option<bool>,
#[arg(long)] pub notifications_enabled: Option<bool>,
#[arg(long)] pub wrac_enabled: Option<bool>,
#[arg(long)] pub proxy: Option<String>,
#[arg(long)] pub debug_logs: bool,
}
impl Args {
@ -129,9 +139,12 @@ impl Args {
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.update_time { config.update_time = v }
if let Some(v) = self.oof_update_time { config.oof_update_time = v }
if let Some(v) = self.max_messages { config.max_messages = v }
if let Some(v) = self.konata_size { config.konata_size = v }
if let Some(v) = self.hide_my_ip { config.hide_my_ip = v }
if let Some(v) = self.show_other_ip { config.show_other_ip = v }
if let Some(v) = self.remove_gui_shit { config.remove_gui_shit = v }
if let Some(v) = self.auth_enabled { config.auth_enabled = v }
if let Some(v) = self.ssl_enabled { config.ssl_enabled = v }
if let Some(v) = self.chunked_enabled { config.chunked_enabled = v }
@ -139,5 +152,6 @@ impl Args {
if let Some(v) = self.commands_enabled { config.commands_enabled = v }
if let Some(v) = self.notifications_enabled { config.notifications_enabled = v }
if let Some(v) = self.wrac_enabled { config.wrac_enabled = v }
if self.debug_logs { config.debug_logs = true }
}
}
}

View File

@ -1,4 +1,4 @@
use std::sync::{atomic::{AtomicUsize, Ordering}, mpsc::Sender, Arc, RwLock};
use std::sync::{atomic::{AtomicBool, AtomicUsize, Ordering}, mpsc::Sender, Arc, RwLock};
use rand::random;
@ -10,7 +10,8 @@ pub struct Context {
pub sender: RwLock<Option<Arc<Sender<(String, bool)>>>>,
pub messages: RwLock<Vec<String>>,
pub packet_size: AtomicUsize,
pub name: RwLock<String>
pub name: RwLock<String>,
pub is_focused: AtomicBool
}
impl Context {
@ -22,6 +23,7 @@ impl Context {
messages: RwLock::new(Vec::new()),
packet_size: AtomicUsize::default(),
name: RwLock::new(config.name.clone().unwrap_or_else(|| format!("Anon#{:X}", random::<u16>()))),
is_focused: AtomicBool::new(true)
}
}

View File

@ -1,7 +1,8 @@
use std::sync::{mpsc::{channel, Receiver}, Arc, RwLock};
use std::sync::{atomic::Ordering, mpsc::{channel, Receiver}, Arc, RwLock};
use std::cell::RefCell;
use std::time::{Duration, SystemTime};
use std::thread;
use std::error::Error;
use chrono::Local;
@ -26,12 +27,13 @@ use gtk::{
Justification, Label, ListBox, Orientation, Overlay, Picture, ScrolledWindow, Settings, Window
};
use crate::proto::parse_rac_url;
use crate::{chat::config::{default_konata_size, default_oof_update_time}, proto::parse_rac_url};
use super::{config::{default_max_messages, default_update_time, get_config_path, save_config, Config},
ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize_message, SERVER_LIST};
struct UiModel {
is_dark_theme: bool,
chat_box: GtkBox,
chat_scrolled: ScrolledWindow,
app: Application,
@ -54,11 +56,11 @@ pub fn add_chat_message(ctx: Arc<Context>, message: String) {
let _ = ctx.sender.read().unwrap().clone().unwrap().send((message, false));
}
fn load_pixbuf(data: &[u8]) -> Pixbuf {
fn load_pixbuf(data: &[u8]) -> Result<Pixbuf, Box<dyn Error>> {
let loader = PixbufLoader::new();
loader.write(data).unwrap();
loader.close().unwrap();
loader.pixbuf().unwrap()
loader.write(data)?;
loader.close()?;
Ok(loader.pixbuf().ok_or("laod pixbuf error")?)
}
macro_rules! gui_entry_setting {
@ -162,6 +164,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
let message_format_entry = gui_entry_setting!("Message Format", message_format, ctx, vbox);
let proxy_entry = gui_option_entry_setting!("Socks5 proxy", proxy, ctx, vbox);
let update_time_entry = gui_usize_entry_setting!("Update Time", update_time, ctx, vbox);
let oof_update_time_entry = gui_usize_entry_setting!("Out-of-focus Update Time", oof_update_time, ctx, vbox);
let max_messages_entry = gui_usize_entry_setting!("Max Messages", max_messages, ctx, vbox);
let hide_my_ip_entry = gui_checkbox_setting!("Hide My IP", hide_my_ip, ctx, vbox);
let show_other_ip_entry = gui_checkbox_setting!("Show Other IP", show_other_ip, ctx, vbox);
@ -172,6 +175,9 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
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 notifications_enabled_entry = gui_checkbox_setting!("Notifications Enabled", notifications_enabled, ctx, vbox);
let debug_logs_entry = gui_checkbox_setting!("Debug Logs", debug_logs, ctx, vbox);
let konata_size_entry = gui_usize_entry_setting!("Konata Size", konata_size, ctx, vbox);
let remove_gui_shit_entry = gui_checkbox_setting!("Remove Gui Shit", remove_gui_shit, ctx, vbox);
let save_button = Button::builder()
.label("Save")
@ -196,6 +202,10 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
#[weak] notifications_enabled_entry,
#[weak] wrac_enabled_entry,
#[weak] proxy_entry,
#[weak] debug_logs_entry,
#[weak] oof_update_time_entry,
#[weak] konata_size_entry,
#[weak] remove_gui_shit_entry,
move |_| {
let config = Config {
host: host_entry.text().to_string(),
@ -220,6 +230,28 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
update_time
}
},
oof_update_time: {
let oof_update_time = oof_update_time_entry.text();
if let Ok(oof_update_time) = oof_update_time.parse::<usize>() {
oof_update_time
} else {
let oof_update_time = default_oof_update_time();
oof_update_time_entry.set_text(&oof_update_time.to_string());
oof_update_time
}
},
konata_size: {
let konata_size = konata_size_entry.text();
if let Ok(konata_size) = konata_size.parse::<usize>() {
konata_size.max(0).min(200)
} else {
let konata_size = default_konata_size();
konata_size_entry.set_text(&konata_size.to_string());
konata_size
}
},
max_messages: {
let max_messages = max_messages_entry.text();
@ -232,6 +264,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
}
},
hide_my_ip: hide_my_ip_entry.is_active(),
remove_gui_shit: remove_gui_shit_entry.is_active(),
show_other_ip: show_other_ip_entry.is_active(),
auth_enabled: auth_enabled_entry.is_active(),
ssl_enabled: ssl_enabled_entry.is_active(),
@ -240,6 +273,7 @@ fn open_settings(ctx: Arc<Context>, app: &Application) {
formatting_enabled: formatting_enabled_entry.is_active(),
commands_enabled: commands_enabled_entry.is_active(),
notifications_enabled: notifications_enabled_entry.is_active(),
debug_logs: debug_logs_entry.is_active(),
proxy: {
let proxy = proxy_entry.text().to_string();
@ -361,7 +395,7 @@ fn build_menu(ctx: Arc<Context>, app: &Application) {
.activate(clone!(
#[weak] app,
move |_, _, _| {
AboutDialog::builder()
AboutDialog::builder()
.application(&app)
.authors(["TheMixRay", "MeexReay"])
.license(" DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ -380,7 +414,7 @@ fn build_menu(ctx: Arc<Context>, app: &Application) {
.comments("better RAC client")
.website("https://github.com/MeexReay/bRAC")
.website_label("source code")
.logo(&Texture::for_pixbuf(&load_pixbuf(include_bytes!("images/icon.png"))))
.logo(&Texture::for_pixbuf(&load_pixbuf(include_bytes!("images/icon.png")).unwrap()))
.build()
.present();
}
@ -390,6 +424,14 @@ fn build_menu(ctx: Arc<Context>, app: &Application) {
}
fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
let is_dark_theme = if let Some(settings) = Settings::default() {
settings.is_gtk_application_prefer_dark_theme() || settings.gtk_theme_name()
.map(|o| o.to_lowercase().contains("dark"))
.unwrap_or_default()
} else {
false
};
let main_box = GtkBox::new(Orientation::Vertical, 5);
main_box.set_css_classes(&["main-box"]);
@ -400,11 +442,15 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
widget_box.set_css_classes(&["widget_box"]);
widget_box.append(&Calendar::builder()
.css_classes(["calendar"])
.show_heading(false)
.can_target(false)
.build());
let remove_gui_shit = ctx.config(|c| c.remove_gui_shit);
if !remove_gui_shit {
widget_box.append(&Calendar::builder()
.css_classes(["calendar"])
.show_heading(false)
.can_target(false)
.build());
}
let server_list_vbox = GtkBox::new(Orientation::Vertical, 5);
@ -445,60 +491,68 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
widget_box.append(&server_list_vbox);
let fixed = Fixed::new();
fixed.set_can_target(false);
if !remove_gui_shit {
let fixed = Fixed::new();
fixed.set_can_target(false);
let konata = Picture::for_pixbuf(&load_pixbuf(include_bytes!("images/konata.png")));
konata.set_size_request(174, 127);
fixed.put(&konata, 325.0, 4.0);
let konata_size = ctx.config(|c| c.konata_size) as i32;
let logo_gif = include_bytes!("images/logo.gif");
let konata = Picture::for_pixbuf(&load_pixbuf(include_bytes!("images/konata.png")).unwrap());
konata.set_size_request(174 * konata_size / 100, 127 * konata_size / 100);
fixed.put(&konata, (499 - 174 * konata_size / 100) as f64, (131 - 127 * konata_size / 100) as f64);
let logo = Picture::for_pixbuf(&load_pixbuf(logo_gif));
logo.set_size_request(152, 64);
let logo_gif = include_bytes!("images/logo.gif");
let logo_anim = PixbufAnimation::from_stream(
&MemoryInputStream::from_bytes(
&glib::Bytes::from(logo_gif)
),
None::<&gio::Cancellable>
).unwrap().iter(Some(SystemTime::now()));
let logo = Picture::for_pixbuf(&load_pixbuf(logo_gif).unwrap());
logo.set_size_request(152 * konata_size / 100, 64 * konata_size / 100);
timeout_add_local(Duration::from_millis(30), {
let logo = logo.clone();
let logo_anim = logo_anim.clone();
let logo_anim = PixbufAnimation::from_stream(
&MemoryInputStream::from_bytes(
&glib::Bytes::from(logo_gif)
),
None::<&gio::Cancellable>
).unwrap().iter(Some(SystemTime::now()));
move || {
logo.set_pixbuf(Some(&logo_anim.pixbuf()));
logo_anim.advance(SystemTime::now());
timeout_add_local(Duration::from_millis(30), {
let logo = logo.clone();
let logo_anim = logo_anim.clone();
let ctx = ctx.clone();
ControlFlow::Continue
}
});
fixed.put(&logo, 262.0, 4.0);
move || {
if ctx.is_focused.load(Ordering::SeqCst) {
logo.set_pixbuf(Some(&logo_anim.pixbuf()));
logo_anim.advance(SystemTime::now());
}
ControlFlow::Continue
}
});
// 262, 4
fixed.put(&logo, (436 - 174 * konata_size / 100) as f64, (131 - 127 * konata_size / 100) as f64);
let time = Label::builder()
.label(&Local::now().format("%H:%M").to_string())
.justify(Justification::Right)
.css_classes(["time"])
.build();
let time = Label::builder()
.label(&Local::now().format("%H:%M").to_string())
.justify(Justification::Right)
.css_classes(["time"])
.build();
timeout_add_local(Duration::from_secs(1), {
let time = time.clone();
timeout_add_local(Duration::from_secs(1), {
let time = time.clone();
move || {
time.set_label(&Local::now().format("%H:%M").to_string());
move || {
time.set_label(&Local::now().format("%H:%M").to_string());
ControlFlow::Continue
}
});
ControlFlow::Continue
}
});
fixed.put(&time, 432.0, 4.0);
fixed.set_halign(Align::End);
fixed.put(&time, 432.0, 4.0);
fixed.set_halign(Align::End);
widget_box_overlay.add_overlay(&fixed);
widget_box_overlay.add_overlay(&fixed);
}
widget_box_overlay.set_child(Some(&widget_box));
@ -553,8 +607,10 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
));
if let Err(e) = on_send_message(ctx.clone(), &text_entry.text()) {
let msg = format!("Send message error: {}", e.to_string()).to_string();
add_chat_message(ctx.clone(), msg);
if ctx.config(|o| o.debug_logs) {
let msg = format!("Send message error: {}", e.to_string()).to_string();
add_chat_message(ctx.clone(), msg);
}
}
}
));
@ -572,8 +628,10 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
));
if let Err(e) = on_send_message(ctx.clone(), &text_entry.text()) {
let msg = format!("Send message error: {}", e.to_string()).to_string();
add_chat_message(ctx.clone(), msg);
if ctx.config(|o| o.debug_logs) {
let msg = format!("Send message error: {}", e.to_string()).to_string();
add_chat_message(ctx.clone(), msg);
}
}
}
));
@ -621,6 +679,7 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
window.present();
UiModel {
is_dark_theme,
chat_scrolled,
chat_box,
app: app.clone(),
@ -640,30 +699,31 @@ fn setup(_: &Application, ctx: Arc<Context>, ui: UiModel) {
run_recv_loop(ctx.clone());
let (tx, rx) = channel();
ui.window.connect_notify(Some("is-active"), {
let ctx = ctx.clone();
#[cfg(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() {
i.close().expect("libnotify close error");
}
}
});
}
});
move |a, _| {
let is_focused = a.is_active();
#[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);
ctx.is_focused.store(is_focused, Ordering::SeqCst);
if is_focused {
make_recv_tick(ctx.clone());
GLOBAL.with(|global| {
if let Some((ui, _)) = &*global.borrow() {
#[cfg(feature = "libnotify")]
for i in ui.notifications.read().unwrap().clone() {
i.close().expect("libnotify close error");
}
#[cfg(not(feature = "libnotify"))]
for i in ui.notifications.read().unwrap().clone() {
ui.app.withdraw_notification(&i);
}
}
}
});
});
}
}
});
@ -686,7 +746,7 @@ fn setup(_: &Application, ctx: Arc<Context>, ui: UiModel) {
}
}
let message: String = rx.recv().unwrap();
on_add_message(ctx.clone(), &ui, message);
on_add_message(ctx.clone(), &ui, message, !clear);
}
});
});
@ -695,15 +755,7 @@ fn setup(_: &Application, ctx: Arc<Context>, ui: UiModel) {
});
}
fn load_css() {
let is_dark_theme = if let Some(settings) = Settings::default() {
settings.is_gtk_application_prefer_dark_theme() || settings.gtk_theme_name()
.map(|o| o.to_lowercase().contains("dark"))
.unwrap_or_default()
} else {
false
};
fn load_css(is_dark_theme: bool) {
let provider = CssProvider::new();
provider.load_from_data(&format!(
"{}\n{}",
@ -756,105 +808,80 @@ fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str)
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, notify: bool) {
let Some(message) = sanitize_message(message) else { return; };
if message.is_empty() {
return;
}
let hbox = GtkBox::new(Orientation::Horizontal, 2);
// TODO: cache these colors maybe??
let (ip_color, date_color, text_color) = if ui.is_dark_theme {
(
"#494949",
"#929292",
"#FFFFFF"
)
} else {
(
"#585858",
"#292929",
"#000000"
)
};
let mut label = String::new();
if let Some((date, ip, content, nick)) = parse_message(message.clone()) {
if let Some(ip) = ip {
if ctx.config(|o| o.show_other_ip) {
let ip_label = Label::builder()
.label(&ip)
.margin_end(10)
.halign(Align::Start)
.valign(Align::Start)
.css_classes(["message-ip"])
.selectable(true)
.build();
hbox.append(&ip_label);
label.push_str(&format!("<span color=\"{ip_color}\">{}</span> ", glib::markup_escape_text(&ip)));
}
}
let date_label = Label::builder()
.label(format!("[{date}]"))
.halign(Align::Start)
.valign(Align::Start)
.css_classes(["message-date"])
.selectable(true)
.build();
hbox.append(&date_label);
label.push_str(&format!("<span color=\"{date_color}\">[{}]</span> ", glib::markup_escape_text(&date)));
if let Some((name, color)) = nick {
let name_label = Label::builder()
.label(format!("<{name}>"))
.halign(Align::Start)
.valign(Align::Start)
.css_classes(["message-name", &format!("message-name-{}", color)])
.selectable(true)
.build();
label.push_str(&format!("<span font_weight=\"bold\" color=\"{}\">&lt;{}&gt;</span> ", color.to_uppercase(), glib::markup_escape_text(&name)));
hbox.append(&name_label);
if !ui.window.is_active() {
if notify && !ui.window.is_active() {
if ctx.config(|o| o.chunked_enabled) {
send_notification(ctx.clone(), ui, &format!("{}'s Message", &name), &content);
// let notif = Notification::new(&format!("{}'s Message", &name));
// notif.set_body(Some(&content));
// app.send_notification(Some("user-message"), &notif);
send_notification(ctx.clone(), ui, &format!("{}'s Message", &name), &glib::markup_escape_text(&content));
}
}
} else {
if !ui.window.is_active() {
if notify && !ui.window.is_active() {
if ctx.config(|o| o.chunked_enabled) {
send_notification(ctx.clone(), ui, "System Message", &content);
// let notif = Notification::new("System Message");
// notif.set_body(Some(&content));
// app.send_notification(Some("system-message"), &notif);
}
}
}
let content_label = Label::builder()
.label(&content)
.halign(Align::Start)
.valign(Align::Start)
.css_classes(["message-content"])
.selectable(true)
.wrap(true)
.wrap_mode(WrapMode::Char)
.build();
hbox.append(&content_label);
label.push_str(&format!("<span color=\"{text_color}\">{}</span>", glib::markup_escape_text(&content)));
} else {
let content_label = Label::builder()
.label(&message)
.halign(Align::Start)
.valign(Align::Start)
.css_classes(["message-content"])
.selectable(true)
.wrap(true)
.wrap_mode(WrapMode::Char)
.build();
label.push_str(&format!("<span color=\"{text_color}\">{}</span>", glib::markup_escape_text(&message)));
hbox.append(&content_label);
if !ui.window.is_active() {
if notify && !ui.window.is_active() {
if ctx.config(|o| o.chunked_enabled) {
send_notification(ctx.clone(), ui, "Chat Message", &message);
// let notif = Notification::new("Chat Message");
// notif.set_body(Some(&message));
// app.send_notification(Some("chat-message"), &notif);
}
}
}
let hbox = GtkBox::new(Orientation::Horizontal, 2);
hbox.append(&Label::builder()
.label(&label)
.halign(Align::Start)
.valign(Align::Start)
.selectable(true)
.wrap(true)
.wrap_mode(WrapMode::WordChar)
.use_markup(true)
.build());
hbox.set_hexpand(true);
ui.chat_box.append(&hbox);
@ -868,13 +895,27 @@ fn on_add_message(ctx: Arc<Context>, ui: &UiModel, message: String) {
});
}
fn make_recv_tick(ctx: Arc<Context>) {
if let Err(e) = recv_tick(ctx.clone()) {
if ctx.config(|o| o.debug_logs) {
let _ = print_message(ctx.clone(), format!("Print messages error: {}", e.to_string()).to_string());
}
thread::sleep(Duration::from_secs(1));
}
}
fn run_recv_loop(ctx: Arc<Context>) {
thread::spawn(move || {
loop {
if let Err(e) = recv_tick(ctx.clone()) {
let _ = print_message(ctx.clone(), format!("Print messages error: {}", e.to_string()).to_string());
thread::sleep(Duration::from_secs(1));
}
make_recv_tick(ctx.clone());
thread::sleep(Duration::from_millis(
if ctx.is_focused.load(Ordering::SeqCst) {
ctx.config(|o| o.update_time) as u64
} else {
ctx.config(|o| o.oof_update_time) as u64
}
));
}
});
}
@ -895,8 +936,8 @@ pub fn run_main_loop(ctx: Arc<Context>) {
move |app| {
let ui = build_ui(ctx.clone(), app);
load_css(ui.is_dark_theme);
setup(app, ctx.clone(), ui);
load_css();
}
});
@ -914,4 +955,4 @@ pub fn run_main_loop(ctx: Arc<Context>) {
{
libnotify::uninit();
}
}
}

View File

@ -1,5 +1,5 @@
use std::{
error::Error, sync::Arc, thread, time::{Duration, SystemTime, UNIX_EPOCH}
error::Error, sync::Arc, time::{SystemTime, UNIX_EPOCH}
};
use crate::connect_rac;
@ -31,10 +31,10 @@ lazy_static! {
pub static ref IP_REGEX: Regex = Regex::new(r"\{(.*?)\} (.*)").unwrap();
pub static ref COLORED_USERNAMES: Vec<(Regex, String)> = vec![
(Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), "green".to_string()), // bRAC
(Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), "red".to_string()), // CRAB
(Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), "magenta".to_string()), // Mefidroniy
(Regex::new(r"<(.*?)> (.*)").unwrap(), "cyan".to_string()), // clRAC
(Regex::new(r"\u{B9AC}\u{3E70}<(.*?)> (.*)").unwrap(), "#70fa7a".to_string()), // bRAC
(Regex::new(r"\u{2550}\u{2550}\u{2550}<(.*?)> (.*)").unwrap(), "#fa7070".to_string()), // CRAB
(Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), "#da70fa".to_string()), // Mefidroniy
(Regex::new(r"<(.*?)> (.*)").unwrap(), "#70fadc".to_string()), // clRAC
];
pub static ref SERVER_LIST: Vec<String> = vec![
@ -215,11 +215,13 @@ pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
}
},
Err(e) => {
println!("Read messages error: {}", e.to_string())
if ctx.config(|o| o.debug_logs) {
add_chat_message(ctx.clone(), format!("Read messages error: {}", e.to_string()));
}
}
_ => {}
}
thread::sleep(Duration::from_millis(ctx.config(|o| o.update_time) as u64));
Ok(())
}
@ -295,4 +297,4 @@ pub fn find_username_color(message: &str) -> Option<(String, String, String)> {
}
}
None
}
}

View File

@ -1,3 +1,6 @@
.message-content { color:rgb(255, 255, 255); }
/* Now made with GTK Pango Markup */
/* .message-content { color:rgb(255, 255, 255); }
.message-date { color:rgb(146, 146, 146); }
.message-ip { color:rgb(73, 73, 73); }
.message-ip { color:rgb(73, 73, 73); } */

View File

@ -1,3 +1,6 @@
.message-content { color:rgb(0, 0, 0); }
/* Now made with GTK Pango Markup */
/* .message-content { color:rgb(0, 0, 0); }
.message-date { color:rgb(41, 41, 41); }
.message-ip { color:rgb(88, 88, 88); }
.message-ip { color:rgb(88, 88, 88); } */

View File

@ -1,5 +1,3 @@
.send-button, .send-text { border-radius: 0; }
.calendar {
transform: scale(0.6);
@ -16,9 +14,11 @@
font-weight: bold;
}
.message-name { font-weight: bold; }
/* Now made with GTK Pango Markup */
/* .message-name { font-weight: bold; }
.message-name-green { color: #70fa7a; }
.message-name-red { color: #fa7070; }
.message-name-magenta { color: #da70fa; }
.message-name-cyan { color: #70fadc; }
.message-name-cyan { color: #70fadc; } */