diff --git a/packages/omamobile-settings/PKGBUILD b/packages/omamobile-settings/PKGBUILD index cb9f9b41c..9395e74bd 100644 --- a/packages/omamobile-settings/PKGBUILD +++ b/packages/omamobile-settings/PKGBUILD @@ -9,6 +9,7 @@ license=(MIT) depends=(omarchy bash coreutils systemd brightnessctl polkit python qt6-base qt6-declarative qt6-svg) makedepends=(gcc make) checkdepends=(dbus python) +optdepends=('feedbackd: the Keyboard haptics page edits its theme') build() { "$startdir/bin/build"; } check() { "$startdir/test/all"; } diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 3cdd006cd..1aad5d1f8 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -6,8 +6,8 @@ palette and a read-only About page. It shows the model, operating system, kernel architecture, memory, root-filesystem capacity and installed package versions. Unknown values remain unavailable. It opens from the desktop launcher. -This package contains the read-only foundation and one settings page, Display -(brightness and, where the monitor lists more than one, the refresh rate; the +This package contains the read-only foundation and three settings pages. Display +is brightness and, where the monitor lists more than one, the refresh rate (the refresh rate changes the running session only: turning the phone makes auto-rotate apply the monitor's preferred mode again, and a session restart or a reload of Hyprland's config does too). The page runs @@ -36,6 +36,14 @@ row stays hidden today: omamobile-device-husky blacklists `max77759_charger` (`omamobile-max77759.conf`), so there is no `max77759-charger` power supply until that blacklist is lifted on a kernel with derekross/linux-omarchy-mobile#266. +A third page, Keyboard haptics, sets the pattern +feedbackd plays for key presses (low: one light tick; medium: a tick, then a 40 ms gap; high: a stronger tick, then the gap; tried by feel on a Pixel 8 Pro); it +edits the user's feedbackd theme (`~/.config/feedbackd/themes/custom.json`, the +two key entries of the `full` profile, never above 0.125 or 60 ms in total; the first version of the file is kept once as `custom.json.bak-haptics`, a theme that +does not have exactly those two entries is refused before anything changes). It never touches feedbackd's profile, so calls, messages and +alarms ring as before; changing the level restarts feedbackd, so a ring in progress stops. A phone without such a theme (or with one that does not have exactly the two key entries) gets a plain +message on the page and no buttons. That page runs +`backends/haptics.sh` through the same runner. Omarchy's existing tools continue to provide the other settings changes. Network, wallpaper, app management and recording controls are separate future contributions with their own runtime contracts and tests; this catalog does not offer those routes. diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml new file mode 100644 index 000000000..0dac869f8 --- /dev/null +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: MIT +import QtQuick +import QtQuick.Layouts +import "." +ColumnLayout { + id: page + spacing: 14 + property string level: "" + property string status: qsTr("Reading the haptics...") + property bool busy: true + // True once the theme has been read: a phone without the keyboard haptics theme gets no buttons. + property bool available: false + property int reqId: -1 + readonly property var levels: [ + { id: "low", label: qsTr("Low"), hint: qsTr("one light tick") }, + { id: "medium", label: qsTr("Medium"), hint: qsTr("tick, then a short gap") }, + { id: "high", label: qsTr("High"), hint: qsTr("stronger tick, then a short gap") } + ] + function apply(r) { + busy = false + if (r.error) { status = r.error; return } + if (!r.level) { status = qsTr("The haptics backend gave no level."); return } + available = true + level = r.level + status = qsTr("Keyboard tick: %1. Tap a level; it applies at once. Changing it restarts the feedback service, so a ring in progress stops.").arg(level) + } + Connections { target: actions; function onFinished(tool, r, id) { if (tool === "haptics" && id === page.reqId) page.apply(r) } } + Component.onCompleted: reqId = actions.run("haptics", ["get"]) + // Leaving the page drops what was typed; nothing here is ever saved. + Component.onDestruction: { tryField.clear(); if (tryField.activeFocus) Qt.inputMethod.hide() } + Repeater { + model: page.levels + delegate: SettingsButton { + required property var modelData + Layout.fillWidth: true; Layout.preferredHeight: 64 + visible: page.available + // No focus on tap, so the try field keeps the keyboard up while levels are compared. + focusPolicy: Qt.NoFocus + highlighted: page.level === modelData.id; enabled: page.available && !page.busy + onClicked: { page.busy = true; page.reqId = actions.run("haptics", ["set", "level", modelData.id]) } + contentItem: Column { + spacing: 2 + SettingsLabel { text: modelData.label; color: backend.foreground; width: parent.width } + SettingsLabel { text: modelData.hint; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(12); width: parent.width; wrapMode: Text.Wrap } + } + } + } + SettingsTextField { + id: tryField + objectName: "hapticsTryField" + Layout.fillWidth: true; Layout.preferredHeight: 52 + visible: page.available + placeholderText: qsTr("Try it here: type to feel the ticks") + color: backend.foreground; placeholderTextColor: backend.muted + inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhSensitiveData + background: Rectangle { radius: Math.min(backend.radius, width / 2, height / 2); color: SettingsStyle.fill("normal") } + onVisibleChanged: if (!visible) clear() + } + SettingsLabel { text: page.status; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true } + Item { Layout.fillHeight: true } +} diff --git a/packages/omamobile-settings/app/Main.qml b/packages/omamobile-settings/app/Main.qml index 3d4ccd66b..c954aaf54 100644 --- a/packages/omamobile-settings/app/Main.qml +++ b/packages/omamobile-settings/app/Main.qml @@ -24,7 +24,7 @@ ApplicationWindow { if (backend.searching) search.clear() backend.back() } - readonly property var customPages: ({ display: "DisplayPage.qml", battery: "BatteryPage.qml" }) + readonly property var customPages: ({ display: "DisplayPage.qml", battery: "BatteryPage.qml", haptics: "HapticsPage.qml" }) readonly property string customSource: backend.searching ? "" : (customPages[backend.page] || "") readonly property bool showingAbout: backend.page === "about" && !backend.searching Connections { diff --git a/packages/omamobile-settings/app/actionrunner.cpp b/packages/omamobile-settings/app/actionrunner.cpp index 83822926e..022970d76 100644 --- a/packages/omamobile-settings/app/actionrunner.cpp +++ b/packages/omamobile-settings/app/actionrunner.cpp @@ -16,7 +16,7 @@ void ActionRunner::post(const QString &tool, const QVariantMap &result, int id) int ActionRunner::run(const QString &tool, const QStringList &args) { static const QRegularExpression word("\\A[a-z0-9]{1,16}\\z"); - static const QStringList tools = {"display", "charge"}; + static const QStringList tools = {"display", "charge", "haptics"}; const int id = ++m_next; auto fail = [this, &tool, id](const QString &why) { post(tool, {{"error", why}}, id); return id; }; if (!tools.contains(tool) || args.size() > 3) return fail("unknown action"); diff --git a/packages/omamobile-settings/app/actionrunner.h b/packages/omamobile-settings/app/actionrunner.h index 3ebe43868..cdd519621 100644 --- a/packages/omamobile-settings/app/actionrunner.h +++ b/packages/omamobile-settings/app/actionrunner.h @@ -4,7 +4,7 @@ #include #include -// Runs the source-owned backend scripts (display, charge) with a fixed argument list and no shell. Pages call run(); +// Runs the source-owned backend scripts (display, charge, haptics) with a fixed argument list and no shell. Pages call run(); // the JSON the script prints comes back through finished(), always from the event loop and never before run() // has returned its id. class ActionRunner : public QObject { diff --git a/packages/omamobile-settings/app/catalog.json b/packages/omamobile-settings/app/catalog.json index 35b266a24..7201f8063 100644 --- a/packages/omamobile-settings/app/catalog.json +++ b/packages/omamobile-settings/app/catalog.json @@ -17,6 +17,13 @@ "page": "battery", "requires": "charge" }, + { + "id": "haptics", + "title": "Keyboard haptics", + "detail": "Strength of the keyboard tick", + "icon": "haptics", + "page": "haptics" + }, { "id": "about", "title": "About this device", @@ -37,5 +44,9 @@ "battery": { "title": "Battery", "rows": [] + }, + "haptics": { + "title": "Keyboard haptics", + "rows": [] } } diff --git a/packages/omamobile-settings/app/icons/haptics.svg b/packages/omamobile-settings/app/icons/haptics.svg new file mode 100644 index 000000000..972c941a8 --- /dev/null +++ b/packages/omamobile-settings/app/icons/haptics.svg @@ -0,0 +1 @@ + diff --git a/packages/omamobile-settings/app/resources.qrc b/packages/omamobile-settings/app/resources.qrc index 27e14cec7..a5f13ec18 100644 --- a/packages/omamobile-settings/app/resources.qrc +++ b/packages/omamobile-settings/app/resources.qrc @@ -6,6 +6,8 @@ DisplayPage.qml BatteryPage.qml icons/battery.svg + HapticsPage.qml + icons/haptics.svg icons/display.svg catalog.json icons/system.svg diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh new file mode 100755 index 000000000..b2cbb65ba --- /dev/null +++ b/packages/omamobile-settings/backends/haptics.sh @@ -0,0 +1,148 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Keyboard haptics level: probe/get/set. The level is the pattern feedbackd plays for key and +# button presses. It lives in the user's feedbackd theme ($XDG_CONFIG_HOME/feedbackd/themes/custom.json, entries +# button-pressed and key-pressed of the "full" profile); where that theme comes from is the keyboard haptics notes in +# https://github.com/derekross/omarchy-mobile/issues/538. Levels (motor level of 255 in brackets): +# low: one 0.015 tick (3, the lowest) for 15 ms; +# medium: 0.07 (17) for 15 ms, then 0 for 40 ms; +# high: 0.1 (25) for 15 ms, then the same 40 ms gap. +# The gap levels were tried by feel on a Pixel 8 Pro (2026-11-19). +# Nothing above 0.125 and no pattern longer than 60 ms in total is ever written. +# Only the two key entries of the theme are written. feedbackd's profile, and so whether calls, messages and alarms +# ring, is never touched here: a keyboard page does not change that. Changing the level restarts feedbackd (a ring +# in progress stops). +# The theme directory comes from XDG_CONFIG_HOME, else HOME; nothing else in the environment is read (python3 is +# called by its absolute path, the helper tools by PATH). The test runs a copy +# of this script with `dry=1`, which skips feedbackd and the preview tick. The theme file is checked (exactly the +# two key entries in the full profile) before anything is changed. +set -euo pipefail +dry=0 +dir=${XDG_CONFIG_HOME:-$HOME/.config}/feedbackd/themes +file=$dir/custom.json +cap=0.125 +verb=${1:-} +key=${2:-} +value=${3:-} + +fail() { printf '%s\n' "$1"; exit 2; } + +level_pair() { + case $1 in + low) echo "0.015 15" ;; + medium) echo "0.07,0 15,40" ;; + high) echo "0.1,0 15,40" ;; + *) return 1 ;; + esac +} + +# Prints the level; exit 3: the theme does not have exactly the two key entries (the same rule set applies); +# exit 4: it cannot be read as a theme. +current_level() { + /usr/bin/python3 -I - "$file" <<'PY' +import json, sys +try: + d = json.load(open(sys.argv[1])) + pairs = [] + for p in d["profiles"]: + if p["name"] != "full": + continue + for f in p["feedbacks"]: + if f.get("type") == "VibraPattern" and f["event-name"] in ("button-pressed", "key-pressed"): + pairs.append((tuple(f["magnitudes"]), tuple(f["durations"]))) +except Exception: + sys.exit(4) +if len(pairs) != 2: + sys.exit(3) +names = {((0.015,), (15,)): "low", ((0.07, 0), (15, 40)): "medium", ((0.1, 0), (15, 40)): "high"} +if pairs[0] == pairs[1] and pairs[0] in names: + print(names[pairs[0]]) +else: + print("custom") +PY +} + +case $verb in +probe) + if [[ -r $file ]] && current_level >/dev/null 2>&1; then + printf '{"id":"haptics","state":"working","reason":"","risk":"none"}\n' + else + printf '{"id":"haptics","state":"unavailable","reason":"no keyboard haptics theme on this phone","risk":"none"}\n' + exit 2 + fi + ;; +get) + [[ -r $file ]] || fail '{"error":"no keyboard haptics theme on this phone"}' + rc=0; lvl=$(current_level) || rc=$? + case $rc in + 0) ;; + 3) fail '{"error":"the haptics theme does not have the two key entries"}' ;; + *) fail '{"error":"the haptics theme could not be read"}' ;; + esac + printf '{"level":"%s"}\n' "$lvl" + ;; +set) + [[ $key == level ]] || fail '{"error":"unknown key"}' + pair=$(level_pair "$value") || fail '{"error":"bad value"}' + mag=${pair% *}; ms=${pair#* } + # defence in depth: the table above can never exceed the cap or 60 ms in total + /usr/bin/python3 -I -c "import sys; m=[float(x) for x in '$mag'.split(',')]; d=[int(x) for x in '$ms'.split(',')]; sys.exit(0 if len(m) == len(d) and all(0 <= x <= $cap for x in m) and all(x > 0 for x in d) and sum(d) <= 60 else 1)" || fail '{"error":"above the safety cap"}' + [[ -e $file ]] || fail '{"error":"no keyboard haptics theme on this phone"}' + [[ -w $file ]] || fail '{"error":"theme file not writable"}' + edit() { /usr/bin/python3 -I - "$file" "$mag" "$ms" "$1" <<'PY' +import json, os, sys, tempfile +path, mode = sys.argv[1], sys.argv[4] +mag = [float(x) for x in sys.argv[2].split(",")] +ms = [int(x) for x in sys.argv[3].split(",")] +try: + d = json.load(open(path)) + n = 0 + for p in d["profiles"]: + if p["name"] != "full": + continue + for f in p["feedbacks"]: + if f.get("type") == "VibraPattern" and f["event-name"] in ("button-pressed", "key-pressed"): + f["magnitudes"] = mag + f["durations"] = ms + n += 1 +except Exception: + n = -1 +if n != 2: + print('{"error":"the haptics theme does not have the two key entries"}') + sys.exit(2) +if mode == "write": + real = os.path.realpath(path) + fd, tmp = tempfile.mkstemp(dir=os.path.dirname(real)) + try: + with os.fdopen(fd, "w") as out: + json.dump(d, out, indent=2) + out.flush() + os.fsync(out.fileno()) + os.chmod(tmp, os.stat(real).st_mode & 0o7777) + os.replace(tmp, real) + except BaseException: + try: + os.unlink(tmp) + except OSError: + pass + print('{"error":"could not write the haptics theme"}') + sys.exit(2) +PY + } + # nothing is changed until the theme is known to be what this edit expects + edit check || exit 2 + [[ -e $file.bak-haptics ]] || cp -p "$file" "$file.bak-haptics" || fail '{"error":"could not keep a copy of the haptics theme"}' + edit write || exit 2 + if [[ $dry != 1 ]]; then + # feedbackd reads the theme when it starts; D-Bus starts it again on the next event. Exact name only. + for p in $(pgrep -u "$(id -u)" -x feedbackd || true); do kill "$p" 2>/dev/null || true; done + sleep 1 + # fbcli ends the feedback when its input closes, and the shell gives it none: keep it open for one pulse. + sleep 0.02 | fbcli -E button-pressed -w 1 >/dev/null 2>&1 || true + fi + printf '{"level":"%s"}\n' "$value" + ;; +*) + fail '{"error":"usage: probe|get|set"}' + ;; +esac diff --git a/packages/omamobile-settings/install b/packages/omamobile-settings/install index 6847708ce..8d1716384 100755 --- a/packages/omamobile-settings/install +++ b/packages/omamobile-settings/install @@ -15,3 +15,4 @@ install -Dm755 "$source_dir/backends/charge.sh" "$dest/usr/lib/omamobile-setting install -Dm755 "$source_dir/libexec/charge-limit" "$dest/usr/lib/omamobile-settings/charge-limit" install -Dm644 "$source_dir/vendor/systemd/system/omamobile-charge-limit@.service" "$dest/usr/lib/systemd/system/omamobile-charge-limit@.service" install -Dm644 "$source_dir/vendor/polkit/50-omamobile-charge-limit.rules" "$dest/usr/share/polkit-1/rules.d/50-omamobile-charge-limit.rules" +install -Dm755 "$source_dir/backends/haptics.sh" "$dest/usr/lib/omamobile-settings/backends/haptics.sh" diff --git a/packages/omamobile-settings/test/all b/packages/omamobile-settings/test/all index a8623d42a..653229fae 100755 --- a/packages/omamobile-settings/test/all +++ b/packages/omamobile-settings/test/all @@ -6,6 +6,7 @@ build_dir=${OMAMOBILE_SETTINGS_TEST_BUILD_DIR:-"$source_dir/build/tests"} "$source_dir/bin/build" "$source_dir/test/display-backend.sh" "$source_dir/test/charge-backend.sh" +"$source_dir/test/haptics-backend.sh" mkdir -p "$build_dir" fixture=$(mktemp -d) trap 'rm -rf -- "$fixture"' EXIT HUP INT TERM diff --git a/packages/omamobile-settings/test/haptics-backend.sh b/packages/omamobile-settings/test/haptics-backend.sh new file mode 100755 index 000000000..ffd793e58 --- /dev/null +++ b/packages/omamobile-settings/test/haptics-backend.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# backends/haptics.sh against a temporary feedbackd theme (XDG_CONFIG_HOME), in a copy of the script with dry=1, +# so feedbackd and fbcli are never called. +set -euo pipefail +src=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) +tmp=$(mktemp -d); trap 'rm -rf -- "$tmp"' EXIT +mkdir -p "$tmp/config/feedbackd/themes" +dir=$tmp/config/feedbackd/themes +export XDG_CONFIG_HOME=$tmp/config +sed 's/^dry=0/dry=1/' "$src/backends/haptics.sh" > "$tmp/haptics.sh" +grep -q '^dry=1' "$tmp/haptics.sh" +cat > "$dir/custom.json" <<'EOT' +{"name":"custom","profiles":[{"name":"full","feedbacks":[ + {"event-name":"button-pressed","type":"VibraPattern","magnitudes":[0.015],"durations":[15]}, + {"event-name":"key-pressed","type":"VibraPattern","magnitudes":[0.015],"durations":[15]}, + {"event-name":"message-new-instant","type":"Sound","effect":"message-new-instant"}]}]} +EOT +run() { bash "$tmp/haptics.sh" "$@" || true; } +eq() { [[ $1 == "$2" ]] || { echo "FAIL: got $1, want $2" >&2; exit 1; }; } + +# the full magnitudes and durations of both key entries, for every level +pat() { /usr/bin/python3 -I -c 'import json,sys; print(sorted({(tuple(f["magnitudes"]),tuple(f["durations"])) for p in json.load(open(sys.argv[1]))["profiles"] for f in p["feedbacks"] if f.get("type")=="VibraPattern"}))' "$dir/custom.json"; } +eq "$(pat)" '[((0.015,), (15,))]' +eq "$(run get)" '{"level":"low"}' +eq "$(run set level medium)" '{"level":"medium"}' +eq "$(run get)" '{"level":"medium"}' +eq "$(pat)" '[((0.07, 0.0), (15, 40))]' +eq "$(run set level high)" '{"level":"high"}' +eq "$(pat)" '[((0.1, 0.0), (15, 40))]' +# "off" is not a level here: it would be the phone-wide silent profile, which this page never touches +eq "$(run set level off)" '{"error":"bad value"}' +eq "$(run get)" '{"level":"high"}' +eq "$(run set level low)" '{"level":"low"}' +eq "$(pat)" '[((0.015,), (15,))]' +eq "$(run get)" '{"level":"low"}' +eq "$(run set level loud)" '{"error":"bad value"}' +eq "$(run set level 0.5)" '{"error":"bad value"}' +eq "$(run set strength low)" '{"error":"unknown key"}' +eq "$(run nonsense)" '{"error":"usage: probe|get|set"}' +# nothing above the cap is ever in the theme, and the sound entry is left alone +python3 - "$dir/custom.json" <<'PY' +import json, sys +d = json.load(open(sys.argv[1])) +fb = d["profiles"][0]["feedbacks"] +assert all(all(0 <= m <= 0.125 for m in f["magnitudes"]) and sum(f["durations"]) <= 60 for f in fb if f["type"] == "VibraPattern") +assert any(f["type"] == "Sound" for f in fb) +PY +# the mode of the file is kept, and the first theme is saved once +[[ $(stat -c %a "$dir/custom.json") == 644 ]] || { chmod 644 "$dir/custom.json"; run set level high >/dev/null; [[ $(stat -c %a "$dir/custom.json") == 644 ]]; } +[[ -e $dir/custom.json.bak-haptics ]] +# a theme with one key entry is refused before anything is touched, by set and by get +cp "$dir/custom.json" "$tmp/good.json" +python3 - "$dir/custom.json" <<'PY' +import json, sys +d = json.load(open(sys.argv[1])) +d["profiles"][0]["feedbacks"] = [f for f in d["profiles"][0]["feedbacks"] if f["event-name"] != "key-pressed"] +json.dump(d, open(sys.argv[1], "w")) +PY +before=$(sha256sum "$dir/custom.json") +eq "$(run set level medium)" '{"error":"the haptics theme does not have the two key entries"}' +[[ $(sha256sum "$dir/custom.json") == "$before" ]] +eq "$(run get)" '{"error":"the haptics theme does not have the two key entries"}' +[[ $(run probe) == *'"state":"unavailable"'* ]] || { echo "FAIL: probe says working on a one-entry theme" >&2; exit 1; } +# a theme that is not JSON at all +echo "{ not json" > "$dir/custom.json" +eq "$(run get)" '{"error":"the haptics theme could not be read"}' +[[ $(run probe) == *'"state":"unavailable"'* ]] || { echo "FAIL: probe says working on a broken theme" >&2; exit 1; } +cp "$tmp/good.json" "$dir/custom.json" +eq "$(run probe)" '{"id":"haptics","state":"working","reason":"","risk":"none"}' +# a theme that is not there: a plain message, no crash, nothing is created, no level can be set +rm "$dir/custom.json" "$dir/custom.json.bak-haptics" +eq "$(run get)" '{"error":"no keyboard haptics theme on this phone"}' +eq "$(run set level medium)" '{"error":"no keyboard haptics theme on this phone"}' +[[ ! -e $dir/custom.json && ! -e $dir/custom.json.bak-haptics ]] +echo "haptics backend: ok" diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index b87a721ce..39eb36d1b 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -4,6 +4,7 @@ #include "deviceinfocontroller.h" #include "actionrunner.h" #include +#include #include #include #include @@ -31,22 +32,22 @@ private slots: void probeShowsTheBatteryRowOnlyWhenTheBackendSaysAvailable() { Backend on; on.setBackendDir(stubs("on")); - QCOMPARE(on.rows().size(), 2); - QTRY_COMPARE(on.rows().size(), 3); + QCOMPARE(on.rows().size(), 3); + QTRY_COMPARE(on.rows().size(), 4); Backend off; off.setBackendDir(stubs("off")); off.setToolAvailable("charge", true); - QTRY_COMPARE(off.rows().size(), 2); // the probe's answer clears it + QTRY_COMPARE(off.rows().size(), 3); // the probe's answer clears it } void navigationRejectsUnknownAndHiddenActions() { Backend backend; backend.setBackendDir(stubs("off")); QVERIFY(backend.catalogProblems().isEmpty()); - QCOMPARE(backend.rows().size(), 2); // the Battery row waits for the charge backend, absent here + QCOMPARE(backend.rows().size(), 3); // the Battery row waits for the charge backend, absent here backend.setToolAvailable("charge", true); - QCOMPARE(backend.rows().size(), 3); + QCOMPARE(backend.rows().size(), 4); backend.setToolAvailable("charge", false); - QCOMPARE(backend.rows().size(), 2); + QCOMPARE(backend.rows().size(), 3); QVERIFY(!backend.navigate("recording")); backend.activate("arbitrary-command"); QCOMPARE(backend.page(), QString("root")); @@ -134,6 +135,40 @@ private slots: QMetaObject::invokeMethod(page.get(), "apply", QVariant(QVariantMap{{"available", false}})); QCOMPARE(page->property("status").toString(), QString("Settings cannot set a charge limit on this phone.")); } + void hapticsPageGoesBackToRoot() { + Backend backend; + backend.setBackendDir(stubs("off")); + QVERIFY(backend.navigate("haptics")); + QCOMPARE(backend.page(), QString("haptics")); + backend.back(); + QCOMPARE(backend.page(), QString("root")); + } + void hapticsTryFieldExistsAndIsClearedOnLeaving() { + Backend backend; + backend.setBackendDir(stubs("off")); + backend.setHomeCommand({}); + ActionRunner runner; + runner.setBackendDir(stubs("off")); + DeviceInfoController info(true); + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("actions", &runner); + engine.rootContext()->setContextProperty("deviceInfo", &info); + engine.load(QUrl("qrc:/Main.qml")); + QCOMPARE(engine.rootObjects().size(), 1); + auto *window = engine.rootObjects().first(); + QVERIFY(backend.navigate("haptics")); + QTRY_VERIFY(window->findChild("hapticsTryField")); + QPointer field = window->findChild("hapticsTryField"); + field->setProperty("text", "typed"); + QCOMPARE(field->property("text").toString(), QString("typed")); + QVERIFY(QMetaObject::invokeMethod(window, "goBack")); + QCOMPARE(backend.page(), QString("root")); + QTRY_VERIFY(!field || field->property("text").toString().isEmpty()); + QVERIFY(backend.navigate("haptics")); + QTRY_VERIFY(window->findChild("hapticsTryField")); + QCOMPARE(window->findChild("hapticsTryField")->property("text").toString(), QString()); + } void searchHasOnlyImplementedRoutesAndBackClearsIt() { Backend backend; backend.setBackendDir(stubs("off")); diff --git a/packages/omamobile-settings/version b/packages/omamobile-settings/version index b1e80bb24..845639eef 100644 --- a/packages/omamobile-settings/version +++ b/packages/omamobile-settings/version @@ -1 +1 @@ -0.1.3 +0.1.4