Files
SodiumPet/scripts/linux/sodiumpet-launcher.sh
T
deepseek 9313704918 feat(linux): 支持 Linux / Wayland 桌面运行
- 新增 src/main/platform.ts:Ozone 后端选择(Wayland 优先 XWayland)、
  能力降级封装、XDG 数据目录、缺参 relaunch
- 主进程窗口定位/置顶/跨工作区/拖拽/视线跟随改为平台能力封装
- 托盘失败容错、Linux 窗口图标、pet:// 缺失文件返回 404
- 新增 scripts/linux/{install,run,uninstall}.sh 与启动器、desktop 菜单项、自启动
- 新增 assets/linux 应用图标;README 增加 Linux/Wayland 文档
- 清理仓库根目录误提交的 Chromium 日志文件
2026-12-02 05:13:49 +09:00

81 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# SodiumPet Linux 启动器
#
# 由 scripts/linux/install.sh 安装到 <PREFIX>/bin/sodiumpet。
# 这里负责三件事:
# 1. 设置数据目录(SODIUM_PET_HOME,默认 <PREFIX>/home);
# 2. 选择 Chromium 显示后端:Wayland 会话优先 XWayland(窗口可定位/置顶/穿透),
# 没有 XWayland 时才退回原生 Wayland;
# 3. 个别系统禁用了非特权 user namespace 时,自动补 --no-sandbox。
set -eu
SELF="$(readlink -f "$0")"
PREFIX="$(cd "$(dirname "$SELF")/.." && pwd)"
APP_DIR="$PREFIX/app"
ELECTRON="$PREFIX/electron/electron"
if [ ! -x "$ELECTRON" ]; then
echo "SodiumPet: 找不到 $ELECTRON,请重新运行 scripts/linux/install.sh" >&2
exit 1
fi
export SODIUM_PET_HOME="${SODIUM_PET_HOME:-$PREFIX/home}"
: "${XDG_RUNTIME_DIR:=/run/user/$(id -u)}"
export XDG_RUNTIME_DIR
# ---- 显示后端 ----
ozone="${SODIUM_PET_OZONE:-auto}"
if [ "$ozone" = "auto" ]; then
if [ -n "${WAYLAND_DISPLAY:-}" ] || [ "${XDG_SESSION_TYPE:-}" = "wayland" ]; then
if [ -n "${DISPLAY:-}" ]; then
ozone="x11" # XWayland:功能完整
else
ozone="wayland" # 原生 Wayland:没有 XWayland 时的兜底
fi
else
ozone="x11"
fi
fi
if [ "$ozone" = "x11" ] && [ -z "${DISPLAY:-}" ]; then
echo "SodiumPet: 当前没有 DISPLAY,改用原生 Wayland(窗口位置/置顶会受限)" >&2
ozone="wayland"
fi
# 登录自启动时 XWayland 可能还没就绪:等一小会儿 X socket,仍没有就退回原生 Wayland
if [ "$ozone" = "x11" ]; then
disp="${DISPLAY#*:}"
disp="${disp%%.*}"
xsock="/tmp/.X11-unix/X$disp"
i=0
while [ ! -S "$xsock" ] && [ "$i" -lt 50 ]; do
sleep 0.1
i=$((i + 1))
done
if [ ! -S "$xsock" ] && [ -n "${WAYLAND_DISPLAY:-}" ]; then
echo "SodiumPet: X socket $xsock 未就绪,改用原生 Wayland" >&2
ozone="wayland"
fi
fi
EXTRA="--ozone-platform=$ozone"
# ---- 沙箱兜底 ----
if [ "${SODIUM_PET_DISABLE_SANDBOX:-0}" = "1" ]; then
EXTRA="$EXTRA --no-sandbox"
elif [ -e "$PREFIX/electron/chrome-sandbox" ] && [ ! -u "$PREFIX/electron/chrome-sandbox" ]; then
restrict="$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns 2>/dev/null || echo 0)"
userns="$(cat /proc/sys/user/max_user_namespaces 2>/dev/null || echo 1)"
if [ "$restrict" = "1" ] || [ "$userns" = "0" ]; then
EXTRA="$EXTRA --no-sandbox"
fi
fi
mkdir -p "$PREFIX/logs"
if [ "${SODIUM_PET_LOG:-1}" = "1" ]; then
LOG="$PREFIX/logs/sodiumpet.log"
: > "$LOG"
exec "$ELECTRON" $EXTRA "$APP_DIR" "$@" >>"$LOG" 2>&1
else
exec "$ELECTRON" $EXTRA "$APP_DIR" "$@"
fi