mirror of
https://github.com/flectar/mail.git
synced 2026-11-11 17:57:54 +00:00
101 lines
3.7 KiB
Bash
Executable File
101 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
app_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
|
|
integrate_appimage() {
|
|
if [[ -z "${APPIMAGE:-}" || ! -f "$APPIMAGE" ]]; then
|
|
printf 'Desktop integration must be run from the packaged AppImage.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
local data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
if [[ -e "$data_home/appimagekit/no_desktopintegration" \
|
|
|| -e /usr/share/appimagekit/no_desktopintegration \
|
|
|| -e /etc/appimagekit/no_desktopintegration \
|
|
|| -n "${DESKTOPINTEGRATION:-}" ]]; then
|
|
printf 'Desktop integration is disabled or already managed on this system.\n' >&2
|
|
exit 1
|
|
fi
|
|
if command -v pgrep >/dev/null 2>&1 && pgrep -x appimaged >/dev/null 2>&1; then
|
|
printf 'Desktop integration is already managed by appimaged.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
local applications_dir="$HOME/Applications"
|
|
local installed_appimage="$applications_dir/flectar-mail.AppImage"
|
|
local desktop_dir="$data_home/applications"
|
|
local icon_root="$data_home/icons/hicolor"
|
|
local desktop_file="$desktop_dir/com.flectar.mail.desktop"
|
|
local desktop_exec
|
|
|
|
if [[ "$(readlink -f "$APPIMAGE")" != "$(readlink -m "$installed_appimage")" ]]; then
|
|
install -Dm755 "$APPIMAGE" "$installed_appimage.new"
|
|
mv -f "$installed_appimage.new" "$installed_appimage"
|
|
else
|
|
chmod 0755 "$installed_appimage"
|
|
fi
|
|
install -Dm644 \
|
|
"$app_dir/usr/share/icons/hicolor/512x512/apps/com.flectar.mail.png" \
|
|
"$icon_root/512x512/apps/com.flectar.mail.png"
|
|
install -Dm644 \
|
|
"$app_dir/usr/share/icons/hicolor/scalable/apps/com.flectar.mail.svg" \
|
|
"$icon_root/scalable/apps/com.flectar.mail.svg"
|
|
install -d "$desktop_dir"
|
|
|
|
# A Wayland compositor resolves the xdg app-id from this exact desktop-file
|
|
# basename. Point Exec at the installed AppImage without changing that ID,
|
|
# and keep the arguments: %U delivers mail links, and the New email action
|
|
# passes an empty one.
|
|
desktop_exec=${installed_appimage//\\/\\\\}
|
|
desktop_exec=${desktop_exec//\"/\\\"}
|
|
desktop_exec=${desktop_exec//\`/\\\`}
|
|
desktop_exec=${desktop_exec//\$/\\\$}
|
|
local command arguments
|
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
|
if [[ "$line" == Exec=* ]]; then
|
|
command=${line#Exec=}
|
|
arguments=
|
|
if [[ "$command" == *" "* ]]; then
|
|
arguments=" ${command#* }"
|
|
fi
|
|
printf 'Exec="%s"%s\n' "$desktop_exec" "$arguments"
|
|
else
|
|
printf '%s\n' "$line"
|
|
fi
|
|
done < "$app_dir/usr/share/applications/com.flectar.mail.desktop" \
|
|
> "$desktop_file.new"
|
|
chmod 0644 "$desktop_file.new"
|
|
mv -f "$desktop_file.new" "$desktop_file"
|
|
|
|
if command -v desktop-file-validate >/dev/null 2>&1; then
|
|
desktop-file-validate "$desktop_file"
|
|
fi
|
|
if command -v update-desktop-database >/dev/null 2>&1; then
|
|
update-desktop-database "$desktop_dir"
|
|
fi
|
|
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
|
|
gtk-update-icon-cache -f -t "$icon_root" >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
printf 'Integrated Flectar Mail at %s\n' "$installed_appimage"
|
|
printf 'Launch it from the desktop application menu.\n'
|
|
}
|
|
|
|
if [[ "${1:-}" == "--integrate" ]]; then
|
|
integrate_appimage
|
|
exit 0
|
|
fi
|
|
|
|
# The executable finds the bundled libraries in usr/lib through its RUNPATH.
|
|
# Do not export LD_LIBRARY_PATH: the browser and every other program the app
|
|
# launches would inherit it and load those libraries instead of the host's.
|
|
|
|
# The Linux binary supports Slint's Wayland and X11 winit integrations. Slint
|
|
# paints every application control while the window system owns window chrome.
|
|
export SLINT_BACKEND="${SLINT_BACKEND:-winit-software}"
|
|
|
|
# Keep the process name stable. Some native UI/runtime discovery code uses
|
|
# argv[0], while the generic cargo-appimage runner passes "AppRun" here.
|
|
exec -a flectar-mail "$app_dir/usr/bin/flectar-mail" "$@"
|