Skip to content

Commit

Permalink
Set default text/plain editor to something not LibreOffice
Browse files Browse the repository at this point in the history
Debian does not define default application, so the choice is a bit
random (in practice - lexicographical). For text/plain, it hits
LibreOffice, which is very unfriendly for text/plain. Choose something
that is not libreoffice instead.
Fedora does define gedit as default editor, but xdg-open doesn't handle
mimeapps.list, it only looks for defaults.list file. Add a symlink to
fix this (but not on Ubuntu, which ships the symlink via
desktop-file-utils package).

Re-calculate the choice on package update too, if the currently selected
editor doesn't exist anymore (happens for example when org.gnome.gedit is replaced
with org.gnome.TextEditor).

Fixes QubesOS/qubes-issues#8385
  • Loading branch information
marmarek committed Aug 2, 2023
1 parent 3ab856b commit b98ffab
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions archlinux/PKGBUILD.install
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ update_qubesconfig() {

dconf update &> /dev/null || :

/usr/lib/qubes/set-default-text-editor

# Location of files which contains list of protected files
mkdir -p /etc/qubes/protected-files.d
# shellcheck source=init/functions
Expand Down
2 changes: 2 additions & 0 deletions debian/qubes-core-agent.install
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ usr/lib/qubes/upgrades-installed-check
usr/lib/qubes/upgrades-status-notify
usr/lib/qubes/vm-file-editor
usr/lib/qubes/xdg-icon
usr/lib/qubes/set-default-text-editor
usr/lib/qubes/tinyproxy-wrapper
usr/share/glib-2.0/schemas/*
usr/share/kde4/services/*.desktop
Expand All @@ -163,6 +164,7 @@ usr/share/keyrings/qubes-ubuntu-archive-keyring.gpg
usr/share/keyrings/qubes-ubuntu-archive-keyring-4.2.gpg
usr/share/kservices5/ServiceMenus/*.desktop
usr/share/applications/*.desktop
usr/share/applications/defaults.list
usr/share/man/man1/qvm-*
usr/share/qubes/mime-override/globs
usr/share/qubes/qubes-master-key.asc
Expand Down
2 changes: 2 additions & 0 deletions debian/qubes-core-agent.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ case "${1}" in
dconf update
fi

/usr/lib/qubes/set-default-text-editor

# tell dom0 about installed updates (applications, features etc)
/etc/qubes-rpc/qubes.PostInstall || true
;;
Expand Down
4 changes: 4 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export PYTHON_PREFIX_ARG=--install-layout=deb

include /usr/share/dpkg/default.mk
export DESTDIR=$(shell pwd)/debian/tmp
DISTRIBUTION := $(shell lsb_release -is)

%:
dh $@ --with systemd,python3 --with=config-package
Expand Down Expand Up @@ -38,6 +39,9 @@ override_dh_systemd_start:
dh_systemd_start --no-restart-on-upgrade

override_dh_install:
if [ "$(DISTRIBUTION)" = "Ubuntu" ]; then \
sed -i '/defaults.list/d' debian/qubes-core-agent.install; \
fi
dh_install --fail-missing

override_dh_gencontrol:
Expand Down
6 changes: 6 additions & 0 deletions misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ UDEVRULESDIR := $(SYSLIBDIR)/udev/rules.d
QUBESDATADIR := $(DATADIR)/qubes
QUBESMIMEDIR := $(QUBESDATADIR)/xdg-override

release := $(shell lsb_release -is)

.PHONY: all clean install

all: marker-vm
Expand Down Expand Up @@ -39,10 +41,14 @@ install:
done < data-dirs
$(RM) mime/icons
umask 022 && cp -r applications mime '$(DESTDIR)$(QUBESMIMEDIR)'
if [ "$(release)" != "Ubuntu" ]; then \
ln -s mimeapps.list $(DESTDIR)/usr/share/applications/defaults.list; \
fi
install -m 0755 -d $(DESTDIR)$(BINDIR)
install -m 0755 -t $(DESTDIR)$(BINDIR) qvm-features-request
install -m 0755 -d $(DESTDIR)$(QUBESLIBDIR)
install -m 0755 -t $(DESTDIR)$(QUBESLIBDIR) qvm-service-wrapper
install -m 0755 -t $(DESTDIR)$(QUBESLIBDIR) set-default-text-editor
install -m 0755 -d $(DESTDIR)/etc/xdg/xfce4/xfconf/xfce-perchannel-xml
install -m 0644 -t $(DESTDIR)/etc/xdg/xfce4/xfconf/xfce-perchannel-xml xfce4-notifyd.xml

Expand Down
56 changes: 56 additions & 0 deletions misc/set-default-text-editor
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

text_plain_app=$(xdg-mime query default text/plain)

if [ -n "$text_plain_app" ] &&
[ -e "/usr/share/applications/$text_plain_app" ] &&
[ "$text_plain_app" != "libreoffice-writer.desktop" ]; then
# not set to libreoffice, nothing to do
exit 0
fi

text_plain_apps=$(
grep -rl '^MimeType=.*text/plain;' "/usr/share/applications" |
LC_ALL=C sort |
while read -r app; do
app_name=$(basename "$app")
if grep -q '^Terminal=[tT]' "$app"; then
continue
elif [ "$app_name" = "libreoffice-writer.desktop" ]; then
continue
fi
printf "%s" "$app_name;"
done
)

if [ -z "$text_plain_apps" ]; then
echo "No application handle text/plain, do not set default" >&2
exit 0
fi

mimeapps_file="/usr/share/applications/mimeapps.list"
touch "$mimeapps_file"
awk -v apps="$text_plain_apps" '
/^\[/ {
if (indefault && !added) {
print "text/plain=" apps
added=1
}
indefault=0
}
/^\[Default Applications\]/ { indefault=1 }
/^text\/plain=/ {
if (indefault) { print "text/plain=" apps; added=1 }
else { print }
next
}
/./ { print }
END {
if (!added) {
if (!indefault) { print "[Default Applications]" }
print "text/plain=" apps
}
}
' < "$mimeapps_file" > "$mimeapps_file.new" && \
mv "$mimeapps_file.new" "$mimeapps_file"

4 changes: 4 additions & 0 deletions rpm_spec/core-agent.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ dconf update &> /dev/null || :
# And actually setup the proxy usage in package managers
/usr/lib/qubes/update-proxy-configs

/usr/lib/qubes/set-default-text-editor

# Location of files which contains list of protected files
mkdir -p /etc/qubes/protected-files.d
. /usr/lib/qubes/init/functions
Expand Down Expand Up @@ -918,6 +920,7 @@ rm -f %{name}-%{version}
/usr/lib/qubes/upgrades-status-notify
/usr/lib/qubes/qubes-sync-clock
/usr/lib/qubes/resize-rootfs
/usr/lib/qubes/set-default-text-editor
/usr/lib/qubes/tinyproxy-wrapper
/usr/lib/dracut/dracut.conf.d/30-qubes.conf
%dir /usr/lib/qubes/init
Expand All @@ -938,6 +941,7 @@ rm -f %{name}-%{version}
/usr/share/applications/qubes-run-terminal.desktop
/usr/share/applications/qubes-open-file-manager.desktop
/usr/share/applications/qvm-open-in-dvm.desktop
/usr/share/applications/defaults.list
/usr/share/qubes/serial.conf
/usr/share/qubes/marker-vm
/usr/share/glib-2.0/schemas/20_org.gnome.settings-daemon.plugins.updates.qubes.gschema.override
Expand Down

0 comments on commit b98ffab

Please sign in to comment.