diff --git a/packages/omamobile-shell/README.md b/packages/omamobile-shell/README.md index 71f4ac874..e805d08d3 100644 --- a/packages/omamobile-shell/README.md +++ b/packages/omamobile-shell/README.md @@ -103,3 +103,7 @@ Open, save and choose-a-folder requests through the portal (Qt, GTK, Electron an The package contract follows omarchy-mac's: `./install DESTDIR` stages files and enables nothing, `test/all` runs the package's own tests, and `version` holds the version. Develop on a desktop with `phone/dev/run-desktop` from the repo root. + +## Device settings + +After the shared rules, `hypr/phone.lua` loads `/usr/share/omamobile/hypr/device.lua` if a device package installs one, for settings only that phone needs (an inner and an outer panel, its own input devices). Every session that loads `phone.lua` (setup-user adds it to `looknfeel.lua`) gets it, new and existing users alike. It runs under `pcall`: a syntax or runtime error in the device file is logged and the shared rules stay in force. With no device file nothing changes, so every phone today is unaffected. diff --git a/packages/omamobile-shell/hypr/phone.lua b/packages/omamobile-shell/hypr/phone.lua index 08ae4f943..c21dc9d94 100644 --- a/packages/omamobile-shell/hypr/phone.lua +++ b/packages/omamobile-shell/hypr/phone.lua @@ -247,3 +247,14 @@ elseif o.cmd_present("voxtype") then { "Stop dictation (push-to-talk)", "voxtype record stop", { release = true } }, }) end + +-- Device packages may add their own session settings in one optional file, +-- loaded after the shared rules above. pcall: a broken device file logs its +-- error and the shared rules stay in force. No file, no change. +local device_hook = "/usr/share/omamobile/hypr/device.lua" +local device_file = io.open(device_hook, "r") +if device_file then + device_file:close() + local ok, err = pcall(dofile, device_hook) + if not ok then print("omamobile: " .. device_hook .. ": " .. tostring(err)) end +end diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 0b80220d4..d6efa4d36 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -1030,6 +1030,11 @@ lua=$(command -v lua || command -v lua5.4 || command -v luajit || true) if [[ -n $lua ]]; then out=$("$lua" test/phone-rules.lua) || { grep -v '^ok' <<<"$out"; fail "phone.lua window rules"; } pass "phone.lua: edge to edge, opaque, dialogs, picture-in-picture" + # The optional device.lua: a broken one is reported, the shared rules stand. + for hook in valid syntax runtime; do + out=$(DEVICE_HOOK_CASE=$hook "$lua" test/phone-rules.lua) || { grep -v '^ok' <<<"$out"; fail "phone.lua with a $hook device.lua"; } + done + pass "phone.lua: device.lua runs after the shared rules, and an error in it leaves them standing" # Dictation keys under Omarchy 4.5's helpers: four homes, four bindings.lua dk=$(mktemp -d) mkdir -p "$dk/plain/.config/hypr" "$dk/migrated/.config/hypr" "$dk/own/.config/hypr" diff --git a/packages/omamobile-shell/test/phone-rules.lua b/packages/omamobile-shell/test/phone-rules.lua index 80340ba78..9bc844034 100644 --- a/packages/omamobile-shell/test/phone-rules.lua +++ b/packages/omamobile-shell/test/phone-rules.lua @@ -42,7 +42,29 @@ o = { o.bind("CTRL + ALT + DELETE", "Close all windows", "omarchy-hyprland-window-close-all") o.bind("ALT + TAB", "Focus on next window", hl.dsp.window.cycle_next()) o.bind("F9", "Start dictation (push-to-talk)", "voxtype record start") +-- The optional device hook (/usr/share/omamobile/hypr/device.lua), with no +-- file, a valid one, a syntax error and a runtime error (DEVICE_HOOK_CASE). +-- Only that one path is redirected, to a temporary file; with no case set +-- the hook path reads as absent, so no file on the host takes part. +local hook_case = os.getenv("DEVICE_HOOK_CASE") or "absent" +local real_open, real_dofile = io.open, dofile +local hook_path = "/usr/share/omamobile/hypr/device.lua" +local hook_tmp = os.tmpname() +local hook_source = { + valid = "omamobile_hook_ran = true", + syntax = "this is not Lua!", + runtime = 'error("fixture device error")', +} +os.remove(hook_tmp) +if hook_source[hook_case] then + local f = assert(real_open(hook_tmp, "w")) + f:write(hook_source[hook_case]); f:close() +end +io.open = function(path, ...) return real_open(path == hook_path and hook_tmp or path, ...) end +dofile = function(path) return real_dofile(path == hook_path and hook_tmp or path) end dofile("hypr/phone.lua") +io.open, dofile = real_open, real_dofile +os.remove(hook_tmp) local failed = false local function check(ok, what) @@ -158,4 +180,7 @@ check(#find("ALT + TAB") == 2 and find("ALT + TAB")[1].dispatcher.dsp == "cycle_ local f9 = find("F9", true) check(#f9 == 1 and f9[1].dispatcher == "voxtype record stop", "F9 still stops Voxtype on release") +check(omamobile_hook_ran == (hook_case == "valid" or nil), + "device hook (" .. hook_case .. "): runs only when valid, and the shared rules stand") + os.exit(failed and 1 or 0) diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 3abec2f78..9221c8c4f 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.134 +0.2.135