From 7ba01992a8ef57e3046dd0ce25d8f7bd4f3fb6ad Mon Sep 17 00:00:00 2001 From: MeexReay Date: Wed, 18 Jun 2025 16:44:32 +0300 Subject: [PATCH] make gtk feature --- Cargo.toml | 11 ++++++----- build.rs | 16 +++++----------- src/chat/mod.rs | 12 ++++++++++-- src/main.rs | 9 ++++++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f7764c6..a386de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ homedir = "0.3.4" native-tls = "0.2.14" clap = { version = "4.5.36", features = ["derive"] } serde = { version = "1.0.219", features = ["serde_derive"] } -gtk4 = { version = "0.9.6", features = [ "v4_10" ] } +gtk4 = { version = "0.9.6", features = [ "v4_10" ], optional = true } chrono = "0.4.40" serde_default = "0.2.0" socks = "0.3.4" @@ -22,11 +22,12 @@ gdk-pixbuf = { version = "0.3.0", optional = true } # DO NOT UPDATE winapi = { version = "0.3.9", optional = true, features = ["wincon", "winuser"] } tungstenite = "0.27.0" +[build-dependencies] +winresource = { version = "0.1.20", optional = true } + [features] default = [] +gtk = ["dep:gtk4"] libnotify = ["dep:libnotify", "dep:gdk-pixbuf"] notify-rust = ["dep:notify-rust"] -winapi = ["dep:winapi"] - -[build-dependencies] -winresource = "0.1.20" +winapi = ["dep:winapi", "dep:winresource"] diff --git a/build.rs b/build.rs index b197c4b..848c5e3 100644 --- a/build.rs +++ b/build.rs @@ -1,16 +1,10 @@ -use { - std::{ - env, - io, - }, - winresource::WindowsResource, -}; +use std::io; fn main() -> io::Result<()> { + #[cfg(feature = "winapi")] if env::var_os("CARGO_CFG_WINDOWS").is_some() { - WindowsResource::new() - .set_icon("misc/icon.ico") - .compile()?; + use {std::env, winresource::WindowsResource}; + WindowsResource::new().set_icon("misc/icon.ico").compile()?; } Ok(()) -} \ No newline at end of file +} diff --git a/src/chat/mod.rs b/src/chat/mod.rs index c828de3..bc6fa56 100644 --- a/src/chat/mod.rs +++ b/src/chat/mod.rs @@ -10,13 +10,17 @@ use super::proto::{ connect, read_messages, register_user, send_message, send_message_auth, send_message_spoof_auth, }; -use gui::{add_chat_messages, clear_chat_messages}; use lazy_static::lazy_static; use regex::Regex; use ctx::Context; +#[cfg(feature = "gtk")] +pub mod gui; +#[cfg(feature = "gtk")] pub use gui::run_main_loop; +#[cfg(feature = "gtk")] +use gui::{add_chat_messages, clear_chat_messages}; const HELP_MESSAGE: &str = "Help message: /help - show help message @@ -49,7 +53,6 @@ lazy_static! { pub mod config; pub mod ctx; -pub mod gui; pub fn sanitize_text(input: &str) -> String { let without_ansi = ANSI_REGEX.replace_all(input, ""); @@ -57,6 +60,7 @@ pub fn sanitize_text(input: &str) -> String { cleaned_text.into_owned() } +#[cfg(feature = "gtk")] pub fn add_message(ctx: Arc, message: &str) -> Result<(), Box> { for i in message.split("\n").map(|o| o.to_string()) { print_message(ctx.clone(), i)?; @@ -64,6 +68,7 @@ pub fn add_message(ctx: Arc, message: &str) -> Result<(), Box, command: &str) -> Result<(), Box> { let command = command.trim_start_matches("/"); let (command, args) = command.split_once(" ").unwrap_or((&command, "")); @@ -176,12 +181,14 @@ pub fn prepare_message(ctx: Arc, message: &str) -> String { ) } +#[cfg(feature = "gtk")] pub fn print_message(ctx: Arc, message: String) -> Result<(), Box> { ctx.add_message(ctx.config(|o| o.max_messages), vec![message.clone()]); add_chat_messages(ctx.clone(), vec![message]); Ok(()) } +#[cfg(feature = "gtk")] pub fn recv_tick(ctx: Arc) -> Result<(), Box> { let last_size = ctx.packet_size(); @@ -218,6 +225,7 @@ pub fn recv_tick(ctx: Arc) -> Result<(), Box> { Ok(()) } +#[cfg(feature = "gtk")] pub fn on_send_message(ctx: Arc, message: &str) -> Result<(), Box> { if message.starts_with("/") && ctx.config(|o| o.commands_enabled) { on_command(ctx.clone(), &message)?; diff --git a/src/main.rs b/src/main.rs index 0e2cdaf..e2071a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use bRAC::chat::{ config::{get_config_path, load_config, Args}, ctx::Context, - run_main_loop, }; use bRAC::proto::{connect, read_messages, send_message}; use clap::Parser; @@ -53,7 +52,11 @@ fn main() { return; } - let ctx = Arc::new(Context::new(&config)); + #[cfg(feature = "gtk")] + { + let ctx = Arc::new(Context::new(&config)); - run_main_loop(ctx.clone()); + use bRAC::chat::run_main_loop; + run_main_loop(ctx.clone()); + } }