Change notification system

This commit is contained in:
Hadi 2024-06-24 21:13:22 +02:00
parent 1cdfe8e278
commit 3b84f735ee
9 changed files with 50 additions and 38 deletions

View File

@ -23,6 +23,7 @@ feel free to contribute <3 ([CONTRIBUTING.md](CONTRIBUTING.md))
- [ ] Animations based on app name - [ ] Animations based on app name
- [ ] Wofi: popin - [ ] Wofi: popin
- [ ] Wlogout: fade in - [ ] Wlogout: fade in
- [ ] Fix screenshots
- [ ] Nixvim - [ ] Nixvim
- [ ] Telescope: find with file content - [ ] Telescope: find with file content

View File

@ -13,9 +13,7 @@ let
message="󰃠 Brightness: $brightness_level%" message="󰃠 Brightness: $brightness_level%"
${pkgs.libnotify}/bin/notify-send "$message" \ notif "brightness" "$message" "extraargs=-h int:value:$brightness_level"
-h int:value:"$brightness_level" \
--replace-id="$(cat "/tmp/nixy-notification" 2>/dev/null || echo 0)" --print-id > "/tmp/nixy-notification"
''; '';
brightness-up = pkgs.writeShellScriptBin "brightness-up" '' brightness-up = pkgs.writeShellScriptBin "brightness-up" ''

View File

@ -14,8 +14,7 @@ let
pkill hypridle pkill hypridle
message="󰅶 Caffeine Activated" message="󰅶 Caffeine Activated"
fi fi
${pkgs.libnotify}/bin/notify-send "$message" \ notif "caffeine" "$message"
--replace-id="$(cat "/tmp/nixy-notification" 2>/dev/null || echo 0)" --print-id > "/tmp/nixy-notification"
''; '';
in { home.packages = [ caffeine-status caffeine ]; } in { home.packages = [ caffeine-status caffeine ]; }

View File

@ -17,12 +17,8 @@ let
fi fi
''; '';
wireguard-import = pkgs.writeShellScriptBin "wireguard-import" '' lock = pkgs.writeShellScriptBin "lock" ''
nmcli connection import type wireguard file "$1" ${pkgs.hyprlock}/bin/hyprlock
''; '';
vault = pkgs.writeShellScriptBin "vault" '' in { home.packages = [ menu powermenu lock ]; }
nvim $HOME/Nextcloud/obsidian
'';
in { home.packages = [ menu wireguard-import powermenu vault ]; }

View File

@ -1,21 +1,18 @@
{ pkgs, config, ... }: { pkgs, ... }:
let let
homedir = config.home.homeDirectory;
default = "4000"; default = "4000";
night-shift-on = pkgs.writeShellScriptBin "night-shift-on" '' night-shift-on = pkgs.writeShellScriptBin "night-shift-on" ''
${pkgs.hyprland}/bin/hyprctl dispatch exec "${pkgs.wlsunset}/bin/wlsunset -t ${default}" ${pkgs.hyprland}/bin/hyprctl dispatch exec "${pkgs.wlsunset}/bin/wlsunset -t ${default}"
message="󰖔 Night-Shift Activated" message="󰖔 Night-Shift Activated"
${pkgs.libnotify}/bin/notify-send "$message" \ notif "night-shift" "$message"
--replace-id="$(cat "/tmp/nixy-notification" 2>/dev/null || echo 0)" --print-id > "/tmp/nixy-notification"
''; '';
night-shift-off = pkgs.writeShellScriptBin "night-shift-off" '' night-shift-off = pkgs.writeShellScriptBin "night-shift-off" ''
pkill wlsunset pkill wlsunset
message="󰖔 Night-Shift Deactivated" message="󰖔 Night-Shift Deactivated"
${pkgs.libnotify}/bin/notify-send "$message" \ notif "night-shift" "$message"
--replace-id="$(cat "/tmp/nixy-notification" 2>/dev/null || echo 0)" --print-id > "/tmp/nixy-notification"
''; '';
in { home.packages = [ night-shift-on night-shift-off ]; } in { home.packages = [ night-shift-on night-shift-off ]; }

View File

@ -26,9 +26,7 @@ let
message="󰕾 Volume: $volume%" message="󰕾 Volume: $volume%"
fi fi
${pkgs.libnotify}/bin/notify-send "$message" \ notif "sound" "$message" "extraargs=-h int:value:$volume"
-h int:value:"$volume" \
--replace-id="$(cat "/tmp/nixy-notification" 2>/dev/null || echo 0)" --print-id > "/tmp/nixy-notification"
''; '';
sound-up = pkgs.writeShellScriptBin "sound-up" '' sound-up = pkgs.writeShellScriptBin "sound-up" ''

View File

@ -7,7 +7,7 @@ let
[[ ${toString config.var.sops} == "1" ]] && systemctl --user start sops-nix [[ ${toString config.var.sops} == "1" ]] && systemctl --user start sops-nix
notify-system & battery-watch &
${pkgs.waybar}/bin/waybar & ${pkgs.waybar}/bin/waybar &

View File

