mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-06-24 10:52:58 +03:00
make gtk feature
This commit is contained in:
parent
29764b0344
commit
7ba01992a8
11
Cargo.toml
11
Cargo.toml
@ -12,7 +12,7 @@ homedir = "0.3.4"
|
|||||||
native-tls = "0.2.14"
|
native-tls = "0.2.14"
|
||||||
clap = { version = "4.5.36", features = ["derive"] }
|
clap = { version = "4.5.36", features = ["derive"] }
|
||||||
serde = { version = "1.0.219", features = ["serde_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"
|
chrono = "0.4.40"
|
||||||
serde_default = "0.2.0"
|
serde_default = "0.2.0"
|
||||||
socks = "0.3.4"
|
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"] }
|
winapi = { version = "0.3.9", optional = true, features = ["wincon", "winuser"] }
|
||||||
tungstenite = "0.27.0"
|
tungstenite = "0.27.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
winresource = { version = "0.1.20", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
gtk = ["dep:gtk4"]
|
||||||
libnotify = ["dep:libnotify", "dep:gdk-pixbuf"]
|
libnotify = ["dep:libnotify", "dep:gdk-pixbuf"]
|
||||||
notify-rust = ["dep:notify-rust"]
|
notify-rust = ["dep:notify-rust"]
|
||||||
winapi = ["dep:winapi"]
|
winapi = ["dep:winapi", "dep:winresource"]
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
winresource = "0.1.20"
|
|
||||||
|
14
build.rs
14
build.rs
@ -1,16 +1,10 @@
|
|||||||
use {
|
use std::io;
|
||||||
std::{
|
|
||||||
env,
|
|
||||||
io,
|
|
||||||
},
|
|
||||||
winresource::WindowsResource,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
|
#[cfg(feature = "winapi")]
|
||||||
if env::var_os("CARGO_CFG_WINDOWS").is_some() {
|
if env::var_os("CARGO_CFG_WINDOWS").is_some() {
|
||||||
WindowsResource::new()
|
use {std::env, winresource::WindowsResource};
|
||||||
.set_icon("misc/icon.ico")
|
WindowsResource::new().set_icon("misc/icon.ico").compile()?;
|
||||||
.compile()?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
@ -10,13 +10,17 @@ use super::proto::{
|
|||||||
connect, read_messages, register_user, send_message, send_message_auth, send_message_spoof_auth,
|
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 lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use ctx::Context;
|
use ctx::Context;
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
|
pub mod gui;
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub use gui::run_main_loop;
|
pub use gui::run_main_loop;
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
|
use gui::{add_chat_messages, clear_chat_messages};
|
||||||
|
|
||||||
const HELP_MESSAGE: &str = "Help message:
|
const HELP_MESSAGE: &str = "Help message:
|
||||||
/help - show help message
|
/help - show help message
|
||||||
@ -49,7 +53,6 @@ lazy_static! {
|
|||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod ctx;
|
pub mod ctx;
|
||||||
pub mod gui;
|
|
||||||
|
|
||||||
pub fn sanitize_text(input: &str) -> String {
|
pub fn sanitize_text(input: &str) -> String {
|
||||||
let without_ansi = ANSI_REGEX.replace_all(input, "");
|
let without_ansi = ANSI_REGEX.replace_all(input, "");
|
||||||
@ -57,6 +60,7 @@ pub fn sanitize_text(input: &str) -> String {
|
|||||||
cleaned_text.into_owned()
|
cleaned_text.into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub fn add_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
pub fn add_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
||||||
for i in message.split("\n").map(|o| o.to_string()) {
|
for i in message.split("\n").map(|o| o.to_string()) {
|
||||||
print_message(ctx.clone(), i)?;
|
print_message(ctx.clone(), i)?;
|
||||||
@ -64,6 +68,7 @@ pub fn add_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub fn on_command(ctx: Arc<Context>, command: &str) -> Result<(), Box<dyn Error>> {
|
pub fn on_command(ctx: Arc<Context>, command: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let command = command.trim_start_matches("/");
|
let command = command.trim_start_matches("/");
|
||||||
let (command, args) = command.split_once(" ").unwrap_or((&command, ""));
|
let (command, args) = command.split_once(" ").unwrap_or((&command, ""));
|
||||||
@ -176,12 +181,14 @@ pub fn prepare_message(ctx: Arc<Context>, message: &str) -> String {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub fn print_message(ctx: Arc<Context>, message: String) -> Result<(), Box<dyn Error>> {
|
pub fn print_message(ctx: Arc<Context>, message: String) -> Result<(), Box<dyn Error>> {
|
||||||
ctx.add_message(ctx.config(|o| o.max_messages), vec![message.clone()]);
|
ctx.add_message(ctx.config(|o| o.max_messages), vec![message.clone()]);
|
||||||
add_chat_messages(ctx.clone(), vec![message]);
|
add_chat_messages(ctx.clone(), vec![message]);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
||||||
let last_size = ctx.packet_size();
|
let last_size = ctx.packet_size();
|
||||||
|
|
||||||
@ -218,6 +225,7 @@ pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
pub fn on_send_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
pub fn on_send_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
||||||
if message.starts_with("/") && ctx.config(|o| o.commands_enabled) {
|
if message.starts_with("/") && ctx.config(|o| o.commands_enabled) {
|
||||||
on_command(ctx.clone(), &message)?;
|
on_command(ctx.clone(), &message)?;
|
||||||
|
@ -3,7 +3,6 @@ use std::sync::Arc;
|
|||||||
use bRAC::chat::{
|
use bRAC::chat::{
|
||||||
config::{get_config_path, load_config, Args},
|
config::{get_config_path, load_config, Args},
|
||||||
ctx::Context,
|
ctx::Context,
|
||||||
run_main_loop,
|
|
||||||
};
|
};
|
||||||
use bRAC::proto::{connect, read_messages, send_message};
|
use bRAC::proto::{connect, read_messages, send_message};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@ -53,7 +52,11 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gtk")]
|
||||||
|
{
|
||||||
let ctx = Arc::new(Context::new(&config));
|
let ctx = Arc::new(Context::new(&config));
|
||||||
|
|
||||||
|
use bRAC::chat::run_main_loop;
|
||||||
run_main_loop(ctx.clone());
|
run_main_loop(ctx.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user