Skip to content

Commit

Permalink
chore: remove snap confined xdg configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Jul 21, 2021
1 parent 2227c75 commit a468471
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 223 deletions.
1 change: 0 additions & 1 deletion build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports.indentationFilter = [
'!src/vs/base/node/cpuUsage.sh',
'!test/unit/assert.js',
'!resources/linux/snap/electron-launch',
'!resources/linux/snap/hooks/configure',
'!build/ext.js',

// except specific folders
Expand Down
5 changes: 1 addition & 4 deletions build/gulpfile.vscode.linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ function prepareSnapPackage(arch) {
const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' })
.pipe(rename('electron-launch'));

const hooks = gulp.src('resources/linux/snap/hooks/configure', { base: '.' })
.pipe(rename('snap/hooks/configure'));

const all = es.merge(desktops, icon, code, snapcraft, electronLaunch, hooks);
const all = es.merge(desktops, icon, code, snapcraft, electronLaunch);

return all.pipe(vfs.dest(destination));
};
Expand Down
179 changes: 4 additions & 175 deletions resources/linux/snap/electron-launch
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,12 @@ else
ARCH="$SNAP_ARCH-linux-gnu"
fi

source "$SNAP_USER_DATA/.last_revision" 2>/dev/null || true
if [ "$SNAP_DESKTOP_LAST_REVISION" = "$SNAP_REVISION" ]; then
needs_update=false
else
needs_update=true
echo "SNAP_DESKTOP_LAST_REVISION=$SNAP_REVISION" > "$SNAP_USER_DATA/.last_revision"
fi

# Set $REALHOME to the users real home directory
REALHOME=$(getent passwd $UID | cut -d ':' -f 6)

# Set config folder to local path
export XDG_CONFIG_HOME="$SNAP_USER_DATA/.config"
ensure_dir_exists "$XDG_CONFIG_HOME"
chmod 700 "$XDG_CONFIG_HOME"

append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/lib/$ARCH"
append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH"
append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/usr/lib"
append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/lib"
append_dir PATH "$SNAP_DESKTOP_RUNTIME/usr/bin"

# XKB config
export XKB_CONFIG_ROOT="$SNAP_DESKTOP_RUNTIME/usr/share/X11/xkb"

# Give XOpenIM a chance to locate locale data.
# This is required for text input to work in SDL2 games.
export XLOCALEDIR="$SNAP_DESKTOP_RUNTIME/usr/share/X11/locale"

# Set XCursors path
export XCURSOR_PATH="$SNAP_DESKTOP_RUNTIME/usr/share/icons"
prepend_dir XCURSOR_PATH "$SNAP/data-dir/icons"

# Mesa Libs for OpenGL support
append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/mesa"
append_dir LD_LIBRARY_PATH "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/mesa-egl"
Expand Down Expand Up @@ -123,166 +96,22 @@ prepend_dir XDG_DATA_DIRS "$SNAP/share"
prepend_dir XDG_DATA_DIRS "$SNAP/data-dir"
prepend_dir XDG_DATA_DIRS "$SNAP_USER_DATA"

# Set XDG_DATA_HOME to local path
export XDG_DATA_HOME="$SNAP_USER_DATA/.local/share"
ensure_dir_exists "$XDG_DATA_HOME"

# Workaround for GLib < 2.53.2 not searching for schemas in $XDG_DATA_HOME:
# https://bugzilla.gnome.org/show_bug.cgi?id=741335
prepend_dir XDG_DATA_DIRS "$XDG_DATA_HOME"

# Set cache folder to local path
export XDG_CACHE_HOME="$SNAP_USER_COMMON/.cache"
if [[ -d "$SNAP_USER_DATA/.cache" && ! -e "$XDG_CACHE_HOME" ]]; then
GDK_CACHE_DIR="$SNAP_USER_COMMON/.cache"
if [[ -d "$SNAP_USER_DATA/.cache" && ! -e "$GDK_CACHE_DIR" ]]; then
# the .cache directory used to be stored under $SNAP_USER_DATA, migrate it
mv "$SNAP_USER_DATA/.cache" "$SNAP_USER_COMMON/"
fi
ensure_dir_exists "$XDG_CACHE_HOME"

# Ensure the app finds locale definitions (requires locales-all to be installed)
append_dir LOCPATH "$SNAP_DESKTOP_RUNTIME/usr/lib/locale"

# Keep an array of data dirs, for looping through them
IFS=':' read -r -a data_dirs_array <<< "$XDG_DATA_DIRS"

# Setup compiled gsettings schema
GS_SCHEMA_DIR="$XDG_DATA_HOME/glib-2.0/schemas"
function compile_schemas {
if [ -f "$1" ]; then
rm -rf "$GS_SCHEMA_DIR"
ensure_dir_exists "$GS_SCHEMA_DIR"
for ((i = 0; i < ${#data_dirs_array[@]}; i++)); do
schema_dir="${data_dirs_array[$i]}/glib-2.0/schemas"
if [ -f "$schema_dir/gschemas.compiled" ]; then
# This directory already has compiled schemas
continue
fi
if [ -n "$(ls -A "$schema_dir"/*.xml 2>/dev/null)" ]; then
ln -s "$schema_dir"/*.xml "$GS_SCHEMA_DIR"
fi
if [ -n "$(ls -A "$schema_dir"/*.override 2>/dev/null)" ]; then
ln -s "$schema_dir"/*.override "$GS_SCHEMA_DIR"
fi
done
# Only compile schemas if we copied anything
if [ -n "$(ls -A "$GS_SCHEMA_DIR"/*.xml "$GS_SCHEMA_DIR"/*.override 2>/dev/null)" ]; then
"$1" "$GS_SCHEMA_DIR"
fi
fi
}
if [ "$needs_update" = true ]; then
compile_schemas "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/glib-2.0/glib-compile-schemas"
fi
ensure_dir_exists "$GDK_CACHE_DIR"

# Gdk-pixbuf loaders
export GDK_PIXBUF_MODULE_FILE="$XDG_CACHE_HOME/gdk-pixbuf-loaders.cache"
export GDK_PIXBUF_MODULE_FILE="$GDK_CACHE_DIR/gdk-pixbuf-loaders.cache"
export GDK_PIXBUF_MODULEDIR="$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/gdk-pixbuf-2.0/2.10.0/loaders"
if [ -f "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders" ]; then
"$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders" > "$GDK_PIXBUF_MODULE_FILE"
fi

# Font Config and themes
export FONTCONFIG_PATH="$SNAP_DESKTOP_RUNTIME/etc/fonts"
export FONTCONFIG_FILE="$SNAP_DESKTOP_RUNTIME/etc/fonts/fonts.conf"

function make_user_fontconfig {
echo "<fontconfig>"
if [ -d "$REALHOME/.local/share/fonts" ]; then
echo " <dir>$REALHOME/.local/share/fonts</dir>"
fi
if [ -d "$REALHOME/.fonts" ]; then
echo " <dir>$REALHOME/.fonts</dir>"
fi
for ((i = 0; i < ${#data_dirs_array[@]}; i++)); do
if [ -d "${data_dirs_array[$i]}/fonts" ]; then
echo " <dir>${data_dirs_array[$i]}/fonts</dir>"
fi
done
# We need to include a user-writable cachedir first to support
# caching of per-user fonts.
echo ' <cachedir prefix="xdg">fontconfig</cachedir>'
echo " <cachedir>$SNAP_COMMON/fontconfig</cachedir>"
echo "</fontconfig>"
}

if [ "$needs_update" = true ]; then
rm -rf "$XDG_DATA_HOME"/{fontconfig,fonts,fonts-*,themes,.themes}

# This fontconfig fragment is installed in a location that is
# included by the system fontconfig configuration: namely the
# etc/fonts/conf.d/50-user.conf file.
ensure_dir_exists "$XDG_CONFIG_HOME/fontconfig"
make_user_fontconfig > "$XDG_CONFIG_HOME/fontconfig/fonts.conf"

# the themes symlink are needed for GTK 3.18 when the prefix isn't changed
# GTK 3.20 looks into XDG_DATA_DIRS which has connected themes.
if [ -d "$SNAP/data-dir/themes" ]; then
ln -sf "$SNAP/data-dir/themes" "$XDG_DATA_HOME"
ln -sfn "$SNAP/data-dir/themes" "$SNAP_USER_DATA/.themes"
elif [ -d "$SNAP_DESKTOP_RUNTIME/usr/share/themes" ]; then
ln -sf "$SNAP_DESKTOP_RUNTIME/usr/share/themes" "$XDG_DATA_HOME"
ln -sfn "$SNAP_DESKTOP_RUNTIME/usr/share/themes" "$SNAP_USER_DATA/.themes"
fi
fi

# Build mime.cache
# needed for gtk and qt icon
if [ "$needs_update" = true ]; then
rm -rf "$XDG_DATA_HOME/mime"
if [ ! -f "$SNAP_DESKTOP_RUNTIME/usr/share/mime/mime.cache" ]; then
if command -v update-mime-database >/dev/null; then
cp --preserve=timestamps -dR "$SNAP_DESKTOP_RUNTIME/usr/share/mime" "$XDG_DATA_HOME"
update-mime-database "$XDG_DATA_HOME/mime"
fi
fi
fi

# Gio modules and cache (including gsettings module)
export GIO_MODULE_DIR="$XDG_CACHE_HOME/gio-modules"
function compile_giomodules {
if [ -f "$1/glib-2.0/gio-querymodules" ]; then
rm -rf "$GIO_MODULE_DIR"
ensure_dir_exists "$GIO_MODULE_DIR"
ln -s "$1"/gio/modules/*.so "$GIO_MODULE_DIR"
"$1/glib-2.0/gio-querymodules" "$GIO_MODULE_DIR"
fi
}
if [ "$needs_update" = true ]; then
compile_giomodules "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH"
fi


# Create $XDG_RUNTIME_DIR if not exists (to be removed when https://pad.lv/1656340 is fixed)
[ -n "$XDG_RUNTIME_DIR" ] && mkdir -p "$XDG_RUNTIME_DIR" -m 700

# create symbolic link to ibus socket path for ibus to look up its socket files
# (see comments #3 and #6 on https://launchpad.net/bugs/1580463)
IBUS_CONFIG_PATH="$XDG_CONFIG_HOME/ibus"
ensure_dir_exists "$IBUS_CONFIG_PATH"
[ -d "$IBUS_CONFIG_PATH/bus" ] && rm -rf "$IBUS_CONFIG_PATH/bus"
ln -sfn "$REALHOME/.config/ibus/bus" "$IBUS_CONFIG_PATH"

# ibus and fcitx integration
GTK_IM_MODULE_DIR="$XDG_CACHE_HOME/immodules"
export GTK_IM_MODULE_FILE="$GTK_IM_MODULE_DIR/immodules.cache"
if [ "$needs_update" = true ]; then
rm -rf "$GTK_IM_MODULE_DIR"
ensure_dir_exists "$GTK_IM_MODULE_DIR"
ln -s "$SNAP_DESKTOP_RUNTIME"/usr/lib/"$ARCH"/gtk-3.0/3.0.0/immodules/*.so "$GTK_IM_MODULE_DIR"
"$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/libgtk-3-0/gtk-query-immodules-3.0" > "$GTK_IM_MODULE_FILE"
fi

# GTK theme and behavior modifier
# Those can impact the theme engine used by Qt as well
gtk_configs=(gtk-3.0/settings.ini gtk-3.0/bookmarks gtk-2.0/gtkfilechooser.ini)
for f in "${gtk_configs[@]}"; do
dest="$XDG_CONFIG_HOME/$f"
if [ ! -L "$dest" ]; then
ensure_dir_exists "$(dirname "$dest")"
ln -s "$REALHOME/.config/$f" "$dest"
fi
done

append_dir GTK_PATH "$SNAP_DESKTOP_RUNTIME/usr/lib/$ARCH/gtk-3.0"

exec "$@"
43 changes: 0 additions & 43 deletions resources/linux/snap/hooks/configure

This file was deleted.

2 changes: 2 additions & 0 deletions resources/linux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ apps:
GTK_USE_PORTAL: 1
DISABLE_WAYLAND: 1
SNAP_DESKTOP_RUNTIME: $SNAP/gnome-platform
GSETTINGS_SCHEMA_DIR: $SNAP/usr/share/glib-2.0/schemas

url-handler:
command: electron-launch $SNAP/usr/share/@@NAME@@/bin/@@NAME@@ --open-url --no-sandbox
environment:
GTK_USE_PORTAL: 1
DISABLE_WAYLAND: 1
SNAP_DESKTOP_RUNTIME: $SNAP/gnome-platform
GSETTINGS_SCHEMA_DIR: $SNAP/usr/share/glib-2.0/schemas

layout:
/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/webkit2gtk-4.0:
Expand Down

0 comments on commit a468471

Please sign in to comment.