From f93e96397207ff63a941d11a4e04717da22cdeb0 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Sun, 6 Jul 2025 05:57:23 +0300 Subject: [PATCH] refactor: windows dark mode + refactor build.sh --- .gitignore | 3 +- Cross.toml | 2 - misc/build.sh | 84 ++++++++++------- misc/mslink.sh | 243 ------------------------------------------------ src/chat/gui.rs | 9 ++ 5 files changed, 59 insertions(+), 282 deletions(-) delete mode 100644 Cross.toml delete mode 100755 misc/mslink.sh diff --git a/.gitignore b/.gitignore index ef3caa1..82a169a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /build/ /config.yml /bRAC -/.direnv/ \ No newline at end of file +/.direnv/ +/misc/mslink.sh diff --git a/Cross.toml b/Cross.toml deleted file mode 100644 index 6d92278..0000000 --- a/Cross.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.x86_64-pc-windows-gnu] -image = "mglolenstine/gtk4-cross:rust-gtk-latest" \ No newline at end of file diff --git a/misc/build.sh b/misc/build.sh index df79f98..9a3441d 100755 --- a/misc/build.sh +++ b/misc/build.sh @@ -1,58 +1,70 @@ #!/bin/bash -echo "Run this script only from repository root!" -echo "This script depends on:" -echo " - fact that you are on linux x86_64!" -echo " - zip, unzip, curl. install it with your distro's package manager" -echo " - cross crate. to install it, run this: cargo install cross --git https://github.com/cross-rs/cross" -echo " - docker, so you should run something like this on your distro: sudo systemctl start docker" -read -p "Press enter if you really want to do rm -rf build/" - -rm -rf build -mkdir build +# echo "Run this script only from repository root!" +# echo "This script depends on:" +# echo " - fact that you are on linux x86_64!" +# echo " - zip, unzip, curl. install it with your distro's package manager" +# echo " - cross crate. to install it, run this: cargo install cross --git https://github.com/cross-rs/cross" +# echo " - docker, so you should run something like this on your distro: sudo systemctl start docker" +# read -p "Press enter if you really want to do rm -rf build/" build_linux() { - sudo rm -rf target - rustup update mkdir build/linux-x86_64 mkdir build/linux-x86_64/misc + + # add gnotification version and install script cargo build -r cp target/release/bRAC build/linux-x86_64/misc/bRAC-gnotif cp misc/user-install.sh build/linux-x86_64/install.sh cp misc/bRAC.png build/linux-x86_64/misc cp misc/create-desktop.sh build/linux-x86_64/misc + + # add libnotify version as the alternative cargo build -r -F libnotify cp target/release/bRAC build/linux-x86_64 + + # copy readme, license and make a zip cp README.md build/linux-x86_64 - cp LICENSE build/linux-x86_64 + cp LICENSE build/linux-x86_64 zip -r build/bRAC-linux-x86_64.zip build/linux-x86_64 } build_windows() { - chmod +x misc/mslink.sh - # curl -L https://github.com/wingtk/gvsbuild/releases/download/2025.5.0/GTK4_Gvsbuild_2025.5.0_x64.zip -o build/gvsbuild.zip # TODO: make this link auto-update - # unzip build/gvsbuild.zip "bin/*" -d build/windows-x86_64 - # rm build/gvsbuild.zip - # cross build --target x86_64-pc-windows-gnu -F notify-rust,winapi -r - mkdir build/windows-x86_64 docker run -ti -v `pwd`:/mnt mglolenstine/gtk4-cross:rust-gtk-nightly /bin/bash -c " - source \"\$HOME/.cargo/env\" - rustup update nightly; - rustup +nightly target add x86_64-pc-windows-gnu; - sed -i -e 's/cargo build/cargo +nightly build -F notify-rust,winapi/g' /bin/build; - build; - package; - mv package build/windows-x86_64/bin; - chmod -R 777 build/windows-x86_64" - # cp target/x86_64-pc-windows-gnu/release/bRAC.exe build/windows-x86_64/bin - echo "@echo off" > build/windows-x86_64/start.bat - echo "set \"PATH=%CD%\bin;%PATH%\"" >> build/windows-x86_64/start.bat - echo "start \"\" /B \"bin\bRAC.exe\"" >> build/windows-x86_64/start.bat - ./misc/mslink.sh -l "%COMSPEC% /C start start.bat" -o build/windows-x86_64/bRAC.lnk # TODO: fix this lnk + source \"\$HOME/.cargo/env\"; + rustup update nightly; # update nightly toolchain + rustup +nightly target add x86_64-pc-windows-gnu; # install windows stuff + sed -i -e 's/cargo build/cargo +nightly build -F notify-rust,winapi/g' /bin/build; # add features + nightly + build; # build it, creates package dir + package; # package it (adds some libs) + mv package build/windows-x86_64; + chmod -R 777 build/windows-x86_64; + rm -rf target/x86_64-pc-windows-gnu" + + # copy readme, license and make a zip cp README.md build/windows-x86_64 - curl https://raw.githubusercontent.com/wingtk/gvsbuild/refs/heads/main/COPYING -o build/windows-x86_64/LICENSE + cp LICENSE build/windows-x86_64 zip -r build/bRAC-windows-x86_64.zip build/windows-x86_64 -} +} -build_linux -build_windows +if [ $# -eq 0 ]; then + if [ ! -d build/windows-x86_64 ]; then + build_windows + fi + if [ ! -d build/linux-x86_64 ]; then + build_linux + fi + exit +fi + +if [ $1 = "clean" ]; then + rm -rf build +elif [ $1 = "windows" ]; then + rm -rf build/windows-x86_64 + build_windows +elif [ $1 = "linux" ]; then + rm -rf build/linux-x86_64 + build_linux +else + echo "possible arguments: clean windows linux. none for auto" +fi diff --git a/misc/mslink.sh b/misc/mslink.sh deleted file mode 100755 index ab60317..0000000 --- a/misc/mslink.sh +++ /dev/null @@ -1,243 +0,0 @@ -#!/bin/bash - -# mslink: Allow to create Windows Shortcut without the need of Windows -# -# Copyright (C) 2019 Mikaël Le Bohec -# -# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. - -############################################################################################# -# mslink.sh v1.3 -############################################################################################# -# Ce script permet de créer un Raccourci Windows (Fichier .LNK) -# Script créé en se basant sur la doc -# http://msdn.microsoft.com/en-us/library/dd871305.aspx -############################################################################################# - -OPTIONS=$(getopt -q -n ${0} -o hpl:o:n:w:a:i: -l help,lnk-target:,output-file:,name:,working-dir:,arguments:,icon:,printer-link -- "$@") - -eval set -- ${OPTIONS} - -IS_PRINTER_LNK=0 -while true; do - case "$1" in - -h|--help) HELP=1 ;; - -p|--printer-link) IS_PRINTER_LNK=1 ;; - -l|--lnk-target) LNK_TARGET="$2" ; shift ;; - -o|--output-file) OUTPUT_FILE="$2" ; shift ;; - -n|--name) param_HasName="$2" ; shift ;; - -w|--working-dir) param_HasWorkingDir="$2" ; shift ;; - -a|--arguments) param_HasArguments="$2" ; shift ;; - -i|--icon) param_HasIconLocation="$2" ; shift ;; - --) shift ; break ;; - *) echo "Option inconnue : $1" ; exit 1 ;; - esac - shift -done - -if [ $# -ne 0 ]; then - echo "Option(s) inconnue(s) : $@" - exit 1 -fi - -[ ${#LNK_TARGET} -eq 0 ] || [ ${#OUTPUT_FILE} -eq 0 ] && echo " -Usage : - ${0} -l cible_du_fichier_lnk [-n description] [-w working_dir] [-a cmd_args] [-i icon_path] -o mon_fichier.lnk [-p] - -Options : - -l, --lnk-target Précise la cible du raccourci - -o, --output-file Enregistre le raccourci dans un fichier - -n, --name Spécifie une description au raccourci - -w, --working-dir Spécifie le répertoire de lancement de la commande - -a, --arguments Spécifie les arguments de la commande lancée - -i, --icon Spécifie le chemin de l'icône - -p, --printer-link Génère un raccourci de type imprimante réseau -" && exit 1 - -############################################################################################# -# Fonctions -############################################################################################# - -function ascii2hex() { - echo $(echo -n ${1} | hexdump -v -e '/1 " x%02x"'|sed s/\ /\\\\/g) -} - -function gen_LinkFlags() { - echo '\x'$(printf '%02x' "$((HasLinkTargetIDList + HasName + HasWorkingDir + HasArguments + HasIconLocation))")${LinkFlags_2_3_4} -} - -function gen_Data_string() { - ITEM_SIZE=$(printf '%04x' $((${#1}))) - echo '\x'${ITEM_SIZE:2:2}'\x'${ITEM_SIZE:0:2}$(ascii2hex ${1}) -} - -function gen_IDLIST() { - ITEM_SIZE=$(printf '%04x' $((${#1}/4+2))) - echo '\x'${ITEM_SIZE:2:2}'\x'${ITEM_SIZE:0:2}${1} -} - -function convert_CLSID_to_DATA() { - echo -n ${1:6:2}${1:4:2}${1:2:2}${1:0:2}${1:11:2}${1:9:2}${1:16:2}${1:14:2}${1:19:4}${1:24:12}|sed s/"\([A-Fa-f0-9][A-Fa-f0-9]\)"/\\\\x\\1/g -} - -############################################################################################# -# Variables issues de la documentation officielle de Microsoft -############################################################################################# - -HasLinkTargetIDList=0x01 -HasName=0x04 -HasWorkingDir=0x10 -HasArguments=0x20 -HasIconLocation=0x40 - -HeaderSize='\x4c\x00\x00\x00' # HeaderSize -LinkCLSID=$(convert_CLSID_to_DATA "00021401-0000-0000-c000-000000000046") # LinkCLSID -LinkFlags_2_3_4='\x01\x00\x00' # ForceNoLinkInfo -LinkFlags="" - -FileAttributes_Directory='\x10\x00\x00\x00' # FILE_ATTRIBUTE_DIRECTORY -FileAttributes_File='\x20\x00\x00\x00' # FILE_ATTRIBUTE_ARCHIVE - -CreationTime='\x00\x00\x00\x00\x00\x00\x00\x00' -AccessTime='\x00\x00\x00\x00\x00\x00\x00\x00' -WriteTime='\x00\x00\x00\x00\x00\x00\x00\x00' - -FileSize='\x00\x00\x00\x00' -IconIndex='\x00\x00\x00\x00' -ShowCommand='\x01\x00\x00\x00' # SW_SHOWNORMAL -Hotkey='\x00\x00' # No Hotkey -Reserved='\x00\x00' # Valeur non modifiable -Reserved2='\x00\x00\x00\x00' # Valeur non modifiable -Reserved3='\x00\x00\x00\x00' # Valeur non modifiable -TerminalID='\x00\x00' # Valeur non modifiable - -CLSID_Computer="20d04fe0-3aea-1069-a2d8-08002b30309d" # Poste de travail -CLSID_Network="208d2c60-3aea-1069-a2d7-08002b30309d" # Favoris réseau - -############################################################################################# -# Constantes trouvées à partir de l'analyse de fichiers lnk -############################################################################################# - -PREFIX_LOCAL_ROOT='\x2f' # Disque local -PREFIX_FOLDER='\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' # Dossier de fichiers -PREFIX_FILE='\x32\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' # Fichier -PREFIX_NETWORK_ROOT='\xc3\x01\x81' # Racine de serveur de fichiers réseau -PREFIX_NETWORK_PRINTER='\xc3\x02\xc1' # Imprimante réseau - -END_OF_STRING='\x00' - -############################################################################################# - -if [ ! -z "${param_HasName}" ]; then - STRING_DATA=${STRING_DATA}$(gen_Data_string ${param_HasName}) -else - HasName=0x00 -fi -if [ ! -z "${param_HasWorkingDir}" ]; then - STRING_DATA=${STRING_DATA}$(gen_Data_string ${param_HasWorkingDir}) -else - HasWorkingDir=0x00 -fi -if [ ! -z "${param_HasArguments}" ]; then - STRING_DATA=${STRING_DATA}$(gen_Data_string ${param_HasArguments}) -else - HasArguments=0x00 -fi -if [ ! -z "${param_HasIconLocation}" ]; then - STRING_DATA=${STRING_DATA}$(gen_Data_string ${param_HasIconLocation}) -else - HasIconLocation=0x00 -fi - -LinkFlags=$(gen_LinkFlags) - -# On retire l'anti-slash final s'il y en a un -LNK_TARGET=${LNK_TARGET%\\} - -# On sépare le chemin racine du lien de la cible finale -# On distingue aussi si le lien est de type local ou réseau -# On définie la valeur Item_Data suivant le cas d'un lien réseau ou local - -IS_ROOT_LNK=0 -IS_NETWORK_LNK=0 - -if [[ ${LNK_TARGET} == \\\\* ]]; then - IS_NETWORK_LNK=1 - PREFIX_ROOT=${PREFIX_NETWORK_ROOT} - Item_Data='\x1f\x58'$(convert_CLSID_to_DATA ${CLSID_Network}) - - TARGET_ROOT=${LNK_TARGET%\\*} - if [[ ${LNK_TARGET} == \\\\*\\* ]]; then - TARGET_LEAF=${LNK_TARGET##*\\} - fi - if [ ${TARGET_ROOT} == \\ ]; then - TARGET_ROOT=${LNK_TARGET} - fi -else - PREFIX_ROOT=${PREFIX_LOCAL_ROOT} - Item_Data='\x1f\x50'$(convert_CLSID_to_DATA ${CLSID_Computer}) - - TARGET_ROOT=${LNK_TARGET%%\\*} - if [[ ${LNK_TARGET} == *\\* ]]; then - TARGET_LEAF=${LNK_TARGET#*\\} - fi - [[ ! ${TARGET_ROOT} == *\\ ]] && TARGET_ROOT=${TARGET_ROOT}'\' -fi - -if [ ${IS_PRINTER_LNK} -eq 1 ]; then - PREFIX_ROOT=${PREFIX_NETWORK_PRINTER} - TARGET_ROOT=${LNK_TARGET} - IS_ROOT_LNK=1 -fi - -[ ${#TARGET_LEAF} -eq 0 ] && IS_ROOT_LNK=1 - -############################################################################################# - -# On sélectionne le préfixe qui sera utilisé pour afficher l'icône du raccourci - -if [[ ${TARGET_LEAF} == *.??? ]]; then - PREFIX_OF_TARGET=${PREFIX_FILE} - TYPE_TARGET="fichier" - FileAttributes=${FileAttributes_File} -else - PREFIX_OF_TARGET=${PREFIX_FOLDER} - TYPE_TARGET="dossier" - FileAttributes=${FileAttributes_Directory} -fi - -# On convertit les valeurs des cibles en binaire -TARGET_ROOT=$(ascii2hex "${TARGET_ROOT}") -TARGET_ROOT=${TARGET_ROOT}$(for i in `seq 1 21`;do echo -n '\x00';done) # Nécessaire à partir de Vista et supérieur sinon le lien est considéré comme vide (je n'ai trouvé nul part d'informations à ce sujet) - -TARGET_LEAF=$(ascii2hex "${TARGET_LEAF}") - -# On crée l'IDLIST qui représente le cœur du fichier LNK - -if [ ${IS_ROOT_LNK} -eq 1 ];then - IDLIST_ITEMS=$(gen_IDLIST ${Item_Data})$(gen_IDLIST ${PREFIX_ROOT}${TARGET_ROOT}${END_OF_STRING}) -else - IDLIST_ITEMS=$(gen_IDLIST ${Item_Data})$(gen_IDLIST ${PREFIX_ROOT}${TARGET_ROOT}${END_OF_STRING})$(gen_IDLIST ${PREFIX_OF_TARGET}${TARGET_LEAF}${END_OF_STRING}) -fi - -IDLIST=$(gen_IDLIST ${IDLIST_ITEMS}) - -############################################################################################# - -if [ ${IS_NETWORK_LNK} -eq 1 ]; then - TYPE_LNK="réseau" - if [ ${IS_PRINTER_LNK} -eq 1 ]; then - TYPE_TARGET="imprimante" - fi -else - TYPE_LNK="local" -fi - -echo "Création d'un raccourci de type \""${TYPE_TARGET}" "${TYPE_LNK}"\" avec pour cible "${LNK_TARGET} ${param_HasArguments} 1>&2 - -echo -ne ${HeaderSize}${LinkCLSID}${LinkFlags}${FileAttributes}${CreationTime}${AccessTime}${WriteTime}${FileSize}${IconIndex}${ShowCommand}${Hotkey}${Reserved}${Reserved2}${Reserved3}${IDLIST}${TerminalID}${STRING_DATA} > "${OUTPUT_FILE}" - diff --git a/src/chat/gui.rs b/src/chat/gui.rs index 7dd8675..918c386 100644 --- a/src/chat/gui.rs +++ b/src/chat/gui.rs @@ -482,6 +482,9 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { false }; + #[cfg(target_os = "windows")] + let is_dark_theme = true; + let main_box = GtkBox::new(Orientation::Vertical, 5); main_box.set_css_classes(&["main-box"]); @@ -1296,6 +1299,12 @@ pub fn run_main_loop(ctx: Arc) { libnotify::init("ru.themixray.bRAC").expect("libnotify init error"); } + #[cfg(target_os = "windows")] + { + use std::env; + env::set_var("GTK_THEME", "Adwaita:dark"); + } + let application = Application::builder() .application_id("ru.themixray.bRAC") .flags(ApplicationFlags::FLAGS_NONE)