Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/omarchy-default-browser
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ zen) desktop_id="zen.desktop"; name="Zen"; glyph="󰖟" ;;
;;
esac

prev="$(xdg-settings get default-web-browser)"

xdg-settings set default-web-browser "$desktop_id"
xdg-mime default "$desktop_id" x-scheme-handler/http
xdg-mime default "$desktop_id" x-scheme-handler/https
xdg-mime default "$desktop_id" text/html

# A different browser may have different profiles, so drop remembered webapp selections.
[[ $prev != "$desktop_id" ]] && omarchy-webapp-profile-store clear-all

notify-send -u low "$glyph $name is now the default browser"
54 changes: 52 additions & 2 deletions bin/omarchy-launch-webapp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# omarchy:summary=Launch a URL as a web app in the default supported browser
# omarchy:args=<url>
# omarchy:args=<url> [extra-flags...]

browser=$(xdg-settings get default-web-browser)

Expand All @@ -10,4 +10,54 @@ google-chrome* | brave* | microsoft-edge* | opera* | vivaldi* | helium*) ;;
*) browser="chromium.desktop" ;;
esac

exec setsid uwsm-app -- $(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1) --app="$1" "${@:2}"
browser_exec=$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1)

url="$1"
shift
remember_key="${OMARCHY_WEBAPP_REMEMBER_KEY:-$url}"
profile_arg=()

# Build parallel arrays of profile dir + display name for the effective browser.
dirs=()
names=()
while IFS=$'\t' read -r d n; do
[[ -n $d ]] && dirs+=("$d") && names+=("$n")
done < <(omarchy-webapp-profiles)

