blob: b93bf6eec0a9cb6bcd87f42bf75fbf5da9ed0ac6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
{ config, pkgs, lib, ... }:
let
vars = import ./variables.nix;
# Battery notification script
batteryNotify = pkgs.writeShellScriptBin "battery-notify" ''
#!/bin/sh
# Get battery status
BATTERY_PATH="/sys/class/power_supply/BAT0"
if [ ! -d "$BATTERY_PATH" ]; then
# Try BAT1 if BAT0 doesn't exist
BATTERY_PATH="/sys/class/power_supply/BAT1"
if [ ! -d "$BATTERY_PATH" ]; then
exit 0
fi
fi
CAPACITY=$(cat "$BATTERY_PATH/capacity")
STATUS=$(cat "$BATTERY_PATH/status")
# Critical threshold (5%)
if [ "$CAPACITY" -le 5 ] && [ "$STATUS" != "Charging" ]; then
${pkgs.libnotify}/bin/notify-send -u critical "Battery Critical" "Battery level: $CAPACITY%\nPlease plug in charger immediately!"
# Low threshold (15%)
elif [ "$CAPACITY" -le 15 ] && [ "$STATUS" != "Charging" ]; then
${pkgs.libnotify}/bin/notify-send -u normal "Battery Low" "Battery level: $CAPACITY%\nConsider plugging in charger soon."
fi
'';
in {
home.packages = [ batteryNotify ];
services.dunst = {
enable = true;
settings = lib.mkForce {
global = {
width = "(200,300)";
height = "(0,150)";
offset = "(30,50)";
origin = "bottom-right";
transparency = 10;
frame_width = 2;
corner_radius = 8;
gap_size = 5;
};
urgency_low = {
background = vars.colors.background;
foreground = vars.colors.foreground;
timeout = 8;
};
urgency_normal = {
background = vars.colors.background;
foreground = vars.colors.foreground;
frame_color = vars.colors.accent;
timeout = 10;
};
urgency_critical = {
background = vars.colors.background;
foreground = vars.colors.foreground;
frame_color = vars.colors.alert;
timeout = 0; # Don't auto-dismiss critical notifications
};
};
};
# Systemd service to check battery periodically
systemd.user.services.battery-notify = {
Unit = {
Description = "Battery level notification service";
};
Service = {
Type = "oneshot";
ExecStart = "${batteryNotify}/bin/battery-notify";
};
};
# Timer to run battery check every 2 minutes
systemd.user.timers.battery-notify = {
Unit = {
Description = "Battery level notification timer";
};
Timer = {
OnBootSec = "1min";
OnUnitActiveSec = "2min";
};
Install = {
WantedBy = [ "timers.target" ];
};
};
}
|