Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

Commit d42c46a

Browse files
committed
fix: asus profile
1 parent f138e24 commit d42c46a

File tree

5 files changed

+200
-86
lines changed

5 files changed

+200
-86
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=ASUS Profile Synchronization Service
3+
After=graphical-session.target
4+
5+
[Service]
6+
Type=simple
7+
ExecStart=%h/.local/bin/asus-profile-sync.sh
8+
Restart=on-failure
9+
RestartSec=5
10+
11+
[Install]
12+
WantedBy=default.target

home/local/.local/bin/asus-profile-notify.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# Listen to asusd D-Bus signals and sync tuned profile
3+
# This replaces the udev-based approach to avoid feedback loops
4+
5+
# Profile mapping (from busctl output: 0=Performance, 1=Balanced, 2=Quiet, 3=?)
6+
get_profile_name() {
7+
case "$1" in
8+
0) echo "Performance" ;;
9+
1) echo "Balanced" ;;
10+
2) echo "Quiet" ;;
11+
*) echo "Unknown" ;;
12+
esac
13+
}
14+
15+
# Map profile to tuned and show notification
16+
apply_profile() {
17+
local profile_num="$1"
18+
local profile_name=$(get_profile_name "$profile_num")
19+
20+
case "$profile_name" in
21+
"Quiet")
22+
/usr/sbin/tuned-adm profile powersave >/dev/null 2>&1
23+
/usr/bin/supergfxctl -m "Integrated" >/dev/null 2>&1
24+
icon="battery-profile-powersave"
25+
message="Profile: Quiet (Power Saver)"
26+
;;
27+
"Balanced")
28+
/usr/sbin/tuned-adm profile balanced-battery >/dev/null 2>&1
29+
/usr/bin/supergfxctl -m "Hybrid" >/dev/null 2>&1
30+
icon="battery-060"
31+
message="Profile: Balanced"
32+
;;
33+
"Performance")
34+
/usr/sbin/tuned-adm profile throughput-performance >/dev/null 2>&1
35+
/usr/bin/supergfxctl -m "Hybrid" >/dev/null 2>&1
36+
icon="battery-profile-performance"
37+
message="Profile: Performance"
38+
;;
39+
*)
40+
icon="preferences-system-power-management"
41+
message="Profile: $profile_name"
42+
;;
43+
esac
44+
45+
# Show notification
46+
if command -v qdbus >/dev/null 2>&1; then
47+
qdbus org.kde.plasmashell /org/kde/osdService org.kde.osdService.showText "$icon" "$message" 2>/dev/null
48+
elif command -v notify-send >/dev/null 2>&1; then
49+
notify-send -i "$icon" -t 2000 "ASUS Profile" "$message" 2>/dev/null
50+
fi
51+
}
52+
53+
# Monitor D-Bus for PlatformProfile changes
54+
dbus-monitor --system "type='signal',sender='xyz.ljones.Asusd',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='/xyz/ljones'" | \
55+
while read -r line; do
56+
# Look for PlatformProfile property changes
57+
if echo "$line" | grep -q "PlatformProfile"; then
58+
# Next line should contain the new value
59+
read -r value_line
60+
if echo "$value_line" | grep -q "uint32"; then
61+
profile_num=$(echo "$value_line" | grep -oP 'uint32 \K\d+')
62+
apply_profile "$profile_num"
63+
fi
64+
fi
65+
done

unix/fedora/install/config/hardware/asus.sh

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,19 @@ sudo dnf install -y "${packages[@]}"
3333
sudo systemctl enable supergfxd.service || log_warning "Failed to enable supergfxd"
3434
sudo systemctl start asusd || log_warning "Failed to start asusd"
3535

36-
# Configure udev rules for profile notifications
37-
log_info "Setting up ASUS profile change notifications"
36+
# Set up D-Bus monitoring for profile changes
37+
log_info "Setting up ASUS profile synchronization"
3838

3939
# Get the actual user (not root)
4040
REAL_USER="${SUDO_USER:-$USER}"
41-
REAL_UID=$(id -u "$REAL_USER")
42-
REAL_HOME=$(eval echo "~$REAL_USER")
4341

44-
sudo tee /etc/udev/rules.d/99-asus-profile-toast.rules > /dev/null <<EOF
45-
KERNEL=="platform-profile-*", \\
46-
SUBSYSTEM=="platform-profile", \\
47-
ACTION=="change", \\
48-
RUN+="/bin/bash -c ' \\
49-
DISPLAY=:0 \\
50-
XDG_RUNTIME_DIR=/run/user/$REAL_UID \\
51-
/usr/bin/sudo -u $REAL_USER \\
52-
$REAL_HOME/.local/bin/asus-profile-notify.sh \\
53-
'"
54-
EOF
42+
# Enable and start the user service
43+
sudo -u "$REAL_USER" systemctl --user enable asus-profile-sync.service
44+
sudo -u "$REAL_USER" systemctl --user start asus-profile-sync.service
5545

