From ce084bdb2b07789ca3fa688fd3ebc149488b69d0 Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Tue, 10 Nov 2026 13:06:19 -0600 Subject: [PATCH 1/5] omamobile-shell: share once-only Chromium and Grok fitting Use one internal-output geometry path and the established 578 px layout target. Preserve historical setup markers, custom flags and intentional removals; migrate only the generated 0.83 line once. Query Chromium version only when writing a missing UA. Defer Chrome until its quote-aware launcher is released. Focused tests and scratch-home login checks cover migration, quoting, geometry, deliberately removed flags and divergent XDG variables. Full-package phone and reference-device checks remain gates. Package version is assigned by the maintainer at merge as requested on #581. Co-Authored-By: Codex --- docs/TOUCH-PLAN.md | 38 ++++ packages/omamobile-shell/README.md | 25 +++ .../bin/omamobile-browser-setup | 146 ++++++++++++++ .../omamobile-shell/bin/omamobile-setup-user | 79 +------- .../plugins/omamobile.bar/Bar.qml | 7 + packages/omamobile-shell/test/all | 1 + .../omamobile-shell/test/browser-setup.py | 186 ++++++++++++++++++ packages/omamobile-shell/test/setup-user.sh | 38 +++- 8 files changed, 444 insertions(+), 76 deletions(-) create mode 100755 packages/omamobile-shell/bin/omamobile-browser-setup create mode 100644 packages/omamobile-shell/test/browser-setup.py diff --git a/docs/TOUCH-PLAN.md b/docs/TOUCH-PLAN.md index 38ad3136e..489848f39 100644 --- a/docs/TOUCH-PLAN.md +++ b/docs/TOUCH-PLAN.md @@ -62,6 +62,44 @@ Priorities: **P1** broken, unsafe, or a dead end on a phone; **P2** noticeably a - **3.6 Haptics (P3):** none in the shell. A small helper for long-press, the switcher hold and the answer threshold (cs40l26 exists). It buzzes: announce before testing. - **3.7 Polish (P3):** QS edit mode's "−" badges and Reset confirm; Wi-Fi/Bluetooth Forget confirm or undo; "Added to home" feedback after a drawer long-press; the missing-app tile says "Not installed" instead of its raw id; switcher cards show the app's name, not its id (0.2.43: the desktop entry's name, web apps included, centred over a card that snaps to the centre); OWL slider drags only on their own axis; a fade on the drawer's clipped last row; a safe-area token for the rounded corners; a pull-down strip over fullscreen apps; a Gestures table in the shell README. +## Shared Chromium and Grok Bot fitting revision, 2026-11-10 (3.1) + +Candidate only; no new phone result. Both apps now share the established +578 px layout target and internal geometry detection, including simpledrm. +The 7 Pro's 480 logical px retains 0.83, the 9a's 405 gets 0.70, and the +6a's 360 gets 0.62 for a fresh default. The owner's custom 0.70 and site +zoom stay unchanged. Historical setup markers preserve deleted flags; +defaults and the exact generated-scale migration run once. Chrome is deferred +until the launcher prerequisite is released. The maintainer assigns the +package version at merge. + +Geometry-free Chromium defaults run even before panel geometry is available; +only the scale waits. A separate defaults marker preserves removals before +the phone bar retries the helper at shell start with live monitor geometry, +including computed/auto Lua scales. A failed helper never aborts user setup. + +Runbook (low risk, userspace only): + +1. Run the shell package suite and policy gate. Expect no failures; stop on + any new failure. Save the installed package, both apps' flags, all + `omamobile-chromium-*`, `omamobile-grok-bot-fit` and + `omamobile-browser-fit-*` and `omamobile-browser-defaults-*` markers, and the + user's shell profile/plugins. +2. Announce the package installation and browser restart. Install the full + candidate package. Run user setup and inspect flags: custom 0.70 and UA/IME + removals must survive; fresh scratch defaults at 360 px must be 0.62 for + both apps. Stop and restore if a user override changes. +3. Reopen through normal desktop/browser and web-app entry points. Expect a + complete UA as one argument, working keyboard input, and equal viewport, + client and scroll widths on the diagnostic page. Check Gmail's saved zoom + and the personal transparent clock. Stop on overflow or lost settings. +4. Rollback: restore the prior package, flags, done markers and shell profile + and plugins, restart the shell if needed and reopen the apps normally. + +Full-package 6a checks and the 9a owner's migration check remain required; +the maintainer will validate the 7 Pro. No kernel or boot image is involved. + + ## Omarchy patches this needs (upstreamable) 1. Notifications: swipe to dismiss and a touch close button (1.1). Patch 0017, omamobile-omarchy 0.1.10 (built and tested offline, not yet checked on the phone). The shade under quick settings lists the toasts and history, and a sideways swipe on a row forgets that one notification through the service (patch 0019, omamobile-omarchy 0.1.11, omamobile-shell 0.2.28; offline as above). diff --git a/packages/omamobile-shell/README.md b/packages/omamobile-shell/README.md index 71f4ac874..c4e5b9512 100644 --- a/packages/omamobile-shell/README.md +++ b/packages/omamobile-shell/README.md @@ -103,3 +103,28 @@ 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. + +### Chromium and Grok Bot sizing + +`omamobile-browser-setup`, called by user setup and again by the phone bar at +shell start, fits both apps to the same +578 px layout from the internal output's short logical side. It keeps the +reference phone's 0.83 cap: 480 px gives 0.83, 405 px gives 0.70 and 360 px +gives 0.62. Geometry comes from Hyprland when available, or an internal DRM +mode plus the numeric scale in `hypr/monitors.lua` before the compositor runs. +DSI, eDP and simpledrm's Unknown outputs are supported; external outputs are +ignored. Missing geometry defers only the scale factor. Chromium's user agent, +input-method and no-first-run defaults are written independently. The shell +retry obtains live geometry for an auto or computed Lua scale; helper failure +does not stop the remaining user setup. + +Defaults run once, tracked by `omamobile-browser-fit-chromium` and +`omamobile-browser-fit-grok-bot` in Omarchy's done directory, with +`omamobile-browser-defaults-chromium` preserving removals while scale is +deferred. Old Chromium +per-feature markers also count: deleting a mobile UA, input-method flag or +scale after its original setup remains a user choice. Only the exact generated, +unquoted 0.83 scale line migrates once; custom values and quoted overrides +stay. Chromium's version is read only immediately before writing a missing UA. +No browser profile or site zoom changes. Chrome defaults are deferred until +its quote-aware launcher is released separately in omarchy-pkgs. diff --git a/packages/omamobile-shell/bin/omamobile-browser-setup b/packages/omamobile-shell/bin/omamobile-browser-setup new file mode 100755 index 000000000..9d3461cfe --- /dev/null +++ b/packages/omamobile-shell/bin/omamobile-browser-setup @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Seed mobile browser flags from the phone's geometry, preserving user choices.""" +import json +import math +import os +from pathlib import Path +import re +import shlex +import subprocess + + +def monitor_scale(text): + match = re.search(r"^local omarchy_monitor_scale = ([0-9.]+)(?:\s*/\s*([0-9.]+))?\s*(?:--[^\n]*)?$", text, re.M) + if not match: + return None + try: + value = float(match[1]) / float(match[2] or 1) + return value if math.isfinite(value) and value > 0 else None + except (ValueError, ZeroDivisionError): + return None + + +def logical_width(monitors): + widths = [] + for monitor in monitors: + if monitor.get("disabled") or not re.match(r"^(DSI|eDP|Unknown)-", monitor.get("name", "")): + continue + try: + width = min(float(monitor["width"]), float(monitor["height"])) / float(monitor["scale"]) + if math.isfinite(width) and width > 0: + widths.append(width) + except (KeyError, TypeError, ValueError, ZeroDivisionError): + continue + return min(widths) if widths else None + + +def geometry(config): + # Live compositor data honours the user's scale and works on simpledrm. + try: + result = subprocess.run(["hyprctl", "monitors", "-j"], capture_output=True, text=True, check=True, timeout=2) + width = logical_width(json.loads(result.stdout)) + if width: + return width + except (OSError, subprocess.SubprocessError, ValueError, TypeError, AttributeError): + pass + # Firstboot runs before Hyprland. Read the numeric scale setup-user seeded; + # never execute Lua to find it. Unknown/auto scales wait for a live session. + try: + scale = monitor_scale((config / "hypr/monitors.lua").read_text()) + if scale: + drm = Path(os.environ.get("OMAMOBILE_DRM", "/sys/class/drm")) + widths = [] + for modes in sorted(drm.glob("card*-*/modes")): + if not re.match(r"card\d+-(DSI|eDP|Unknown)-", modes.parent.name): + continue + match = re.match(r"(\d+)x(\d+)", modes.read_text()) + if match: + widths.append(min(int(match[1]), int(match[2])) / scale) + return min(widths) if widths else None + except (OSError, ValueError): + pass + return None + + +def factor_for(width): + # Use Grok Bot's established 578 px layout for both Chromium and Electron, + # above their minimum widths. Keep the reference phone's 0.83 cap: + # 480 px -> 0.83, 405 px -> 0.70, 360 px -> 0.62. Site zoom is separate. + return f"{math.floor(min(0.83, width / 578) * 100) / 100:.2f}" + + +def browser_major(program): + try: + version = subprocess.run([program, "--version"], capture_output=True, text=True, check=True, timeout=2).stdout + match = re.search(r"\b(\d+)\.", version) + return match[1] if match else "153" + except (OSError, subprocess.SubprocessError): + return "153" # Historical first-login fallback; never query on later logins. + + +def configure(path, factor, done, program): + chromium = program == "chromium" + marker = done / ("omamobile-browser-fit-" + program) + if marker.exists(): + return + if not chromium and factor is None: + return # Grok has only a geometry-dependent scale default. + defaults_marker = done / "omamobile-browser-defaults-chromium" + before = path.read_text() if path.exists() else "" + flags = shlex.split(before, comments=True) + has = lambda key: any(flag.split("=")[0] == key for flag in flags) + prior = lambda name: (done / ("omamobile-" + name)).exists() + scale_marked = (prior("chromium-scale-2") or prior("chromium-scale-3")) if chromium else prior("grok-bot-fit") + scale_flags = [f for f in flags if f.startswith("--force-device-scale-factor=")] + after = before + if factor is not None and scale_marked and scale_flags == ["--force-device-scale-factor=0.83"]: + # Only the exact unquoted line written by historical setup. Custom + # values, quoted overrides and a deliberately deleted scale stay put. + after = re.sub(r"^--force-device-scale-factor=0\.83$", f"--force-device-scale-factor={factor}", after, flags=re.M) + additions = [] + if factor is not None and not scale_marked and not has("--force-device-scale-factor"): + additions.append(f"--force-device-scale-factor={factor}") + if chromium and not defaults_marker.exists(): + for name, defaults in ( + ("chromium-no-first-run", ("--no-first-run",)), + ("chromium-wayland-ime", ("--enable-wayland-ime", "--wayland-text-input-version=3")), + ): + if not prior(name): + additions.extend(flag for flag in defaults if not has(flag.split("=")[0])) + if not prior("chromium-mobile") and not has("--user-agent"): + # Do this only immediately before writing a missing, once-only UA. + major = browser_major(program) + additions.append(shlex.quote(f"--user-agent=Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{major}.0.0.0 Mobile Safari/537.36")) + if additions: + after += ("\n" if after and not after.endswith("\n") else "") + "\n".join(additions) + "\n" + if after != before: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(after) + done.mkdir(parents=True, exist_ok=True) + if chromium: + defaults_marker.touch() + if factor is not None: + marker.touch() + + +def main(): + config = Path.home() / ".config" + done = Path.home() / ".local/state/omarchy/done" + programs = (("chromium", "chromium-flags.conf"), ("grok-bot", "grok-bot-flags.conf")) + if all((done / ("omamobile-browser-fit-" + program)).exists() for program, _ in programs): + return # No geometry or browser process at subsequent logins. + width = geometry(config) + # UA, input method and first-run defaults do not need geometry. The bar + # retries at shell start, with live compositor data, for computed/auto Lua + # scales. Their separate marker preserves removals before that retry too. + factor = factor_for(width) if width and width >= 128 else None + for program, filename in programs: + try: + configure(config / filename, factor, done, program) + except (OSError, ValueError) as error: + print(f"omamobile-browser-setup: {filename}: {error}", file=__import__("sys").stderr) + + +if __name__ == "__main__": + main() diff --git a/packages/omamobile-shell/bin/omamobile-setup-user b/packages/omamobile-shell/bin/omamobile-setup-user index a8e0ba60a..7194132fd 100755 --- a/packages/omamobile-shell/bin/omamobile-setup-user +++ b/packages/omamobile-shell/bin/omamobile-setup-user @@ -15,7 +15,7 @@ set -euo pipefail # runs as on a new user: most check the user's files first (the menu # entries, foot's touch lines, phone.lua, the idle block), and a few # change what is there (they add the missing phone plugins to shell.json, -# replace Chromium's user agent and scale factor, and set the suspend and +# migrate Chromium's generated scale factor once, and set the suspend and # lock toggles). A marked # step the user does want can be had by removing its marker from # ~/.local/state/omarchy/done/ before the next login. @@ -310,24 +310,6 @@ LUA fi fi -# Chromium's first-run dialogs are desktop-sized: their buttons land off a -# phone screen (the "Additional Terms" page blocked a login). Skip them, once. -if omarchy-done ensure omamobile-chromium-no-first-run; then - grep -qx -- --no-first-run ~/.config/chromium-flags.conf 2>/dev/null || - echo --no-first-run >>~/.config/chromium-flags.conf -fi - -# Websites and web apps should get their phone versions. Sites choose by the -# user agent (desktop Chromium on Linux ignores --use-mobile-user-agent, and -# an explicit one also drops the desktop client hints). Once. -if omarchy-done ensure omamobile-chromium-mobile; then - flags=~/.config/chromium-flags.conf - major=$(chromium --version 2>/dev/null | grep -oE '[0-9]+' | head -1) - [[ -f $flags ]] && sed -i -e '/^"\?--user-agent=/d' "$flags" - # Quoted: the launcher splits each line on spaces otherwise. - echo "\"--user-agent=Mozilla/5.0 (Linux; Android 14; Pixel 7 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${major:-153}.0.0.0 Mobile Safari/537.36\"" >>"$flags" -fi - # Auto-sleep (omamobile-sleepd: s2idle 30 s after the screen goes off behind # a secure lock), once, on a phone whose device package says its suspend is # verified (/usr/share/omamobile/auto-sleep-default; device/'s @@ -347,60 +329,11 @@ if omarchy-done ensure omamobile-lock-keypad; then touch ~/.local/state/omarchy/toggles/lock-keypad fi -# Chromium won't lay out narrower than about 500 px, wider than the phone's -# 480 px (at scale 3), so its window ran off the right edge. On Wayland its -# --force-device-scale-factor multiplies the output scale, so 0.83 gives about -# 550 px of layout width (2.5, the first try, made everything 2.5x bigger). -if omarchy-done ensure omamobile-chromium-scale-2; then - if grep -q -- '^--force-device-scale-factor=' ~/.config/chromium-flags.conf 2>/dev/null; then - sed -i 's/^--force-device-scale-factor=.*/--force-device-scale-factor=0.83/' ~/.config/chromium-flags.conf - else - echo --force-device-scale-factor=0.83 >>~/.config/chromium-flags.conf - fi -fi - -# The first version of the mobile step above also deleted the scale factor, -# so Chromium's window ran off the right edge again. Put it back, once. -if omarchy-done ensure omamobile-chromium-scale-3; then - grep -q -- '^--force-device-scale-factor=' ~/.config/chromium-flags.conf 2>/dev/null || - echo --force-device-scale-factor=0.83 >>~/.config/chromium-flags.conf -fi - -# Web text fields should raise the on-screen keyboard (TOUCH-PLAN 3.1): on -# Wayland, Chromium talks to an input method only with --enable-wayland-ime, -# and squeekboard gets text-input-v3 from Hyprland. Each flag once, unless the -# user's file already has it. -if omarchy-done ensure omamobile-chromium-wayland-ime; then - for flag in --enable-wayland-ime --wayland-text-input-version=3; do - grep -cx -- "$flag" ~/.config/chromium-flags.conf >/dev/null 2>&1 || - echo "$flag" >>~/.config/chromium-flags.conf - done -fi - -# Grok Bot, Omarchy's x.ai agent (Electron), won't lay out narrower than 512 -# px (SAND_MIN_WINDOW_SIZE in its main process), wider than a phone's logical -# width, so its window ran off the right edge as Chromium's did. Its launcher -# reads ~/.config/grok-bot-flags.conf. The scale factor there gives the 578 px -# of layout width Chromium gets on the 7 Pro (480 / 0.83): 0.83 there, 0.70 -# on the 9a (405 px), 0.62 at 360 px (a 1080 px panel at scale 3), and 0.83 -# when no panel mode can be read. Once; a factor the user's file already has -# stays theirs. -if omarchy-done ensure omamobile-grok-bot-fit; then - flags=~/.config/grok-bot-flags.conf - factor=0.83 mode= width=0 - for m in "${OMAMOBILE_DRM:-/sys/class/drm}"/card*-DSI-*/modes; do - if [[ -r $m ]]; then mode=$(sed -n 1p "$m"); break; fi - done - if [[ $mode =~ ^([0-9]+)x ]]; then - width=$((BASH_REMATCH[1] / 3)) # $scale, from the monitor step above - [[ $scale == '8 \/ 3' ]] && width=$((BASH_REMATCH[1] * 3 / 8)) - fi - if ((width > 0)); then - factor=$(awk -v w="$width" 'BEGIN { f = int(100 * w / 578) / 100; printf "%.2f", (f < 0.83 ? f : 0.83) }') - fi - grep -c -- '^--force-device-scale-factor=' "$flags" >/dev/null 2>&1 || - echo "--force-device-scale-factor=$factor" >>"$flags" -fi +# Chromium and Grok Bot share the panel's geometry and 578 px fitting rule. +# Defaults and the legacy generated-scale migration run once. Later removal +# of a UA, IME or scale flag remains the user's choice. Chrome follows only +# after its quote-aware launcher is released. +omamobile-browser-setup || echo "omamobile-setup-user: browser setup failed; continuing" >&2 # Style > Unlock picks the look of the disk-encryption unlock screen. The phone # has no encrypted disk, and the early boot logo follows the default theme, so diff --git a/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml b/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml index 6bd395a12..5234b403a 100644 --- a/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml +++ b/packages/omamobile-shell/plugins/omamobile.bar/Bar.qml @@ -29,6 +29,13 @@ Item { property var pluginRegistry: null property var barConfig: ({}) + // setup-user runs before the compositor. Retry its once-only browser fit + // here, where live monitor geometry also resolves computed/auto Lua scales. + Process { + command: ["omamobile-browser-setup"] + running: true + } + // Scalar bar state the host mirrors to other plugins (notifications and the // OSD place themselves clear of the bar with these). readonly property bool barHidden: false diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 85affa2b1..3950ec032 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -1076,6 +1076,7 @@ rm -rf "$shot" pass "screenshot toast: Loupe, or Tensaku without the on-screen keyboard" bash -n bin/omamobile-setup-user || fail "omamobile-setup-user parses" +python3 -B test/browser-setup.py || fail "browser defaults and geometry" bash test/setup-user.sh || fail "omamobile-setup-user against a scratch home" bash -n bin/omamobile-osk-guard || fail "omamobile-osk-guard parses" # The widget crash guard counts a shell death inside the same boot as a diff --git a/packages/omamobile-shell/test/browser-setup.py b/packages/omamobile-shell/test/browser-setup.py new file mode 100644 index 000000000..17c6b57f6 --- /dev/null +++ b/packages/omamobile-shell/test/browser-setup.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +import importlib.machinery +import importlib.util +import json +import os +from pathlib import Path +import shlex +import tempfile +from types import SimpleNamespace +import unittest +from unittest.mock import patch + +loader = importlib.machinery.SourceFileLoader('browser_setup', str(Path(__file__).resolve().parents[1] / 'bin/omamobile-browser-setup')) +spec = importlib.util.spec_from_loader(loader.name, loader) +M = importlib.util.module_from_spec(spec) +loader.exec_module(M) + + +class BrowserSetupTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.root = Path(self.tmp.name) + self.config = self.root / '.config' + self.config.mkdir() + self.done = self.root / '.local/state/omarchy/done' + self.path = self.config / 'chromium-flags.conf' + + def mark(self, *names): + self.done.mkdir(parents=True, exist_ok=True) + for name in names: + (self.done / ('omamobile-' + name)).touch() + + def configure(self, program='chromium', factor='0.62'): + M.configure(self.path, factor, self.done, program) + + def test_geometry_shared_fit_and_landscape(self): + for width, scale, expected in [(1080, 3, '0.62'), (1440, 3, '0.83'), (1080, 8 / 3, '0.70'), (1080, 2, '0.83')]: + for name in ('DSI-1', 'eDP-1', 'Unknown-1'): + monitors = [{'name': name, 'width': width, 'height': 2400, 'scale': scale}, {'name': 'DP-1', 'width': 3840, 'height': 2160, 'scale': 1}] + self.assertEqual(M.factor_for(M.logical_width(monitors)), expected) + monitors[0].update(width=2400, height=width, transform=1) + self.assertEqual(M.factor_for(M.logical_width(monitors)), expected) + self.assertIsNone(M.logical_width([{'name': 'DSI-1', 'width': 0, 'height': 0, 'scale': 0}])) + + def test_numeric_scale_only(self): + self.assertEqual(M.monitor_scale('local omarchy_monitor_scale = 8 / 3\n'), 8 / 3) + for text in ['"auto"', 'os.execute("touch bad")', '1 / 0', '-1', '0', 'math.huge']: + self.assertIsNone(M.monitor_scale('local omarchy_monitor_scale = ' + text)) + + def test_precompositor_geometry_and_defer(self): + (self.config / 'hypr').mkdir() + (self.config / 'hypr/monitors.lua').write_text('local omarchy_monitor_scale = 3\n') + modes = self.root / 'drm/card0-Unknown-1/modes' + modes.parent.mkdir(parents=True) + modes.write_text('1080x2400\n') + with patch.dict(os.environ, {'HOME': str(self.root), 'XDG_STATE_HOME': str(self.root / 'other-state'), 'XDG_CONFIG_HOME': str(self.root / 'other-config'), 'OMAMOBILE_DRM': str(self.root / 'drm')}), patch.object(M.subprocess, 'run', side_effect=OSError): + self.assertEqual(M.geometry(self.config), 360) + modes.unlink() + M.main() + initial = shlex.split(self.path.read_text()) + self.assertIn('--no-first-run', initial) + self.assertIn('--enable-wayland-ime', initial) + self.assertIn('--wayland-text-input-version=3', initial) + self.assertEqual(len([f for f in initial if f.startswith('--user-agent=')]), 1) + self.assertFalse(any(f.startswith('--force-device-scale-factor=') for f in initial)) + self.assertFalse((self.done / 'omamobile-browser-fit-chromium').exists()) + self.assertFalse((self.config / 'grok-bot-flags.conf').exists()) + modes.write_text('1080x2400\n') + M.main() + self.assertIn('--force-device-scale-factor=0.62', self.path.read_text()) + self.assertEqual((self.config / 'grok-bot-flags.conf').read_text(), '--force-device-scale-factor=0.62\n') + self.assertFalse((self.config / 'chrome-flags.conf').exists()) + + def test_deferred_fit_keeps_defaults_removed_before_shell_retry(self): + with patch.dict(os.environ, {'HOME': str(self.root)}), patch.object(M, 'geometry', return_value=None), patch.object(M, 'browser_major', return_value='157') as version: + M.main() + self.path.write_text('# desktop sites, system input method\n') + M.main() + self.assertEqual(self.path.read_text(), '# desktop sites, system input method\n') + version.assert_called_once_with('chromium') + with patch.dict(os.environ, {'HOME': str(self.root)}), patch.object(M, 'geometry', return_value=360), patch.object(M, 'browser_major') as version: + M.main() + self.assertEqual(self.path.read_text(), '# desktop sites, system input method\n--force-device-scale-factor=0.62\n') + self.assertTrue((self.done / 'omamobile-browser-fit-chromium').exists()) + self.assertEqual((self.config / 'grok-bot-flags.conf').read_text(), '--force-device-scale-factor=0.62\n') + version.assert_not_called() + + def test_deferred_migration_preserves_historical_choices(self): + self.mark('chromium-mobile', 'chromium-wayland-ime', 'chromium-no-first-run', 'chromium-scale-3') + self.path.write_text('--force-device-scale-factor=0.83\n') + with patch.object(M, 'browser_major') as version: + self.configure(factor=None) + self.assertEqual(self.path.read_text(), '--force-device-scale-factor=0.83\n') + self.configure() + self.assertEqual(self.path.read_text(), '--force-device-scale-factor=0.62\n') + version.assert_not_called() + + def test_computed_scale_gets_its_fit_from_live_session_retry(self): + (self.config / 'hypr').mkdir() + (self.config / 'hypr/monitors.lua').write_text('local omarchy_monitor_scale = math.max(1, 3)\n') + with patch.dict(os.environ, {'HOME': str(self.root), 'OMAMOBILE_DRM': str(self.root / 'no-drm')}), patch.object(M, 'browser_major', return_value='157') as version: + with patch.object(M.subprocess, 'run', side_effect=OSError): + M.main() + self.assertIn('--enable-wayland-ime', self.path.read_text()) + self.assertNotIn('--force-device-scale-factor', self.path.read_text()) + monitors = [{'name': 'Unknown-1', 'width': 1080, 'height': 2400, 'scale': 3}] + with patch.object(M.subprocess, 'run', return_value=SimpleNamespace(stdout=json.dumps(monitors))): + M.main() + self.assertIn('--force-device-scale-factor=0.62', self.path.read_text()) + self.assertEqual((self.config / 'grok-bot-flags.conf').read_text(), '--force-device-scale-factor=0.62\n') + version.assert_called_once_with('chromium') + + def test_defaults_once_and_ua_one_argument(self): + with patch.object(M, 'browser_major', return_value='157') as version: + self.configure() + ua = [f for f in shlex.split(self.path.read_text(), comments=True) if f.startswith('--user-agent=')] + self.assertEqual(ua, ['--user-agent=Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36']) + # Removing every generated flag is a deliberate user choice. + self.path.write_text('# desktop sites and system defaults\n') + self.configure() + self.assertEqual(self.path.read_text(), '# desktop sites and system defaults\n') + version.assert_called_once_with('chromium') + + def test_historical_markers_preserve_removed_ua_ime_and_scale(self): + self.mark('chromium-mobile', 'chromium-wayland-ime', 'chromium-no-first-run', 'chromium-scale-3') + with patch.object(M, 'browser_major') as version: + self.configure() + self.assertFalse(self.path.exists()) + version.assert_not_called() + + def test_upgrade_uses_omarchy_marker_path_with_custom_xdg(self): + self.mark('chromium-mobile', 'chromium-wayland-ime', 'chromium-no-first-run', 'chromium-scale-3') + with patch.dict(os.environ, {'HOME': str(self.root), 'XDG_STATE_HOME': str(self.root / 'elsewhere')}), patch.object(M, 'geometry', return_value=360), patch.object(M, 'browser_major') as version: + M.main() + self.assertFalse(self.path.exists()) + self.assertTrue((self.done / 'omamobile-browser-fit-chromium').exists()) + version.assert_not_called() + + def test_exact_generated_migration_once_for_both_programs(self): + for program, legacy in [('chromium', 'chromium-scale-2'), ('grok-bot', 'grok-bot-fit')]: + with self.subTest(program=program): + self.mark(legacy, 'chromium-mobile', 'chromium-no-first-run', 'chromium-wayland-ime') + self.path.write_text('# own comment\n--force-device-scale-factor=0.83\n--disable-gpu\n') + with patch.object(M, 'browser_major') as version: + self.configure(program) + self.assertEqual(self.path.read_text(), '# own comment\n--force-device-scale-factor=0.62\n--disable-gpu\n') + self.path.write_text('--force-device-scale-factor=0.83\n') + self.configure(program) + self.assertEqual(self.path.read_text(), '--force-device-scale-factor=0.83\n') + version.assert_not_called() + + def test_custom_flags_and_quoted_override(self): + self.mark('chromium-scale-3') + original = '# personal\n"--force-device-scale-factor=0.83"\n"--user-agent=My own agent"\n--disable-gpu\n--wayland-text-input-version=1\n' + self.path.write_text(original) + with patch.object(M, 'browser_major') as version: + self.configure() + self.assertTrue(self.path.read_text().startswith(original)) + self.assertNotIn('--wayland-text-input-version=3', self.path.read_text()) + version.assert_not_called() + + def test_custom_personal_scale_preserved(self): + self.mark('chromium-scale-3') + self.path.write_text('--force-device-scale-factor=0.70\n') + with patch.object(M, 'browser_major', return_value='157'): + self.configure() + self.assertTrue(self.path.read_text().startswith('--force-device-scale-factor=0.70\n')) + + def test_malformed_flags_retry_without_marking(self): + self.path.write_text('"unterminated') + with self.assertRaises(ValueError): + self.configure() + self.assertEqual(self.path.read_text(), '"unterminated') + self.assertFalse(self.done.exists()) + + def test_later_logins_start_no_process(self): + self.mark('browser-fit-chromium', 'browser-fit-grok-bot') + with patch.dict(os.environ, {'HOME': str(self.root), 'XDG_STATE_HOME': str(self.root / 'other-state'), 'XDG_CONFIG_HOME': str(self.root / 'other-config')}), patch.object(M.subprocess, 'run') as run: + M.main() + run.assert_not_called() + + +if __name__ == '__main__': + unittest.main() diff --git a/packages/omamobile-shell/test/setup-user.sh b/packages/omamobile-shell/test/setup-user.sh index 5642ed59b..2803c7f41 100644 --- a/packages/omamobile-shell/test/setup-user.sh +++ b/packages/omamobile-shell/test/setup-user.sh @@ -27,6 +27,8 @@ if [[ $1 == list-keys && $2 == org.gnome.nautilus.preferences ]]; then fi' # systemctl: logs calls; fails while $HOME/systemctl-fails exists (no user manager) fake systemctl 'echo "systemctl $*" >>"$HOME/calls"; [[ ! -e $HOME/systemctl-fails ]]' +ln -s "$pkg/bin/omamobile-browser-setup" "$F/omamobile-browser-setup" +fake hyprctl 'exit 1' fake chromium 'echo "Chromium 153.0.0.0"' fake omamobile-keyboard-theme 'echo "omamobile-keyboard-theme $*" >>"$HOME/calls"' for f in monitors looknfeel autostart; do echo "-- $f" >"$H/.config/hypr/$f.lua"; done @@ -201,7 +203,12 @@ flags=$H/.config/chromium-flags.conf for flag in --enable-wayland-ime --wayland-text-input-version=3 --force-device-scale-factor=0.83; do [[ $(grep -cx -- "$flag" "$flags") == 1 ]] || fail "chromium-flags.conf has $flag once" done -grep -c '^"--user-agent=.*Mobile Safari/537.36"$' "$flags" >/dev/null || fail "the mobile user agent stays quoted on its line" +python3 - "$flags" <<'PYUA' || fail "the mobile user agent parses as one argument" +import shlex, sys +flags = shlex.split(open(sys.argv[1]).read(), comments=True) +ua = [f for f in flags if f.startswith("--user-agent=")] +assert len(ua) == 1 and ua[0].endswith("Chrome/153.0.0.0 Mobile Safari/537.36"), ua +PYUA # Grok Bot's flags: the 7 Pro's factor, once, after two logins gflags=$H/.config/grok-bot-flags.conf [[ $(grep -cx -- --force-device-scale-factor=0.83 "$gflags") == 1 ]] || fail "grok-bot-flags.conf has the 7 Pro's factor once" @@ -245,14 +252,30 @@ grep -cx -- --force-device-scale-factor=0.70 "$h9/.config/grok-bot-flags.conf" > pass "the Pixel 9a's scale: 8 / 3, GDK_SCALE left at 2, Grok Bot at 0.70" # Grok Bot's factor follows the panel: 0.62 for a 1080 px panel at scale 3 -# (360 px), and 0.83 when no panel mode can be read -for c in 1080x2400:0.62 none:0.83; do +# (360 px); no geometry defers only scale, keeping Chromium's other defaults +for c in 1080x2400:0.62; do hg=$t/grok-${c%%:*}; mkdir -p "$hg/.config/hypr" "$hg/.config/omarchy/extensions" cp "$H"/.config/hypr/{looknfeel,autostart,monitors}.lua "$hg/.config/hypr/" RUN_HOME=$hg RUN_DRM=$t/drm-${c%%:*} run grep -cx -- "--force-device-scale-factor=${c#*:}" "$hg/.config/grok-bot-flags.conf" >/dev/null \ || fail "Grok Bot's factor with panel ${c%%:*} is ${c#*:}" done +hg=$t/grok-none; mkdir -p "$hg/.config/hypr" "$hg/.config/omarchy/extensions" +cp "$H"/.config/hypr/{looknfeel,autostart,monitors}.lua "$hg/.config/hypr/" +RUN_HOME=$hg RUN_DRM=$t/drm-none run +[[ ! -e $hg/.config/grok-bot-flags.conf ]] || fail "no panel defers Grok's scale" +python3 - "$hg/.config/chromium-flags.conf" <<'PYDEFAULTS' +import shlex, sys +flags = shlex.split(open(sys.argv[1]).read(), comments=True) +assert '--no-first-run' in flags and '--enable-wayland-ime' in flags +assert '--wayland-text-input-version=3' in flags +assert len([f for f in flags if f.startswith('--user-agent=')]) == 1 +assert not any(f.startswith('--force-device-scale-factor=') for f in flags) +PYDEFAULTS +RUN_HOME=$hg RUN_DRM=$t/drm-1080x2400 run +for app in grok-bot chromium; do + grep -cx -- --force-device-scale-factor=0.62 "$hg/.config/$app-flags.conf" >/dev/null || fail "$app retries with geometry" +done pass "Grok Bot's scale factor gives about 578 px of layout width on any panel" # Voxtype (phase 3): base.en stays the model, and Whisper's context is cut to @@ -500,3 +523,12 @@ rm "$ha/.local/state/omarchy/toggles/omamobile-sleep" RUN_HOME=$ha RUN_AUTO_SLEEP=$t/auto-sleep-default run [[ ! -e $ha/.local/state/omarchy/toggles/omamobile-sleep ]] || fail "a user who turns auto-sleep off keeps it off" pass "auto-sleep: on once where the device says suspend is verified, a user's off kept" + +# Browser setup is optional: a broken helper must not skip later login steps. +rm "$F/omamobile-browser-setup" +fake omamobile-browser-setup 'exit 1' +rm -f "$H/.local/state/omarchy/done/omamobile-menu-hide-unlock" +run +grep -q 'browser setup failed; continuing' "$t/out" || fail "browser helper failure is reported" +[[ -f $H/.local/state/omarchy/done/omamobile-menu-hide-unlock ]] || fail "user setup continues after browser helper failure" +pass "browser helper failure does not stop later user setup" From 563086d3de671e7fa7d14015c7cc7ffa8acb17a9 Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Wed, 11 Nov 2026 12:09:52 -0600 Subject: [PATCH 2/5] TOUCH-PLAN: record installed 6a browser fitting results Document the exact combined userspace artifact, deferred-geometry and intentional-removal checks, preserved personal settings and remaining reference-phone gates. Co-Authored-By: Codex --- docs/TOUCH-PLAN.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/TOUCH-PLAN.md b/docs/TOUCH-PLAN.md index 489848f39..0ad9b73f2 100644 --- a/docs/TOUCH-PLAN.md +++ b/docs/TOUCH-PLAN.md @@ -64,7 +64,8 @@ Priorities: **P1** broken, unsafe, or a dead end on a phone; **P2** noticeably a ## Shared Chromium and Grok Bot fitting revision, 2026-11-10 (3.1) -Candidate only; no new phone result. Both apps now share the established +The combined package passed the Pixel 6a checks recorded below. Both apps +share the established 578 px layout target and internal geometry detection, including simpledrm. The 7 Pro's 480 logical px retains 0.83, the 9a's 405 gets 0.70, and the 6a's 360 gets 0.62 for a fresh default. The owner's custom 0.70 and site @@ -96,8 +97,30 @@ Runbook (low risk, userspace only): 4. Rollback: restore the prior package, flags, done markers and shell profile and plugins, restart the shell if needed and reopen the apps normally. -Full-package 6a checks and the 9a owner's migration check remain required; -the maintainer will validate the 7 Pro. No kernel or boot image is involved. +### Pixel 6a verification, 2026-11-11 + +The exact tested combined package is `omamobile-shell 0.2.119-1`, integration +`83326ed6d09684ae80f38c9360e8c4e864d32614`, SHA-256 +`02e0acadd2568bf167946a87c740626fffb59068918271bdb2026fac799e0270`, on +`7.3.0-rc6-omamobile-bluejay-input-gated0`. Installation and cold shell restart +were performed while unlocked. All six required phone-smoke checks passed; +package verification found 370 files and none altered. + +The installed helper wrote UA/IME/first-run defaults in an isolated home +without geometry, then obtained actual live monitor geometry for a computed +Lua scale and fitted both apps to 0.62. Removing UA/IME flags before that retry +left them removed. Normal Chromium launch with an isolated profile and the +owner's existing 0.70 gave equal viewport/client/scroll widths of 515 and a +complete mobile UA. Personal browser flags, saved Chrome zoom and the clock +were preserved. Only main's expected remote-session disable was added to the +shell profile. Temporary fixtures were removed and the phone returned home. + +Policy, the complete combined shell suite and independent review passed; +both published UX heads passed repository and every-package CI. These runtime +results qualify the exact combined package above, not a later kernel or an +unrelated subsequently merged shell change. The 9a owner's one-time migration +and the maintainer's existing/fresh-user 7 Pro checks remain before merge. +No kernel or boot image was changed for this userspace verification. ## Omarchy patches this needs (upstreamable) From 04969e06c77da660917f7ba0367877c9dabb5019 Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Sat, 14 Nov 2026 17:04:48 -0600 Subject: [PATCH 3/5] TOUCH-PLAN: name the tested browser source and reference checks Record the generic UA choice and completed Pixel 7 Pro check. Name the immutable integration branch so the earlier combined 6a test can be matched to source; the Pixel 9a migration remains a separate gate. Assisted-by: OpenAI Codex --- docs/TOUCH-PLAN.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/TOUCH-PLAN.md b/docs/TOUCH-PLAN.md index 0ad9b73f2..88f39b048 100644 --- a/docs/TOUCH-PLAN.md +++ b/docs/TOUCH-PLAN.md @@ -77,7 +77,7 @@ package version at merge. Geometry-free Chromium defaults run even before panel geometry is available; only the scale waits. A separate defaults marker preserves removals before the phone bar retries the helper at shell start with live monitor geometry, -including computed/auto Lua scales. A failed helper never aborts user setup. +including computed/auto Lua scales. A failed helper never aborts user setup. Fresh defaults deliberately use a generic Android mobile user agent without a device model; existing user-agent choices are preserved. Runbook (low risk, userspace only): @@ -100,7 +100,7 @@ Runbook (low risk, userspace only): ### Pixel 6a verification, 2026-11-11 The exact tested combined package is `omamobile-shell 0.2.119-1`, integration -`83326ed6d09684ae80f38c9360e8c4e864d32614`, SHA-256 +[`83326ed6d09684ae80f38c9360e8c4e864d32614`](https://github.com/latentoperator/omarchy-mobile/commit/83326ed6d09684ae80f38c9360e8c4e864d32614) on the fork's `bringup/bluejay-userspace-tested-20261111` branch, SHA-256 `02e0acadd2568bf167946a87c740626fffb59068918271bdb2026fac799e0270`, on `7.3.0-rc6-omamobile-bluejay-input-gated0`. Installation and cold shell restart were performed while unlocked. All six required phone-smoke checks passed; @@ -118,8 +118,7 @@ shell profile. Temporary fixtures were removed and the phone returned home. Policy, the complete combined shell suite and independent review passed; both published UX heads passed repository and every-package CI. These runtime results qualify the exact combined package above, not a later kernel or an -unrelated subsequently merged shell change. The 9a owner's one-time migration -and the maintainer's existing/fresh-user 7 Pro checks remain before merge. +unrelated subsequently merged shell change. The maintainer's existing/fresh-user 7 Pro checks passed on November 12; the 9a owner's one-time migration check remains before merge. No kernel or boot image was changed for this userspace verification. From fa1850a66108d951431fc625cd3fa18f31b2fd9a Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Sat, 14 Nov 2026 17:13:57 -0600 Subject: [PATCH 4/5] omamobile-shell: preserve browser overrides after URL fragments shlex comment mode discards an unquoted URL fragment and every following flag. That made browser setup overlook an existing custom scale and UA, then append generated replacements. Recognize comments only at unquoted token boundaries, matching the launcher parsing behavior, and keep malformed-input refusal. A regression fails with the prior parser and verifies that an app URL followed by custom scale and UA remains unchanged. Direct helper tests also suppress bytecode writes into the packaged bin directory. Assisted-by: OpenAI Codex --- .../bin/omamobile-browser-setup | 38 ++++++++++++++++++- .../omamobile-shell/test/browser-setup.py | 13 +++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/omamobile-shell/bin/omamobile-browser-setup b/packages/omamobile-shell/bin/omamobile-browser-setup index 9d3461cfe..9c97dd160 100755 --- a/packages/omamobile-shell/bin/omamobile-browser-setup +++ b/packages/omamobile-shell/bin/omamobile-browser-setup @@ -79,6 +79,42 @@ def browser_major(program): return "153" # Historical first-login fallback; never query on later logins. +def parse_flags(source): + # Comments start at unquoted token boundaries; URL fragments stay literal. + text = [] + quote = None + escaped = False + token = False + comment = False + for char in source: + if comment: + if char != "\n": + continue + comment = False + if escaped: + escaped = False + elif quote: + if char == quote: + quote = None + elif char == "\\" and quote == '"': + escaped = True + elif char == "#" and not token: + comment = True + continue + elif char in " \t\r\n": + token = False + else: + token = True + if char in "'\"": + quote = char + elif char == "\\": + escaped = True + text.append(char) + # Validate quotes/escapes and group argv without evaluating shell code. + return shlex.split("".join(text), comments=False, posix=True) + + + def configure(path, factor, done, program): chromium = program == "chromium" marker = done / ("omamobile-browser-fit-" + program) @@ -88,7 +124,7 @@ def configure(path, factor, done, program): return # Grok has only a geometry-dependent scale default. defaults_marker = done / "omamobile-browser-defaults-chromium" before = path.read_text() if path.exists() else "" - flags = shlex.split(before, comments=True) + flags = parse_flags(before) has = lambda key: any(flag.split("=")[0] == key for flag in flags) prior = lambda name: (done / ("omamobile-" + name)).exists() scale_marked = (prior("chromium-scale-2") or prior("chromium-scale-3")) if chromium else prior("grok-bot-fit") diff --git a/packages/omamobile-shell/test/browser-setup.py b/packages/omamobile-shell/test/browser-setup.py index 17c6b57f6..689673bd6 100644 --- a/packages/omamobile-shell/test/browser-setup.py +++ b/packages/omamobile-shell/test/browser-setup.py @@ -6,11 +6,15 @@ import os from pathlib import Path import shlex +import sys import tempfile from types import SimpleNamespace import unittest from unittest.mock import patch +# Keep direct test runs from leaving bytecode in the packaged bin directory. +sys.dont_write_bytecode = True + loader = importlib.machinery.SourceFileLoader('browser_setup', str(Path(__file__).resolve().parents[1] / 'bin/omamobile-browser-setup')) spec = importlib.util.spec_from_loader(loader.name, loader) M = importlib.util.module_from_spec(spec) @@ -161,6 +165,15 @@ def test_custom_flags_and_quoted_override(self): self.assertNotIn('--wayland-text-input-version=3', self.path.read_text()) version.assert_not_called() + def test_url_fragment_keeps_later_custom_overrides(self): + self.mark('chromium-no-first-run', 'chromium-wayland-ime') + original = '--app=https://example.test/#fragment --force-device-scale-factor=0.70 --user-agent=Custom\n' + self.path.write_text(original) + with patch.object(M, 'browser_major') as version: + self.configure() + self.assertEqual(self.path.read_text(), original) + version.assert_not_called() + def test_custom_personal_scale_preserved(self): self.mark('chromium-scale-3') self.path.write_text('--force-device-scale-factor=0.70\n') From d45d79e145829517b91aaa38a2ba0d7c1fa9b530 Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Sat, 14 Nov 2026 17:14:26 -0600 Subject: [PATCH 5/5] TOUCH-PLAN: distinguish the browser parser correction from old runtime evidence The exact November 11 package remains the historical phone checkpoint. Record the new URL-fragment preservation fix as an offline-validated follow-up so its coverage is not inferred from that earlier boot. Assisted-by: OpenAI Codex --- docs/TOUCH-PLAN.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/TOUCH-PLAN.md b/docs/TOUCH-PLAN.md index 88f39b048..00f62b2be 100644 --- a/docs/TOUCH-PLAN.md +++ b/docs/TOUCH-PLAN.md @@ -79,6 +79,12 @@ only the scale waits. A separate defaults marker preserves removals before the phone bar retries the helper at shell start with live monitor geometry, including computed/auto Lua scales. A failed helper never aborts user setup. Fresh defaults deliberately use a generic Android mobile user agent without a device model; existing user-agent choices are preserved. +November 14 parser follow-up: an unquoted app URL fragment must not hide +later custom scale or user-agent flags. Comment recognition now follows +unquoted token boundaries; the new preservation regression fails with the +previous parser and passes with the correction. This edge-case correction +has offline test evidence only and was not in the historical package below. + Runbook (low risk, userspace only): 1. Run the shell package suite and policy gate. Expect no failures; stop on