feat: work on distributions other than Arch

The README asked for "Arch or an Arch derivative" and the code had two
reasons for it. Neither of them was the mechanism, which is why this is
mostly a matter of not assuming.

The first was the flag file. Arch wraps Electron and Chromium in launchers
that read $XDG_CONFIG_HOME/<name>-flags.conf, and that route is the good
one - it survives upgrades and applies to a launch from a terminal. Debian,
Ubuntu, Fedora and openSUSE keep the equivalent under /etc, where it is the
system's file and not the user's, so there is nothing to write and those
applications have to go through their desktop entry instead. That already
worked, because a launcher is read rather than assumed - but only if the
launcher was recognised as Chromium at all, and it was not:

    APPNAME=chromium
    LIBDIR=/usr/lib/chromium
    exec -a "$APPNAME" "$LIBDIR/$APPNAME" $CHROMIUM_FLAGS "$@"

is the shape every one of those wrappers has, and following it needs the
assignments above resolved and -a understood as renaming the process rather
than naming the program. Both are done now, and the wrappers that still
cannot be followed are caught by CHROMIUM_FLAGS and CHROME_WRAPPER, which
nothing but a Chromium launcher sets. Two applications on the machine this
was written on turn out to have been missed for the same reason: Helium,
whose wrapper is followed to a payload full of markers, and ONLYOFFICE,
which ships libcef.so.

Resolving more wrappers made an old inference dangerous. Any launcher that
could be followed also had "<target>-flags.conf" invented for it, on the
theory that a wrapper builds that name from a variable at runtime. For an
application that simply execs its own binary that file is read by nobody:
the flag would have gone to ~/.config/DesktopEditors-flags.conf and the
desktop entry that would have worked was skipped. The name is now derived
only once the target has shown it reads a flag file at all.

The second reason was snaps. /snap/bin/<name> is a symlink to snapd, so
following it lands on /usr/bin/snap and says nothing; the payload is in the
mounted revision, and that tree takes the same marker check as anything
else. They get a settings switch of their own next to Flatpak, and the
launcher entry as their only way in.

Packaging is now a gate in front of the category rather than a category
beside it. A Chromium installed as a snap or a Flatpak was filed as neither
an application nor a browser, so turning browsers off did not reach it -
which on Ubuntu means the default browser. It is a browser that happens to
be packaged as a snap, and both switches apply.

The rest is the same not-assuming: Steam is found in Debian's
~/.steam/debian-installation and in the snap's private tree, the Flatpak
and snap export directories are scanned even when a session started before
they were installed left them out of XDG_DATA_DIRS, /usr/lib/x86_64-linux-gnu
counts as a shared directory the way /usr/lib does, the watcher covers
snapd's export directory and the NixOS and Guix profiles, LANG is read from
/etc/default/locale as well as /etc/locale.conf, and the systemd user unit
directory is asked of systemd instead of guessed - while still following a
PREFIX that was asked for.
This commit is contained in:
Felitendo committed 2026-08-24 10:23:47 +02:00
1 parent bd84c6645a
commit 36498f2acf
13 files changed
+455 -81

No files matched your search

