Refactor: rewrite startup script without modifying config

This commit is contained in:
obsidrielle
2025-05-14 10:35:11 +08:00
parent cd9167344f
commit a544f09114
4 changed files with 13 additions and 41 deletions
@@ -9,6 +9,8 @@ RESTORE_SCRIPT_DIR="$CUSTOM_DIR/scripts"
RESTORE_SCRIPT="$RESTORE_SCRIPT_DIR/__restore_video_wallpaper.sh"
EXECS_CONF="$CUSTOM_DIR/execs.conf"
VIDEO_OPTS="no-audio loop hwdec=auto scale=bilinear interpolation=no video-sync=display-resample panscan=1.0 video-scale-x=1.0 video-scale-y=1.0 video-align-x=0.5 video-align-y=0.5"
mkdir -p "$THUMBNAIL_DIR"
mkdir -p "$RESTORE_SCRIPT_DIR"
@@ -24,7 +26,6 @@ kill_existing_mpvpaper() {
create_restore_script() {
local video_path=$1
local video_opts=${2:-"no-audio loop"}
cat > "$RESTORE_SCRIPT" << EOF
#!/bin/bash
@@ -34,7 +35,7 @@ create_restore_script() {
pkill -f -9 mpvpaper
for monitor in \$(hyprctl monitors -j | jq -r '.[] | .name'); do
mpvpaper -f -o "$video_opts" "\$monitor" "$video_path" &
mpvpaper -o "$VIDEO_OPTS" "\$monitor" "$video_path" &
sleep 0.1
done
EOF
@@ -42,42 +43,13 @@ EOF
chmod +x "$RESTORE_SCRIPT"
}
ensure_restore_exec() {
local restore_line="exec-once=bash $RESTORE_SCRIPT"
if [ ! -f "$EXECS_CONF" ]; then
echo "$restore_line" >> "$EXECS_CONF"
fi
# Add `exec-once = bash $RESTORE_SCRIPT` if not exists
if ! grep -q "$restore_line" "$EXECS_CONF"; then
echo "$restore_line" >> "$EXECS_CONF"
fi
}
remove_restore() {
if [ -f "$RESTORE_SCRIPT" ]; then
rm "$RESTORE_SCRIPT"
fi
cat > "$RESTORE_SCRIPT.tmp" << EOF
#!/bin/bash
# The content of this script will be generated by switchwall.sh - Don't modify it by yourself.
EOF
# Delete `exec-once = bach $RESTORE_SCRIPT` if exists
if [ -f "$EXECS_CONF" ]; then
grep -v "exec-once=bash $RESTORE_SCRIPT" "$EXECS_CONF" > "$EXECS_CONF.tmp"
mv "$EXECS_CONF.tmp" "$EXECS_CONF"
fi
}
save_video_config() {
local path=$1
local opts=$2
local exec_cmd=$3
echo "VIDEO_PATH=$path" > "$VIDEO_CONFIG"
echo "VIDEO_OPTS=$opts" >> "$VIDEO_CONFIG"
if [ -n "$exec_cmd" ]; then
echo "EXEC_CMD=$exec_cmd" >> "$VIDEO_CONFIG"
fi
mv "$RESTORE_SCRIPT.tmp" $RESTORE_SCRIPT
}
switch() {
@@ -114,12 +86,11 @@ switch() {
fi
local video_path=$1
local video_opts=${2:-"no-audio loop hwdec=auto scale=bilinear interpolation=no video-sync=display-resample panscan=1.0 video-scale-x=1.0 video-scale-y=1.0 video-align-x=0.5 video-align-y=0.5"}
monitors=$(hyprctl monitors -j | jq -r '.[] | .name')
for monitor in $monitors; do
mpvpaper -o "$video_opts" "$monitor" "$video_path" &
mpvpaper -o "$VIDEO_OPTS" "$monitor" "$video_path" &
sleep 0.1
done
@@ -130,7 +101,6 @@ switch() {
if [ -f "$thumbnail" ]; then
"$CONFIG_DIR"/scripts/color_generation/colorgen.sh "$thumbnail" --apply --smart
create_restore_script "$video_path" "$video_opts"
ensure_restore_exec
else
echo "Cannot create image to colorgen"
fi
@@ -0,0 +1,2 @@
#!/bin/bash
# The content of this script will be generated by switchwall.sh - Don't modify it by yourself.
-1
View File
@@ -15,4 +15,3 @@ source=~/.config/hypr/custom/execs.conf
source=~/.config/hypr/custom/general.conf
source=~/.config/hypr/custom/rules.conf
source=~/.config/hypr/custom/keybinds.conf
+1
View File
@@ -1,5 +1,6 @@
# Bar, wallpaper
exec-once = swww-daemon --format xrgb
exec-once = bash ~/.config/hypr/custom/scripts/__restore_video_wallpaper.sh
exec-once = /usr/lib/geoclue-2.0/demos/agent & gammastep
exec-once = agsv1 &