mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-06-24 02:42:57 +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"
|
||||
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"]
|
||||
|
14
build.rs
14
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(())
|
||||
}
|
@ -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<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
||||
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<Context>, message: &str) -> Result<(), Box<dyn Error
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gtk")]
|
||||
pub fn on_command(ctx: Arc<Context>, command: &str) -> Result<(), Box<dyn Error>> {
|
||||
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<Context>, message: &str) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gtk")]
|
||||
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()]);
|
||||
add_chat_messages(ctx.clone(), vec![message]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gtk")]
|
||||
pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
||||
let last_size = ctx.packet_size();
|
||||
|
||||
@ -218,6 +225,7 @@ pub fn recv_tick(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gtk")]
|
||||
pub fn on_send_message(ctx: Arc<Context>, message: &str) -> Result<(), Box<dyn Error>> {
|
||||
if message.starts_with("/") && ctx.config(|o| o.commands_enabled) {
|
||||
on_command(ctx.clone(), &message)?;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user