Only do emacsclient desktop bits when launched from desktop file
In our emacsclient wrapper we can detect if we have been launched as a
desktop file via GIO_LAUNCHED_DESKTOP_FILE and
GIO_LAUNCHED_DESKTOP_FILE_PID and then only do the desktop specific parts
in that case, otherwise we can just run emacsclient directly.
Try ensure native-comp-driver-options then unset SNAP too
We can unset SNAP once we are sure we have used it so in site-start.el
first update native-comp-driver-options just in case our patched version of
comp.el didn't work for some reason and then go and unset $SNAP as well.
Unset various SNAP environment variables on startup
Firefox (and other applications) may change their behaviour when running as
a snap - as such, if we have these SNAP environment variables set in our
environment and then we go and execute say Firefox, it will assume it is
running as a snap and may then misbehave. This causes issues like Firefox
using the wrong profile as seen in https://bugs.launchpad.net/snapd/+bug/1835024 and more specifically in https://github.com/alexmurray/emacs-snap/issues/36. If we unset the
variables then we avoid any confusion in these other applications, plus
Emacs itself doesn't do anything with these anyway so it is safe to unset
them too.
When launching classic snaps, snapd generates a basic profile based off a
standard template. This profile runs in complain mode and so in general
does not restrict what a classic snap can do. However, it does result in
the process being labelled by AppArmor as
"snap.emacs.emacs (complain)". Any subsequent process launched by emacs
also then inherits this profile and so then gets labelled also by the emacs
snap AppArmor label. The Ubuntu dock appears to fall-back to indentifying
an application by it's AppArmor label and so then if say emacs launches
Firefox, the Firefox window gets associated with the Emacs icon on the dock
and not the Firefox icon. So fix this by moving the emacs snap itself to
run unconfined and as such any process it launches will also then run
unconfined too.