# Only offer a profile choice when there is more than one to choose from.
if ((${#dirs[@]} > 1)); then
chosen_dir=""

# Use a remembered profile if it still exists.
remembered="$(omarchy-webapp-profile-store get "$remember_key")"
if [[ -n $remembered ]]; then
for d in "${dirs[@]}"; do [[ $d == "$remembered" ]] && chosen_dir="$d" && break; done
fi

# Otherwise ask, listing each profile (use once) plus an "Always use…" variant (remember).
if [[ -z $chosen_dir ]]; then
options=("${names[@]}" "──────────")
for n in "${names[@]}"; do options+=("Always use $n"); done

picked="$(omarchy-menu-select "Choose profile" "${options[@]}")"
[[ -z $picked || $picked == "──────────" ]] && exit 0

remember=false
sel="$picked"
if [[ $picked == "Always use "* ]]; then
remember=true
sel="${picked#Always use }"
fi

for i in "${!names[@]}"; do
[[ ${names[$i]} == "$sel" ]] && chosen_dir="${dirs[$i]}" && break
done
[[ -z $chosen_dir ]] && exit 0

$remember && omarchy-webapp-profile-store set "$remember_key" "$chosen_dir"
fi

profile_arg=(--profile-directory="$chosen_dir")
fi

exec setsid uwsm-app -- "$browser_exec" "${profile_arg[@]}" --app="$url" "$@"
3 changes: 3 additions & 0 deletions bin/omarchy-webapp-handler-hey
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ if [[ $url =~ ^mailto: ]]; then
web_url="https://app.hey.com/messages/new?to=$email"
fi

# Keep the remembered profile stable across the dynamic mailto: URLs.
export OMARCHY_WEBAPP_REMEMBER_KEY="https://app.hey.com"

exec omarchy-launch-webapp "$web_url"
3 changes: 3 additions & 0 deletions bin/omarchy-webapp-handler-zoom
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ if [[ $url =~ ^zoom(mtg|us):// ]]; then
fi
fi

# Keep the remembered profile stable across the dynamic meeting URLs.
export OMARCHY_WEBAPP_REMEMBER_KEY="https://app.zoom.us/wc/home"

exec omarchy-launch-webapp "$web_url"
17 changes: 17 additions & 0 deletions bin/omarchy-webapp-install
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ if (( $# < 3 )); then
ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "Could not fetch favicon automatically. Enter PNG icon URL (see https://dashboardicons.com)")
fi

# Offer a target browser profile when the effective browser has more than one.
PROFILE_DIRS=()
PROFILE_NAMES=()
while IFS=$'\t' read -r d n; do
[[ -n $d ]] && PROFILE_DIRS+=("$d") && PROFILE_NAMES+=("$n")
done < <(omarchy-webapp-profiles)

if ((${#PROFILE_DIRS[@]} > 1)); then
CHOICE=$(gum choose --header "Which browser profile?" "Ask me each time" "${PROFILE_NAMES[@]}")
if [[ -n $CHOICE && $CHOICE != "Ask me each time" ]]; then
for i in "${!PROFILE_NAMES[@]}"; do
[[ ${PROFILE_NAMES[$i]} == "$CHOICE" ]] &&
omarchy-webapp-profile-store set "$APP_URL" "${PROFILE_DIRS[$i]}" && break
done
fi
fi

CUSTOM_EXEC=""
MIME_TYPES=""
INTERACTIVE_MODE=true
Expand Down
28 changes: 28 additions & 0 deletions bin/omarchy-webapp-profile-store
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# omarchy:summary=Read/write the remembered Chromium profile for a webapp
# omarchy:args=<get|set|clear-all> [key] [dirname]

DIR="$HOME/.config/omarchy/webapps/profiles"
STAMP="$HOME/.config/omarchy/webapps/profiles-browser"

key_for() { printf '%s' "$1" | sha256sum | cut -d' ' -f1; }

cmd="$1"
shift

case "$cmd" in
get) # get <key> -> dirname or nothing
[[ -f $STAMP && "$(cat "$STAMP")" == "$(omarchy-webapp-profiles --browser)" ]] || exit 0
f="$DIR/$(key_for "$1")"
[[ -f $f ]] && cat "$f"
;;
set) # set <key> <dirname>
mkdir -p "$DIR"
printf '%s' "$2" >"$DIR/$(key_for "$1")"
omarchy-webapp-profiles --browser >"$STAMP"
;;
clear-all)
rm -rf "$DIR" "$STAMP"
;;
esac
38 changes: 38 additions & 0 deletions bin/omarchy-webapp-profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# omarchy:summary=List Chromium profiles (dirname<TAB>name) for the effective webapp browser
# omarchy:args=[--browser]

effective_browser() {
case "$(omarchy-default-browser)" in
chromium | chrome | brave | brave-origin | edge | opera | vivaldi | helium) omarchy-default-browser ;;
*) echo "chromium" ;; # firefox/zen/unknown → webapps fall back to chromium
esac
}

config_dir_for() {
case "$1" in
chromium) echo "$HOME/.config/chromium" ;;
chrome) echo "$HOME/.config/google-chrome" ;;
brave) echo "$HOME/.config/BraveSoftware/Brave-Browser" ;;
brave-origin) echo "$HOME/.config/BraveSoftware/Brave-Browser-Origin-Beta" ;;
edge) echo "$HOME/.config/microsoft-edge" ;;
opera) echo "$HOME/.config/opera" ;;
vivaldi) echo "$HOME/.config/vivaldi" ;;
helium) echo "$HOME/.config/net.imput.helium" ;;
*) echo "" ;;
esac
}

browser="$(effective_browser)"
[[ ${1:-} == "--browser" ]] && {
echo "$browser"
exit 0
}

cfg="$(config_dir_for "$browser")"
[[ -n $cfg && -f "$cfg/Local State" ]] || exit 0
command -v jq >/dev/null || exit 0

jq -r '(.profile.info_cache // {}) | to_entries[] | "\(.key)\t\(.value.name // .key)"' \
"$cfg/Local State" 2>/dev/null | sort
4 changes: 4 additions & 0 deletions migrations/1781657000.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo "Webapps can now launch in a chosen browser profile"
echo "With multiple profiles, you'll be asked which to use the next time a webapp launches"

# Nothing to backfill: profile selections live outside .desktop files and are created on demand.