desktop files and winapi usage

This commit is contained in:
MeexReay 2025-04-21 16:47:42 +03:00
parent 015d8fca59
commit cb17464d8f
11 changed files with 82 additions and 13 deletions

12
Cargo.lock generated
View File

@ -106,6 +106,8 @@ dependencies = [
"serde_default", "serde_default",
"serde_yml", "serde_yml",
"socks", "socks",
"winapi",
"winresource",
] ]
[[package]] [[package]]
@ -1647,6 +1649,16 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winresource"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4a67c78ee5782c0c1cb41bebc7e12c6e79644daa1650ebbc1de5d5b08593f7"
dependencies = [
"toml",
"version_check",
]
[[package]] [[package]]
name = "wit-bindgen-rt" name = "wit-bindgen-rt"
version = "0.33.0" version = "0.33.0"

View File

@ -18,7 +18,12 @@ serde_default = "0.2.0"
socks = "0.3.4" socks = "0.3.4"
libnotify = { version = "1.0.3", optional = true } libnotify = { version = "1.0.3", optional = true }
gdk-pixbuf = { version = "0.3.0", optional = true } gdk-pixbuf = { version = "0.3.0", optional = true }
winapi = { version = "0.3.9", optional = true, features = ["wincon", "winuser"] }
[features] [features]
default = ["libnotify"] default = []
libnotify = ["dep:libnotify", "dep:gdk-pixbuf"] libnotify = ["dep:libnotify", "dep:gdk-pixbuf"]
winapi = ["dep:winapi"]
[build-dependencies]
winresource = "0.1.20"

View File

@ -5,7 +5,7 @@ build: build/windows-x86_64 build/linux-x86_64
build/windows-x86_64: build/windows-x86_64:
mkdir -p build mkdir -p build
mkdir -p $@ mkdir -p $@
cargo build -r --target x86_64-pc-windows-gnu cargo build -r -F winapi --target x86_64-pc-windows-gnu
curl -s https://api.github.com/repos/wingtk/gvsbuild/releases/latest \ curl -s https://api.github.com/repos/wingtk/gvsbuild/releases/latest \
| grep -o ".*browser_download_url.*GTK4_Gvsbuild.*_x64.zip.*" \ | grep -o ".*browser_download_url.*GTK4_Gvsbuild.*_x64.zip.*" \
| cut -d : -f 2,3 \ | cut -d : -f 2,3 \
@ -16,17 +16,17 @@ build/windows-x86_64:
mv $@/bin/* $@/ mv $@/bin/* $@/
cp target/x86_64-pc-windows-gnu/release/bRAC.exe $@ cp target/x86_64-pc-windows-gnu/release/bRAC.exe $@
rm -r $@/bin rm -r $@/bin
# TODO: disable console
# TODO: set icon
build/linux-x86_64: build/linux-x86_64:
mkdir -p build mkdir -p build
mkdir -p $@ mkdir -p $@
cargo build -r --target x86_64-unknown-linux-gnu cargo build -r -F libnotify --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 bRAC.png $@ cp ru.themixray.bRAC.png $@
cp bRAC.desktop $@ cp ru.themixray.bRAC.desktop $@
cp install.sh $@
cp uninstall.sh $@
clean: clean:
rm -r build rm -r build

16
build.rs Normal file
View File

@ -0,0 +1,16 @@
use {
std::{
env,
io,
},
winresource::WindowsResource,
};
fn main() -> io::Result<()> {
if env::var_os("CARGO_CFG_WINDOWS").is_some() {
WindowsResource::new()
.set_icon("icon.ico")
.compile()?;
}
Ok(())
}

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

20
install.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
if [ ! -f bRAC ]; then
if cargo build -r; then
cp target/release/bRAC .
else
echo "There is no bRAC binary"
exit 1
fi
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

View File

@ -3,7 +3,7 @@ Name=bRAC
Version=0.1.4 Version=0.1.4
Type=Application Type=Application
Comment=better RAC client Comment=better RAC client
Icon=bRAC.png Icon=ru.themixray.bRAC.png
Exec=bRAC Exec=bRAC
Categories=Network; Categories=Network;
StartupNotify=true StartupNotify=true

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -32,7 +32,7 @@ ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize
struct UiModel { struct UiModel {
chat_box: GtkBox, chat_box: GtkBox,
chat_scrolled: ScrolledWindow, chat_scrolled: ScrolledWindow,
// 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>>>
@ -589,7 +589,7 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
UiModel { UiModel {
chat_scrolled, chat_scrolled,
chat_box, chat_box,
// 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()))
@ -689,7 +689,7 @@ fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str)
} }
#[cfg(not(feature = "libnotify"))] #[cfg(not(feature = "libnotify"))]
fn send_notification(ctx: Arc<Context>, ui: &UiModel, title: &str, message: &str) { fn send_notification(_: Arc<Context>, ui: &UiModel, title: &str, message: &str) {
use gtk4::gio::Notification; use gtk4::gio::Notification;
let notif = Notification::new(title); let notif = Notification::new(title);

View File

@ -2,10 +2,12 @@ use std::sync::Arc;
use bRAC::proto::{connect, read_messages, send_message}; use bRAC::proto::{connect, read_messages, send_message};
use bRAC::chat::{config::{get_config_path, load_config, Args}, ctx::Context, run_main_loop}; use bRAC::chat::{config::{get_config_path, load_config, Args}, ctx::Context, run_main_loop};
use clap::Parser; use clap::Parser;
fn main() { fn main() {
#[cfg(feature = "winapi")]
unsafe { winapi::um::wincon::FreeConsole() };
let args = Args::parse(); let args = Args::parse();
let config_path = get_config_path(); let config_path = get_config_path();

14
uninstall.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
getent passwd | while IFS=: read -r name password uid gid gecos home shell; do
rm -rf $home/.config/bRAC;
done
rm -f /bin/bRAC
rm -f ru.themixray.bRAC.png /usr/share/pixmaps
rm -f ru.themixray.bRAC.desktop /usr/share/applications