@ -1,16 +1,37 @@
{ pkgs, ... }: { pkgs, ... }:
let let
notify-system = pkgs.writeShellScriptBin "notify-system" ''
function minute() {
while true;do
battery-plugged &
battery-level &
sleep 60
done
}
minute notif = pkgs.writeShellScriptBin "notif" ''
# Shell script to send custom notifications
NOTIF_FOLDER="/tmp/notif"
sender_id=$1 # To overwrite existing notifications
message=$2
extraargs=""
description=""
if [[ $3 == "extraargs="* ]]; then
extraargs=$(echo "$3" | sed 's/extraargs=//g')
else
description="$3"
extraargs="$4"
fi
[[ -d "$NOTIF_FOLDER" ]] || mkdir $NOTIF_FOLDER
[[ -f "$NOTIF_FOLDER/$sender_id" ]] || echo "0" > "$NOTIF_FOLDER/$sender_id"
old_notification_id=$(cat "$NOTIF_FOLDER/$sender_id")
${pkgs.libnotify}/bin/notify-send "$message" \
$extraargs \
--replace-id="$old_notification_id" --print-id > "$NOTIF_FOLDER/$sender_id"
'';
battery-watch = pkgs.writeShellScriptBin "battery-watch" ''
while true;do
battery-plugged &
battery-level &
sleep 60
done
''; '';
battery-plugged = pkgs.writeShellScriptBin "battery-plugged" '' battery-plugged = pkgs.writeShellScriptBin "battery-plugged" ''
@ -18,9 +39,9 @@ let
OLD_BATTERY_STATUS=$(cat /tmp/old_battery_status 2>/dev/null || echo "Unknown") OLD_BATTERY_STATUS=$(cat /tmp/old_battery_status 2>/dev/null || echo "Unknown")
if [[ $BATTERY_STATUS != $OLD_BATTERY_STATUS && $OLD_BATTERY_STATUS != "Unknown" ]]; then if [[ $BATTERY_STATUS != $OLD_BATTERY_STATUS && $OLD_BATTERY_STATUS != "Unknown" ]]; then
if [[ $BATTERY_STATUS == "Discharging" ]]; then if [[ $BATTERY_STATUS == "Discharging" ]]; then
${pkgs.libnotify}/bin/notify-send "󰚦 " "Battery is unplugged" notif "battery" "󰚦 Battery is unplugged"
else else
${pkgs.libnotify}/bin/notify-send "󰚥 " "Battery is plugged in" notif "battery" "󰚥 Battery is plugged in"
fi fi
fi fi
echo $BATTERY_STATUS > /tmp/old_battery_status echo $BATTERY_STATUS > /tmp/old_battery_status
@ -30,12 +51,12 @@ let
BATTERY_LEVEL=$(cat /sys/class/power_supply/BAT*/capacity | head -n1) BATTERY_LEVEL=$(cat /sys/class/power_supply/BAT*/capacity | head -n1)
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT*/status | head -n1) BATTERY_STATUS=$(cat /sys/class/power_supply/BAT*/status | head -n1)
if [[ $BATTERY_LEVEL -le 20 ]] && [[ $BATTERY_STATUS == "Discharging" ]]; then if [[ $BATTERY_LEVEL -le 20 ]] && [[ $BATTERY_STATUS == "Discharging" ]]; then
${pkgs.libnotify}/bin/notify-send "󰁻 Low battery" "Battery level is $BATTERY_LEVEL%" notif "battery" "󰁻 Low battery" "Battery level is $BATTERY_LEVEL%"
elif [[ $BATTERY_LEVEL -le 10 ]] && [[ $BATTERY_STATUS == "Discharging" ]]; then elif [[ $BATTERY_LEVEL -le 10 ]] && [[ $BATTERY_STATUS == "Discharging" ]]; then
${pkgs.libnotify}/bin/notify-send --urgency=critical "󰁺 Very low battery" "Battery level is $BATTERY_LEVEL%" notif "battery" "󰁺 Very low battery" "Battery level is $BATTERY_LEVEL%"
elif [[ $BATTERY_LEVEL -eq 100 ]] && [[ $BATTERY_STATUS -ne "Discharging" ]]; then elif [[ $BATTERY_LEVEL -eq 100 ]] && [[ $BATTERY_STATUS -ne "Discharging" ]]; then
${pkgs.libnotify}/bin/notify-send "󰁹 Fully charged" notif "battery" "󰁹 Fully charged"
fi fi
''; '';
in { home.packages = [ notify-system battery-plugged battery-level ]; } in { home.packages = [ notif battery-watch battery-plugged battery-level ]; }

View File

@ -49,6 +49,8 @@
icat = "${pkgs.kitty}/bin/kitty +kitten icat"; icat = "${pkgs.kitty}/bin/kitty +kitten icat";
note = "vim ~/Nextcloud/obsidian"; note = "vim ~/Nextcloud/obsidian";
obs = "vim ~/Nextcloud/obsidian"; obs = "vim ~/Nextcloud/obsidian";
wireguard-import = "nmcli connection import type wireguard file";
vault = "nvim $HOME/nextcloud/Notes/";
# git # git
ga = "git add"; ga = "git add";