Fix sound options and panel controls

This commit is contained in:
2026-09-10 00:41:34 +01:00
parent e827ba10e4
commit aa29f017f7
8 changed files with 183 additions and 23 deletions
+13
View File
@@ -6,6 +6,10 @@ const assert = require("assert")
const src = fs.readFileSync(path.join(__dirname, "..", "Rules.js"), "utf8").replace(/\/\/ Not a .pragma library[^\n]*/, "")
const R = {}
new Function("exports", src + "\n" + ["normalizeConfig", "matchingRules", "stripTags", "describeRule", "normalizeEffect", "withDefaults", "renderTemplate"].map(n => `exports.${n} = ${n}`).join("\n"))(R)
const catalogSrc = fs.readFileSync(path.join(__dirname, "..", "EffectCatalog.js"), "utf8")
const C = {}
new Function("exports", catalogSrc + "\nexports.effects = EFFECTS")(C)
const settingsSrc = fs.readFileSync(path.join(__dirname, "..", "Settings.qml"), "utf8")
const cfg = R.normalizeConfig({
rules: [
@@ -58,4 +62,13 @@ assert.deepStrictEqual(all.rules[1].effects, [])
assert.strictEqual(R.renderTemplate("", { summary: "Hi", body: "<b>x</b>" }, { name: "r" }), "Hi")
assert.strictEqual(R.renderTemplate("{rule}: {summary} / {body} ({app})", { app: "A", summary: "Hi", body: "<b>x</b>" }, { name: "r" }), "r: Hi / x (A)")
const sound = C.effects.find(effect => effect.type === "sound")
assert.ok(sound.rows.some(row => row.key === "duration" && row.min === 0 && row.max === 30 && row.fallback === 0))
assert.ok(sound.rows.some(row => row.key === "repeat" && row.min === 1 && row.max === 50))
assert.strictEqual(sound.options.length, 1)
assert.deepStrictEqual(sound.options[0].values.map(value => value.value), ["message", "bell", "warning", "complete", "phone"])
assert.ok(settingsSrc.includes("function bindService()"))
assert.ok(settingsSrc.includes("running: root.svc === null"))
assert.ok(settingsSrc.includes("onToggled: hero.toggleAttention()"))
console.log("rules: all tests passed")
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# Verifies that the repeat setting reaches the player, including when a saved
# legacy speed value is present alongside it.
set -euo pipefail
repo=$(cd "$(dirname "$0")/.." && pwd)
log=$(mktemp)
trap 'rm -f -- "$log"' EXIT
pw-play() { printf '%s\n' "$*" >> "$AR_SOUND_LOG"; }
export -f pw-play
# Every UI choice must reach a different system sound through ar-effect.
sounds=(message bell warning complete phone)
files=(message-new-instant.oga bell.oga dialog-warning.oga complete.oga phone-incoming-call.oga)
for i in "${!sounds[@]}"; do
: > "$log"
payload="{\"effect\":{\"type\":\"sound\",\"sound\":\"${sounds[i]}\",\"repeat\":1,\"duration\":0},\"notification\":{},\"rule\":{\"name\":\"test\"}}"
AR_SOUND_LOG="$log" bash "$repo/bin/ar-effect" sound "$payload"
grep -Fqx -- "--volume=1 /usr/share/sounds/freedesktop/stereo/${files[i]}" "$log"
done
# An explicit repeat count wins over a saved legacy speed value.
: > "$log"
payload='{"effect":{"type":"sound","sound":"phone","repeat":3,"speed":1,"duration":0},"notification":{},"rule":{"name":"test"}}'
AR_SOUND_LOG="$log" bash "$repo/bin/ar-effect" sound "$payload"
[[ $(wc -l < "$log") -eq 3 ]]
[[ $(grep -Fxc -- "--volume=1 /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga" "$log") -eq 3 ]]
# Each repeat is separately tempo-adjusted when a duration is selected.
ffprobe() { printf '1\n'; }
ffmpeg() {
printf 'ffmpeg %s\n' "$*" >> "$AR_SOUND_LOG"
printf 'wav'
}
pw-play() {
cat >/dev/null
printf 'pw-play %s\n' "$*" >> "$AR_SOUND_LOG"
}
export -f ffprobe ffmpeg pw-play
: > "$log"
AR_OPT_SOUND=bell \
AR_OPT_DURATION=1 \
AR_OPT_REPEAT=3 \
AR_SOUND_LOG="$log" \
bash "$repo/effects/sound"
[[ $(grep -Fc -- 'ffmpeg -nostdin -v error -i /usr/share/sounds/freedesktop/stereo/bell.oga -filter:a atempo=2,atempo=1.50000000 -f wav -' "$log") -eq 3 ]]
[[ $(grep -Fxc -- 'pw-play --volume=1 -' "$log") -eq 3 ]]
# A longer target duration slows each repetition by the corresponding factor.
: > "$log"
AR_OPT_SOUND=warning \
AR_OPT_DURATION=4 \
AR_OPT_REPEAT=1 \
AR_SOUND_LOG="$log" \
bash "$repo/effects/sound"
grep -Fq -- '-filter:a atempo=0.5,atempo=0.50000000 -f wav -' "$log"
grep -Fqx -- 'pw-play --volume=1 -' "$log"
echo "sound: all tests passed"