+14 -12
View File
@@ -10,7 +10,7 @@
MCA_CHANGES=0
MCA_ROUTES=()
# mca_route <kind> <id> <program>
# mca_route <kind> <id> <program> [packaging]
# What happens to one application, left in MCA_ROUTE:
# flags - the launcher reads a flag file; write it there
# desktop - no flag file; shadow or edit the desktop entry
@@ -24,7 +24,7 @@ MCA_ROUTES=()
MCA_ROUTE=''
mca_route() {
local kind="$1" id="$2" prog="$3"
local kind="$1" id="$2" prog="$3" packaging="${4:-native}"
if [[ $kind == steam ]]; then
if mca_config_list_has Skip "$id" || [[ $CFG_STEAM != yes ]]; then
@@ -35,14 +35,14 @@ mca_route() {
return
fi
if ! mca_kind_wanted "$kind" "$id"; then
if ! mca_kind_wanted "$kind" "$id" "$packaging"; then
[[ $kind == unknown ]] && MCA_ROUTE=unknown || MCA_ROUTE=off
return
fi
# A Flatpak has its own copy of everything and none of the host's wrappers,
# so the desktop entry is the only way in.
if [[ $kind == flatpak ]]; then
# A Flatpak or a snap carries its own copy of everything and sees none of
# the host's wrappers, so the desktop entry is the only way in.
if [[ $packaging != native ]]; then
MCA_ROUTE=desktop
return
fi
@@ -59,7 +59,7 @@ mca_route() {
# as it likes to be - it writes only what differs, which is what keeps the
# watcher from chasing its own changes.
mca_apply() {
local i id file prog kind route steam_done=0
local i id file prog kind packaging route steam_done=0
MCA_CHANGES=0
MCA_ROUTES=()
@@ -73,8 +73,9 @@ mca_apply() {
file="${MCA_FILES[i]}"
prog="${MCA_PROGS[i]}"
kind="${MCA_KINDS[i]}"
packaging="${MCA_PACKAGING[i]}"
mca_route "$kind" "$id" "$prog"
mca_route "$kind" "$id" "$prog" "$packaging"
route="$MCA_ROUTE"
MCA_ROUTES[i]="$route"
@@ -153,9 +154,9 @@ mca_revert() {
# The watcher
# ---------------------------------------------------------------------------
# A systemd user path unit watching every directory a desktop entry can appear
# in. That covers a package installed with pacman, a Flatpak, an AppImage
# registered by hand and a Steam client update, without a hook per package
# manager.
# in. That covers a package from whatever the distribution's package manager
# is, a Flatpak, a snap, an AppImage registered by hand and a Steam client
# update, without a hook per package manager.
MCA_UNIT_PATH="middleclick-autoscroll.path"
MCA_UNIT_SERVICE="middleclick-autoscroll.service"
@@ -201,7 +202,8 @@ mca_count_routes() {
MCA_ROUTES=()
for i in "${!MCA_IDS[@]}"; do
mca_route "${MCA_KINDS[i]}" "${MCA_IDS[i]}" "${MCA_PROGS[i]}"
mca_route "${MCA_KINDS[i]}" "${MCA_IDS[i]}" "${MCA_PROGS[i]}" \
"${MCA_PACKAGING[i]}"
route="$MCA_ROUTE"
MCA_ROUTES[i]="$route"
case "$route" in
+10 -3
View File
@@ -34,7 +34,7 @@ MCA_CACHEDIR="${MCA_CACHEDIR:-${MCA_XDG_CACHE}/${MCA_NAME}}"
# Where generated desktop entries go. A file here shadows the one with the same
# name in /usr/share/applications, which is how an application gets extra
# command line arguments without touching anything pacman owns.
# command line arguments without touching a file the package manager owns.
MCA_APPDIR="${MCA_XDG_DATA}/applications"
# Copies of every file that is edited in place rather than shadowed.
@@ -60,8 +60,15 @@ mca_ui_locale() {
[[ -z $l ]] && l="${LANG:-}"
fi
if [[ -z $l && -r /etc/locale.conf ]]; then
l="$(sed -n 's/^LANG=//p' /etc/locale.conf | tr -d '"' | head -n1)"
# systemd writes /etc/locale.conf and most distributions use it; Debian and
# Ubuntu keep the same LANG= line in /etc/default/locale instead.
if [[ -z $l ]]; then
local f
for f in /etc/locale.conf /etc/default/locale; do
[[ -r $f ]] || continue
l="$(sed -n 's/^LANG=//p' "$f" | tr -d '"' | head -n1)"
[[ -n $l ]] && break
done
fi
printf '%s\n' "${l:-C}"
+1
View File
@@ -139,6 +139,7 @@ mca_config_load() {
CFG_APPS=no; mca_config_bool PatchApps yes && CFG_APPS=yes
CFG_BROWSERS=no; mca_config_bool PatchBrowsers yes && CFG_BROWSERS=yes
CFG_FLATPAK=no; mca_config_bool PatchFlatpak yes && CFG_FLATPAK=yes
CFG_SNAP=no; mca_config_bool PatchSnap yes && CFG_SNAP=yes
CFG_AUTOSTART=no; mca_config_bool PatchAutostart yes && CFG_AUTOSTART=yes
CFG_STEAM=no; mca_config_bool PatchSteam yes && CFG_STEAM=yes
CFG_SPOTIFY=no; mca_config_bool PatchSpotify yes && CFG_SPOTIFY=yes
+276 -32
View File
@@ -27,9 +27,23 @@ MCA_MARKERS=(
MCA_SYSTEM_DIRS=(
/ /bin /lib /lib32 /lib64 /sbin /usr /usr/bin /usr/lib /usr/lib32
/usr/lib64 /usr/libexec /usr/sbin /usr/local /usr/local/bin
/usr/local/lib /opt
/usr/local/lib /usr/local/libexec /opt
)
# The same thing for the layouts that put a machine triplet in the path.
# Debian and Ubuntu keep the shared libraries in /usr/lib/x86_64-linux-gnu
# rather than /usr/lib, so that directory is every bit as shared as /usr/lib is
# elsewhere and a marker sitting in it belongs to nobody in particular.
MCA_SYSTEM_DIR_GLOBS=(
'/usr/lib/*-linux-gnu*' '/usr/lib32/*-linux-gnu*'
'/usr/lib64/*-linux-gnu*' '/usr/local/lib/*-linux-gnu*'
)
# Where snapd mounts the installed snaps. /snap is the usual place and the one
# the shims point into; distributions that keep /snap free of a top-level
# directory use the second.
MCA_SNAP_DIRS=(/snap /var/lib/snapd/snap)
# Strings in a launcher script that mean it starts a Chromium or Electron
# process, for the wrappers whose command line is assembled out of variables and
# cannot be followed from the outside.
@@ -38,23 +52,51 @@ MCA_SYSTEM_DIRS=(
# "chromium" on its own is not one of them: /usr/bin/xdg-open lists every
# browser it knows how to start, and that is not a browser.
#
# The flag file convention is an Arch packaging habit and says nothing about the
# engine either, so it is not in here.
MCA_SCRIPT_HINTS='ELECTRON_|app\.asar|chrome-sandbox|libcef|enable-blink-features|ozone-platform-hint'
# The flag file convention is one distribution's packaging habit and says
# nothing about the engine either, so it is not in here.
#
# CHROMIUM_FLAGS and CHROME_WRAPPER earn their place: they are the variables
# the Debian, Fedora and openSUSE Chromium wrappers and Google's own Chrome
# wrapper build their command line out of, and nothing else sets them.
MCA_SCRIPT_HINTS='ELECTRON_|app\.asar|chrome-sandbox|libcef|enable-blink-features|ozone-platform-hint|CHROMIUM_FLAGS|CHROME_WRAPPER|CHROME_VERSION_EXTRA'
# ---------------------------------------------------------------------------
# Desktop entries
# ---------------------------------------------------------------------------
# Where Flatpak and snapd put the launchers they export. Both add these to
# XDG_DATA_DIRS themselves, through a file in /etc/profile.d - but only for a
# session that was started after they were installed, and only for a session
# manager that reads it at all. They are appended, after everything XDG names,
# so a directory that is already in the search path keeps its own position and
# the ones that were missing are still scanned.
mca_extra_desktop_dirs() {
printf '%s\n' \
"$MCA_XDG_DATA/flatpak/exports/share/applications" \
/var/lib/flatpak/exports/share/applications \
/var/lib/snapd/desktop/applications
}
# The directories a desktop entry can come from, most specific first - which is
# also XDG lookup order, so the first file found for an id is the one that is
# actually used.
mca_desktop_dirs() {
local dirs="${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" d
printf '%s\n' "$MCA_APPDIR"
while IFS= read -r -d: d; do
[[ -n $d ]] && printf '%s/applications\n' "${d%/}"
done <<< "${dirs}:"
local -A seen=()
while IFS= read -r d; do
[[ -n $d ]] || continue
d="${d%/}"
[[ -n ${seen[$d]+set} ]] && continue
seen[$d]=1
printf '%s\n' "$d"
done < <(
printf '%s\n' "$MCA_APPDIR"
while IFS= read -r -d: d; do
[[ -n $d ]] && printf '%s/applications\n' "${d%/}"
done <<< "${dirs}:"
mca_extra_desktop_dirs
)
}
# mca_desktop_get <file> <key>
@@ -192,7 +234,7 @@ mca_exec_is_steam_link() {
case "${prog##*/}" in
steam|steam-runtime) return 0 ;;
esac
[[ $prog == flatpak:com.valvesoftware.Steam ]]
[[ $prog == flatpak:com.valvesoftware.Steam || $prog == snap:steam ]]
}
# ---------------------------------------------------------------------------
@@ -265,6 +307,11 @@ _mca_has_markers() {
for s in "${MCA_SYSTEM_DIRS[@]}"; do
[[ $dir == "$s" ]] && return 1
done
for s in "${MCA_SYSTEM_DIR_GLOBS[@]}"; do
# Unquoted on purpose - these are patterns, not names.
# shellcheck disable=SC2053
[[ $dir == $s ]] && return 1
done
for m in "${MCA_MARKERS[@]}"; do
[[ -e "$dir/$m" ]] && return 0
@@ -273,23 +320,118 @@ _mca_has_markers() {
return 1
}
# The plain assignments the script made before it handed over, for
# _mca_script_subst to read. A variable of its own rather than something passed
# around: every caller of _mca_script_target reads it through a command
# substitution, so each call already works on a copy and there is nothing here
# that two of them could collide over.
declare -A MCA_SCRIPT_VARS=()
# _mca_script_subst <text>
# The text with $NAME and ${NAME} replaced by what the script assigned to them,
# left in MCA_SUBST.
#
# Fails as soon as something turns up that only a running shell could work out
# - a positional parameter, a name the script never set, a default value. That
# is the point: an unresolvable path has to come out as no path at all, never
# as a wrong one.
MCA_SUBST=''
_mca_script_subst() {
local text="$1" out='' rest name
while [[ $text == *'$'* ]]; do
out+="${text%%\$*}"
rest="${text#*\$}"
if [[ $rest == '{'* ]]; then
[[ $rest == *'}'* ]] || return 1
name="${rest%%\}*}"; name="${name#\{}"
rest="${rest#*\}}"
else
name="${rest%%[!A-Za-z0-9_]*}"
rest="${rest:${#name}}"
fi
[[ $name =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || return 1
[[ -n ${MCA_SCRIPT_VARS[$name]+set} ]] || return 1
out+="${MCA_SCRIPT_VARS[$name]}"
text="$rest"
done
MCA_SUBST="$out$text"
return 0
}
# _mca_script_target <script>
# The program a wrapper script hands over to, so a chain like
# heroic -> electron43 -> /usr/lib/electron43/electron can be followed.
#
# The assignments above the exec line are followed as well, because that is the
# shape the Chromium wrappers outside Arch have: Debian, Ubuntu, Fedora and
# openSUSE all set the directory and the program name into variables at the top
# of the script and end on `exec -a "$APPNAME" "$LIBDIR/$APPNAME"`. Without
# resolving those there is nothing to follow, and the answer would have to come
# from the hint scan - a weaker kind of evidence than finding the binary and
# its markers.
_mca_script_target() {
local script="$1" line tok
local script="$1" line tok name val skip=0
local -a tokens
local re_assign='^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)=([^[:space:];|&()`]*)[[:space:]]*$'
MCA_SCRIPT_VARS=()
while IFS= read -r line; do
if [[ $line =~ $re_assign ]]; then
name="${BASH_REMATCH[2]}"
val="${BASH_REMATCH[3]}"
# One pair of quotes around the whole value is ordinary and means
# nothing here. Single quotes also mean the value is literal, so
# there is nothing left to expand.
if [[ $val == \'*\' ]]; then
MCA_SCRIPT_VARS[$name]="${val:1:${#val}-2}"
continue
fi
[[ $val == \"*\" ]] && val="${val:1:${#val}-2}"
if _mca_script_subst "$val"; then
MCA_SCRIPT_VARS[$name]="$MCA_SUBST"
else
# Not resolvable, so anything built from it must not be either.
unset "MCA_SCRIPT_VARS[$name]"
fi
continue
fi
[[ $line =~ ^[[:space:]]*exec[[:space:]]+(.*)$ ]] || continue
read -r -a tokens <<< "${BASH_REMATCH[1]}"
skip=0
for tok in "${tokens[@]}"; do
[[ $tok == env ]] && continue
(( skip )) && { skip=0; continue; }
case "$tok" in
env) continue ;;
# `exec -a NAME PROG` renames the process. NAME is not a
# program, and it is usually the wrapper's own name, so
# following it would lead straight back here.
-a|--argv0) skip=1; continue ;;
-*) continue ;;
esac
[[ $tok == *=* && $tok != /* ]] && continue
[[ $tok == -* ]] && continue
# Anything still carrying a shell variable cannot be resolved from
# the outside; the hint scan has to answer for those.
[[ $tok == *'$'* ]] && return 1
tok="${tok%\"}"; tok="${tok#\"}"
tok="${tok%\'}"; tok="${tok#\'}"
# Anything still carrying a shell variable is resolved from the
# assignments above, or not at all; the hint scan answers for the
# wrappers that build their command line some other way.
if [[ $tok == *'$'* ]]; then
_mca_script_subst "$tok" || return 1
tok="$MCA_SUBST"
fi
[[ -n $tok ]] || return 1
if [[ $tok == /* ]]; then
printf '%s\n' "$tok"
else
@@ -302,13 +444,15 @@ _mca_script_target() {
}
# mca_flags_candidates <program>
# The flag files a launcher reads, in the order it reads them. Arch's Electron
# and Chromium wrappers all take extra arguments from
# $XDG_CONFIG_HOME/<name>-flags.conf, which is a far better place to inject than
# a desktop entry: it survives package updates and it applies to a launch from
# the terminal too.
# The flag files a launcher reads, in the order it reads them, taken from the
# launcher itself rather than assumed from the distribution. Where the wrappers
# follow that convention - Arch's Electron and Chromium packages do, and take
# extra arguments from $XDG_CONFIG_HOME/<name>-flags.conf - it is a far better
# place to inject than a desktop entry: it survives package updates and it
# applies to a launch from the terminal too. Where they do not, this finds
# nothing and the caller falls back to the desktop entry.
mca_flags_candidates() {
local prog="$1" depth="${2:-0}" target
local prog="$1" depth="${2:-0}" target inherited
(( depth > 3 )) && return 0
[[ -r $prog ]] || return 0
head -c2 -- "$prog" 2>/dev/null | grep -q '#!' || return 0
@@ -316,10 +460,22 @@ mca_flags_candidates() {
grep -oE '[A-Za-z0-9_.+-]+-flags\.conf' -- "$prog" 2>/dev/null
# A wrapper that only execs another wrapper (heroic -> electron43) inherits
# that one's flag files, plus the specific name it builds from a variable.
# that one's flag files, plus the specific name it builds from a variable
# at runtime and therefore never writes down - which is why that one is
# derived from the target's own name rather than found.
#
# It is derived only once the target has shown that it reads a flag file at
# all. Every launcher that can be followed is not a launcher that reads
# one: the Chromium wrappers outside Arch do not, and neither does an
# ordinary program that simply execs its own binary. Naming a file for
# those would put the flag somewhere nothing ever looks and skip the
# desktop entry that would have worked.
if target="$(_mca_script_target "$prog")" && [[ -n $target ]]; then
printf '%s-flags.conf\n' "${target##*/}"
mca_flags_candidates "$target" $(( depth + 1 ))
inherited="$(mca_flags_candidates "$target" $(( depth + 1 )))"
if [[ -n $inherited ]]; then
printf '%s-flags.conf\n' "${target##*/}"
printf '%s\n' "$inherited"
fi
fi
}
@@ -413,8 +569,9 @@ _mca_detect_uncached() {
MCA_IDS=() # desktop file id, without the .desktop suffix
MCA_FILES=() # the desktop entry that is in effect for that id
MCA_NAMES=() # display name
MCA_PROGS=() # resolved program, or a flatpak app id
MCA_KINDS=() # app | browser | flatpak | steam | unknown | no
MCA_PROGS=() # resolved program, or a Flatpak app id or a snap name
MCA_KINDS=() # app | browser | steam | unknown | no
MCA_PACKAGING=() # native | flatpak | snap
# The shortcuts Steam writes for single games. Not applications of their own - a
# game is whatever engine it was built with, and none of those reads a Chromium
@@ -435,11 +592,12 @@ mca_scan_once() {
}
mca_scan() {
local dir file id name exec_line prog kind i
local dir file id name exec_line prog kind packaging i
local -A seen=()
local -a c_ids=() c_files=() c_names=() c_progs=() c_browser=() c_stat=()
MCA_IDS=(); MCA_FILES=(); MCA_NAMES=(); MCA_PROGS=(); MCA_KINDS=()
MCA_PACKAGING=()
MCA_STEAM_LINKS=(); MCA_STEAM_LINK_FILES=()
# Pass one: read the entries and work out what each of them starts. No
@@ -476,6 +634,8 @@ mca_scan() {
if [[ ${prog##*/} == flatpak ]]; then
mca_exec_flatpak_id "$exec_line" || continue
prog="flatpak:$MCA_PROG"
elif mca_snap_name "$prog"; then
prog="snap:$MCA_PROG"
fi
if mca_exec_is_steam_link "$exec_line" "$prog"; then
@@ -494,14 +654,28 @@ mca_scan() {
MCA_STAT=()
_mca_stat_batch "${c_stat[@]}"
# Pass two: decide what each one is.
# Pass two: decide what each one is. What it does - an application or a
# browser - and how it was packaged are two separate questions: a Chromium
# installed as a snap is still a browser, and somebody who has turned
# browsers off means that one too.
for i in "${!c_ids[@]}"; do
prog="${c_progs[i]}"
kind=no
packaging=native
if [[ $prog == flatpak:* ]]; then
prog="${prog#flatpak:}"
mca_flatpak_is_chromium "$prog" && kind=flatpak
packaging=flatpak
mca_flatpak_is_chromium "$prog" \
&& { (( c_browser[i] )) && kind=browser || kind=app; }
elif [[ $prog == snap:* ]]; then
prog="${prog#snap:}"
packaging=snap
if [[ $prog == steam ]]; then
kind=steam
elif mca_snap_is_chromium "$prog"; then
(( c_browser[i] )) && kind=browser || kind=app
fi
elif [[ ${prog##*/} == steam || ${prog##*/} == steam-runtime ]]; then
# Steam is Chromium inside, but nothing about it can be changed
# from a command line argument; it has its own module.
@@ -519,6 +693,7 @@ mca_scan() {
MCA_NAMES+=("${c_names[i]}")
MCA_PROGS+=("$prog")
MCA_KINDS+=("$kind")
MCA_PACKAGING+=("$packaging")
done
mca_cache_flush
@@ -557,6 +732,66 @@ mca_desktop_is_browser() {
return 1
}
# mca_snap_name <program>
# The snap an executable belongs to, left in MCA_PROG - assigned rather than
# printed for the same reason mca_exec_program is: the scan asks this about
# every desktop entry on the system, and a command substitution per entry is a
# fork per entry.
#
# /snap/bin/<name> is the shim snapd puts in PATH and is a symlink to snapd
# itself, so following it lands on /usr/bin/snap and says nothing whatever
# about the application. The name is the only thing that carries information,
# and it is what leads to the mounted tree below.
mca_snap_name() {
local prog="$1" rest d
for d in "${MCA_SNAP_DIRS[@]}"; do
if [[ $prog == "$d/bin/"* ]]; then
rest="${prog#"$d/bin/"}"
# A snap that ships several programs names them <snap>.<app>.
MCA_PROG="${rest%%.*}"
return 0
fi
if [[ $prog == "$d/"* ]]; then
rest="${prog#"$d/"}"
MCA_PROG="${rest%%/*}"
return 0
fi
done
return 1
}
# mca_snap_is_chromium <snap name>
# A snap keeps everything it ships inside its own mounted revision, so the
# marker check works the same way there as anywhere else once that tree has
# been located. "current" is the symlink snapd keeps pointing at the revision
# that will actually be started.
mca_snap_is_chromium() {
local name="$1" d root
if [[ -n ${MCA_DETECT_MEMO[snap:$name]+set} ]]; then
[[ ${MCA_DETECT_MEMO[snap:$name]} == yes ]]
return $?
fi
for d in "${MCA_SNAP_DIRS[@]}"; do
root="$d/$name/current"
[[ -d $root ]] || continue
if [[ -n "$(find "$root" -maxdepth 5 \
\( -name 'chrome_crashpad_handler' -o -name 'app.asar' \
-o -name 'libcef.so' -o -name 'v8_context_snapshot.bin' \
-o -name 'chrome-sandbox' \) \
-print -quit 2>/dev/null)" ]]
then
MCA_DETECT_MEMO[snap:$name]=yes
return 0
fi
done
MCA_DETECT_MEMO[snap:$name]=no
return 1
}
# mca_flatpak_is_chromium <app id>
# Flatpak keeps every application in its own tree, so the marker check works the
# same way once that tree has been located.
@@ -584,19 +819,28 @@ mca_flatpak_is_chromium() {
return 1
}
# mca_kind_wanted <kind> <id>
# mca_kind_wanted <kind> <id> [packaging]
# Whether the current settings say this entry should be patched. Skip beats
# everything, an explicit include beats detection, and detection beats nothing.
#
# Packaging is a gate in front of the category rather than a category of its
# own: a Flatpak or a snap sees none of the host's configuration and is worth
# switching off as a group, but it is still an application or a browser and
# whichever of those the user turned off applies to it too.
mca_kind_wanted() {
local kind="$1" id="$2"
local kind="$1" id="$2" packaging="${3:-native}"
mca_config_list_has Skip "$id" && return 1
mca_config_list_has Include "$id" && return 0
case "$packaging" in
flatpak) [[ $CFG_FLATPAK == yes ]] || return 1 ;;
snap) [[ $CFG_SNAP == yes ]] || return 1 ;;
esac
case "$kind" in
app) [[ $CFG_APPS == yes ]] ;;
browser) [[ $CFG_BROWSERS == yes ]] ;;
flatpak) [[ $CFG_FLATPAK == yes && $CFG_APPS == yes ]] ;;
*) return 1 ;;
esac
}
+1
View File
@@ -215,6 +215,7 @@ MCA_SETTINGS=(
"PatchApps|bool|yes|Electron and CEF applications"
"PatchBrowsers|bool|yes|Chromium-based browsers"
"PatchFlatpak|bool|yes|Flatpak applications"
"PatchSnap|bool|yes|Snap applications"
"PatchAutostart|bool|yes|Programs that start themselves at login"
"PatchSteam|bool|yes|Steam"
"PatchSpotify|bool|yes|Spotify"
+17 -7
View File
@@ -4,15 +4,25 @@
#
# There are two ways in, and the order matters:
#
# 1. A flag file. Arch's Electron and Chromium wrappers read extra arguments
# from $XDG_CONFIG_HOME/<name>-flags.conf. This is the good one - it is the
# supported way to pass arguments, it survives package upgrades untouched,
# and it applies however the program is started, including from a terminal.
# 1. A flag file. Where the distribution wraps Electron and Chromium in a
# launcher script that reads extra arguments from
# $XDG_CONFIG_HOME/<name>-flags.conf - Arch and its derivatives do, and it
# is the convention their packages follow - this is the good one: it is
# the supported way to pass arguments, it survives package upgrades
# untouched, and it applies however the program is started, including from
# a terminal.
#
# Nothing is assumed about which distribution this is. The launcher itself
# is read, and the route is taken only for a launcher that really does
# name such a file. Elsewhere - Debian, Ubuntu, Fedora, openSUSE, where
# the equivalent file lives under /etc and is the system's to write -
# there is no flag file to use and route 2 answers for everything.
#
# 2. A desktop entry. For applications that ship their own binary with no
# wrapper - most vendor packages, every Flatpak - there is nowhere else to
# put an argument, so a copy of the entry with the flag appended goes into
# ~/.local/share/applications, where it shadows the system one.
# wrapper, and for everything a Flatpak or a snap contains, there is
# nowhere else to put an argument, so a copy of the entry with the flag
# appended goes into ~/.local/share/applications, where it shadows the
# system one.
#
# Nothing outside $HOME is ever written to.
+9 -1
View File
@@ -30,6 +30,11 @@ MCA_STEAM_LAUNCH_FLAG='-noverifyfiles'
# Every place a Steam installation is known to live, resolved and de-duplicated
# because ~/.steam/steam is normally a symlink into ~/.local/share.
#
# Which of these is the real one depends on how Steam was installed: Valve's
# own package and the Arch one use ~/.local/share/Steam, Debian's puts it in
# ~/.steam/debian-installation, and the Flatpak and the snap each keep it
# inside the private tree their sandbox gives them.
mca_steam_roots() {
local candidates=(
"$MCA_XDG_DATA/Steam"
@@ -37,6 +42,8 @@ mca_steam_roots() {
"$HOME/.steam/root"
"$HOME/.steam/debian-installation"
"$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam"
"$HOME/.var/app/com.valvesoftware.Steam/data/Steam"
"$HOME/snap/steam/common/.local/share/Steam"
)
local dir real
local -A seen=()
@@ -79,7 +86,8 @@ mca_steam_running() {
local f pid
for f in \
"$HOME/.steam/steam.pid" \
"$HOME/.var/app/com.valvesoftware.Steam/.steam/steam.pid"
"$HOME/.var/app/com.valvesoftware.Steam/.steam/steam.pid" \
"$HOME/snap/steam/common/.steam/steam.pid"
do
[[ -r $f ]] || continue
pid="$(< "$f")"