5646
# Configure polkit for profile switching
5747
sudo tee /etc/polkit-1/rules.d/49-asus-profile.rules > /dev/null <<'EOF'
58-
// Allow switching TuneD profiles from udev/inactive sessions
48+
// Allow switching TuneD profiles from user sessions
5949
polkit.addRule(function(action, subject) {
6050
if (action.id == "com.redhat.tuned.switch_profile") {
6151
return polkit.Result.YES;
@@ -64,10 +54,6 @@ polkit.addRule(function(action, subject) {
6454
EOF
6555

6656
sudo chmod 644 /etc/polkit-1/rules.d/49-asus-profile.rules
67-
sudo chmod 644 /etc/udev/rules.d/99-asus-profile-toast.rules
68-
69-
# Restart services
7057
sudo systemctl restart polkit
71-
sudo udevadm control --reload-rules
7258

7359
log_success "ASUS system optimizations applied"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# Migration: Replace udev-based ASUS profile sync with D-Bus approach
3+
# Removes old udev rule and asus-profile-notify.sh
4+
# Enables new systemd user service for D-Bus monitoring
5+
6+
echo "Running migration: ASUS Profile Sync - udev to D-Bus migration"
7+
8+
# Check if this is an ASUS system
9+
if ! sudo dmidecode -s system-manufacturer 2>/dev/null | grep -qi asus; then
10+
echo "Not an ASUS system, skipping migration"
11+
exit 0
12+
fi
13+
14+
echo "Stopping old udev-based profile sync..."
15+
16+
if [[ -f /etc/udev/rules.d/99-asus-profile-toast.rules ]]; then
17+
echo "Removing old udev rule: /etc/udev/rules.d/99-asus-profile-toast.rules"
18+
sudo rm -f /etc/udev/rules.d/99-asus-profile-toast.rules
19+
sudo udevadm control --reload-rules
20+
echo "Old udev rule removed"
21+
else
22+
echo "Old udev rule not found (already removed or never existed)"
23+
fi
24+
25+
OLD_SCRIPT="$HOME/.local/bin/asus-profile-notify.sh"
26+
if [[ -f "$OLD_SCRIPT" ]]; then
27+
echo "Removing old script: $OLD_SCRIPT"
28+
rm -f "$OLD_SCRIPT"
29+
echo "Old script removed"
30+
else
31+
echo "Old script not found (already removed or never existed)"
32+
fi
33+
34+
echo "Cleaning up old lock and state files..."
35+
rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-notify.lock"
36+
rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-last-state"
37+
rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-debounce"
38+
rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-timestamp"
39+
rm -f /tmp/asus-profile-notify.lock
40+
rm -f /tmp/asus-profile-last-state
41+
echo "Cleaned up temporary files"
42+
43+
NEW_SCRIPT="$HOME/.local/bin/asus-profile-sync.sh"
44+
NEW_SERVICE="$HOME/.config/systemd/user/asus-profile-sync.service"
45+
46+
if [[ ! -f "$NEW_SCRIPT" ]] || [[ ! -f "$NEW_SERVICE" ]]; then
47+
echo "New files not found, attempting to stow 'home' package..."
48+
49+
CONFIGS_DIR="$HOME/Dev/.configs"
50+
if [[ ! -d "$CONFIGS_DIR" ]]; then
51+
echo "ERROR: Configs directory not found at $CONFIGS_DIR"
52+
echo "Please ensure your dotfiles are cloned to $CONFIGS_DIR"
53+
exit 1
54+
fi
55+
56+
COMMON_HELPERS="$CONFIGS_DIR/unix/fedora/install/helpers/common.sh"
57+
if [[ -f "$COMMON_HELPERS" ]]; then
58+
source "$COMMON_HELPERS"
59+
fi
60+
61+
STOW_SCRIPT="$CONFIGS_DIR/unix/common/dotfiles/stow.sh"
62+
if [[ ! -f "$STOW_SCRIPT" ]]; then
63+
echo "ERROR: Stow script not found at $STOW_SCRIPT"
64+
exit 1
65+
fi
66+
67+
source "$STOW_SCRIPT"
68+
69+
if stow_dotfiles "$CONFIGS_DIR/home" "$HOME" local; then
70+
echo "Stowed home/local package"
71+
else
72+
echo "ERROR: Failed to stow home/local package"
73+
exit 1
74+
fi
75+
76+
if [[ ! -f "$NEW_SCRIPT" ]]; then
77+
echo "ERROR: $NEW_SCRIPT still not found after stowing"
78+
exit 1
79+
fi
80+
81+
if [[ ! -f "$NEW_SERVICE" ]]; then
82+
echo "ERROR: $NEW_SERVICE still not found after stowing"
83+
exit 1
84+
fi
85+
86+
echo "New files successfully deployed"
87+
else
88+
echo "New files already exist"
89+
fi
90+
91+
echo "Reloading systemd user daemon..."
92+
systemctl --user daemon-reload
93+
94+
echo "Enabling and starting new D-Bus monitoring service..."
95+
systemctl --user enable asus-profile-sync.service
96+
systemctl --user restart asus-profile-sync.service
97+
98+
if systemctl --user is-active --quiet asus-profile-sync.service; then
99+
echo "asus-profile-sync.service is running"
100+
else
101+
echo "⚠ WARNING: asus-profile-sync.service failed to start"
102+
echo "Check status with: systemctl --user status asus-profile-sync.service"
103+
exit 1
104+
fi
105+
106+
echo ""
107+
echo "Migration completed successfully!"
108+
echo ""
109+
echo "Summary of changes:"
110+
echo " - Removed: /etc/udev/rules.d/99-asus-profile-toast.rules"
111+
echo " - Removed: ~/.local/bin/asus-profile-notify.sh"
112+
echo " - Added: ~/.local/bin/asus-profile-sync.sh"
113+
echo " - Added: ~/.config/systemd/user/asus-profile-sync.service"
114+
echo " - Enabled: asus-profile-sync.service (D-Bus monitoring)"
115+
echo ""
116+
echo "You can now test by pressing Fn+F5 to change power profiles"
117+
echo "Monitor logs with: journalctl --user -u asus-profile-sync.service -f"

0 commit comments

Comments
 (0)