diff --git a/packages/omamobile-shell/README.md b/packages/omamobile-shell/README.md index 4f9e2d36d..3ded5ce8d 100644 --- a/packages/omamobile-shell/README.md +++ b/packages/omamobile-shell/README.md @@ -94,7 +94,7 @@ afterwards. ## File dialogs -Open, save and choose-a-folder requests through the portal (Qt, GTK, Electron and Flatpak apps alike) get Nautilus's libadwaita file chooser from xdg-desktop-portal-gnome, not xdg-desktop-portal-gtk's GTK 3 desktop chooser, whose Places sidebar took half of the 480 px width. Nautilus's chooser folds its sidebar away at phone width and has touch-sized rows; `hypr/phone.lua` tiles it, even when it has a parent window, so it fills the screen between the bar and the on-screen keyboard. Only FileChooser goes to the gnome backend: its other interfaces need gnome-shell. It runs without gnome-shell (its Mutter service channel is missing, so it falls back to a plain Wayland connection). xdg-desktop-portal-gtk stays as the fallback and for its other interfaces. GTK apps that would draw their own chooser in-process are sent to the portal too (`GTK_USE_PORTAL=1` for GTK 3, `GDK_DEBUG=portals` for GTK 4, in `environment.d/20-omamobile-osk.conf`); Qt Widgets apps keep Omarchy's `QT_QPA_PLATFORMTHEME=gtk3` for now. +Open, save and choose-a-folder requests through the portal (Qt, GTK, Electron and Flatpak apps alike) get Nautilus's libadwaita file chooser from xdg-desktop-portal-gnome, not xdg-desktop-portal-gtk's GTK 3 desktop chooser, whose Places sidebar took half of the 480 px width. Nautilus's chooser folds its sidebar away at phone width and has touch-sized rows; `hypr/phone.lua` tiles it, even when it has a parent window, so it fills the screen between the bar and the on-screen keyboard. Only FileChooser goes to the gnome backend: its other interfaces need gnome-shell. It runs without gnome-shell (its Mutter service channel is missing, so it falls back to a plain Wayland connection). xdg-desktop-portal-gtk stays as the fallback and for its other interfaces. Omarchy's Secret-portal migration writes the user's own `~/.config/xdg-desktop-portal/hyprland-portals.conf`, whose `default=hyprland;gtk` would hide these picks, so `omamobile-setup-user` adds the phone's lines that file doesn't name yet at each login (a line the user set stays, blanks around its `=` or not). A symlinked or read-only file, or one whose last group isn't `[preferred]`, is left alone with a line in the login's output. GTK apps that would draw their own chooser in-process are sent to the portal too (`GTK_USE_PORTAL=1` for GTK 3, `GDK_DEBUG=portals` for GTK 4, in `environment.d/20-omamobile-osk.conf`); Qt Widgets apps keep Omarchy's `QT_QPA_PLATFORMTHEME=gtk3` for now. ## Windows on a phone screen diff --git a/packages/omamobile-shell/bin/omamobile-setup-user b/packages/omamobile-shell/bin/omamobile-setup-user index c4ce2ab60..b8712622f 100755 --- a/packages/omamobile-shell/bin/omamobile-setup-user +++ b/packages/omamobile-shell/bin/omamobile-setup-user @@ -703,3 +703,43 @@ fi # installer, so run Omarchy's own script: it creates only what is missing. keyring=${OMARCHY_PATH:-/usr/share/omarchy}/install/user/default-keyring.sh if [[ -f $keyring ]]; then bash "$keyring"; fi + +# The phone's portal picks (the permission sheet for Access, Nautilus's +# chooser for FileChooser) are in /etc/xdg/xdg-desktop-portal/ +# hyprland-portals.conf. Omarchy's migration 1788261467 (the Secret portal) +# writes ~/.config/xdg-desktop-portal/hyprland-portals.conf with its own +# default=hyprland;gtk, and xdg-desktop-portal goes by the first file that +# answers: from then on file dialogs were GTK 3's desktop chooser, which +# Hyprland squeezed to the screen (623 px into 405 on the Pixel 9a, text drawn +# tall and narrow), and the permission question GTK's dialog. Every login, +# since the migration can come with any update: the user's file gets each of +# the phone's lines whose interface it doesn't name yet (with or without +# blanks around the =). One the user set stays as it is. The lines go at the +# end, so only while the file's last group is [preferred]; a symlinked file +# (dotfile setups) or one we can't write is left alone, with a line in the +# output, rather than writing through the link or failing the login. +portals=${OMAMOBILE_PORTALS_CONF:-/etc/xdg/xdg-desktop-portal/hyprland-portals.conf} +user_portals=${XDG_CONFIG_HOME:-$HOME/.config}/xdg-desktop-portal/hyprland-portals.conf +if [[ -f $portals && -f $user_portals ]]; then + last_group=$(grep -E '^[[:space:]]*\[' "$user_portals" | tail -n1 | tr -d '[:space:]' || true) + if [[ -L $user_portals || ! -w $user_portals ]]; then + echo "omamobile-setup-user: $user_portals is a symlink or not writable; the phone's portal picks aren't added to it" >&2 + elif [[ $last_group != '[preferred]' ]]; then + echo "omamobile-setup-user: $user_portals doesn't end in its [preferred] group; the phone's portal picks aren't added to it" >&2 + else + added= + while IFS= read -r line; do + key=${line%%=*} + grep -Eq "^[[:space:]]*${key//./\\.}[[:space:]]*=" "$user_portals" && continue + if [[ -z $added ]]; then + [[ -z $(tail -c1 "$user_portals") ]] || echo >>"$user_portals" + echo "# Omamobile (omamobile-setup-user): the phone's picks from $portals" >>"$user_portals" + fi + echo "$line" >>"$user_portals" + added=1 + done < <(grep -E '^org\.freedesktop\.impl\.portal\.[A-Za-z]+=' "$portals") + if [[ -n $added ]]; then + systemctl --user try-restart xdg-desktop-portal.service 2>/dev/null || true + fi + fi +fi diff --git a/packages/omamobile-shell/test/setup-user.sh b/packages/omamobile-shell/test/setup-user.sh index 5149f082b..fd6f2a929 100644 --- a/packages/omamobile-shell/test/setup-user.sh +++ b/packages/omamobile-shell/test/setup-user.sh @@ -78,6 +78,7 @@ run() { OMARCHY_PATH="${RUN_OMARCHY_PATH:-$t/omarchy}" \ OMAMOBILE_USER_UNITS="${RUN_USER_UNITS:-$t/no-user-units}" \ OMAMOBILE_AUTO_SLEEP_DEFAULT="${RUN_AUTO_SLEEP:-$t/no-auto-sleep-default}" \ + OMAMOBILE_PORTALS_CONF="$pkg/portal/hyprland-portals.conf" \ bash bin/omamobile-setup-user "$@" >"$t/out" 2>&1 || { cat "$t/out"; fail "omamobile-setup-user runs"; } } run @@ -562,3 +563,46 @@ 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" + +# Omarchy's Secret-portal migration writes the user's own hyprland-portals.conf, +# which hides the phone's in /etc. Each login adds the phone's lines the file +# doesn't name yet, once, restarts the portal only then, and keeps the user's own. +hp=$t/portals; mkdir -p "$hp/.config/hypr" "$hp/.config/xdg-desktop-portal"; cp "$H"/.config/hypr/*.lua "$hp/.config/hypr/" +up=$hp/.config/xdg-desktop-portal/hyprland-portals.conf +printf '[preferred]\ndefault=hyprland;gtk\norg.freedesktop.impl.portal.Secret=gnome-keyring\n' >"$up" +RUN_HOME=$hp run; RUN_HOME=$hp run +grep -qx 'org.freedesktop.impl.portal.FileChooser=gnome;gtk' "$up" || fail "the user's portals file gets the phone's file chooser" +grep -qx 'org.freedesktop.impl.portal.Access=omamobile;gtk' "$up" || fail "the user's portals file gets the phone's permission sheet" +grep -qx 'org.freedesktop.impl.portal.Secret=gnome-keyring' "$up" || fail "Omarchy's Secret line stays" +[[ $(grep -c '^org.freedesktop.impl.portal.FileChooser=' "$up") == 1 ]] || fail "two logins add the file chooser once" +[[ $(grep -c 'try-restart xdg-desktop-portal' "$hp/calls") == 1 ]] || fail "the portal restarts once, when lines were added" +sed -i 's|^org.freedesktop.impl.portal.FileChooser=.*|org.freedesktop.impl.portal.FileChooser=gtk|' "$up" +RUN_HOME=$hp run +grep -qx 'org.freedesktop.impl.portal.FileChooser=gtk' "$up" || fail "a file chooser the user picked stays" +[[ $(grep -c '^org.freedesktop.impl.portal.FileChooser=' "$up") == 1 ]] || fail "a user's own file chooser line isn't joined by the phone's" +[[ ! -e $H/.config/xdg-desktop-portal/hyprland-portals.conf ]] || fail "without a user portals file none is made" +# A user's line written with blanks around the = counts as theirs, and a dot +# in the key isn't a wildcard (an "orgXfreedesktop" line doesn't count). +printf '[preferred]\ndefault=hyprland;gtk\norg.freedesktop.impl.portal.FileChooser = kde\norgXfreedesktopXimplXportalXAccess=gtk\n' >"$up" +RUN_HOME=$hp run +[[ $(grep -c 'portal.FileChooser' "$up") == 1 ]] || fail "a user's 'FileChooser = kde' isn't joined by the phone's line" +grep -qx 'org.freedesktop.impl.portal.Access=omamobile;gtk' "$up" || fail "a key with other characters in place of the dots doesn't hide the phone's line" +# The lines go at the end, so only while [preferred] is the last group. +printf '[preferred]\ndefault=hyprland;gtk\n[other]\nkey=value\n' >"$up" +cp "$up" "$t/portals-other.conf" +RUN_HOME=$hp run +cmp -s "$up" "$t/portals-other.conf" || fail "a file whose last group isn't [preferred] is left alone" +grep -q "doesn't end in its \[preferred\] group" "$t/out" || fail "a file left alone for its last group says so" +# A symlinked file (dotfiles) or a read-only one is left alone, and the login goes on. +printf '[preferred]\ndefault=hyprland;gtk\n' >"$t/dotfiles-portals.conf" +rm "$up"; ln -s "$t/dotfiles-portals.conf" "$up" +RUN_HOME=$hp run +[[ -L $up ]] || fail "the symlink stays a symlink" +[[ $(cat "$t/dotfiles-portals.conf") == $'[preferred]\ndefault=hyprland;gtk' ]] || fail "nothing is written through a symlinked portals file" +grep -q 'is a symlink or not writable' "$t/out" || fail "a symlinked portals file left alone says so" +rm "$up"; printf '[preferred]\ndefault=hyprland;gtk\n' >"$up"; chmod a-w "$up" +RUN_HOME=$hp run +[[ $(grep -c '^org.freedesktop.impl.portal.' "$up") == 0 ]] || fail "a read-only portals file is left alone" +grep -q 'is a symlink or not writable' "$t/out" || fail "a read-only portals file left alone says so" +chmod u+w "$up" +pass "the user's portals file (Omarchy's Secret migration) gets the phone's file chooser and permission sheet, once, and a symlinked, read-only or other-group file is left alone" diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 244c5adea..96e23b59c 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.142 +0.2.143