#!/bin/sh
set -eu

# AFFiNE is an Electron app staged by apply_extra to /app/extra/affine. Run it
# through zypak-wrapper (from org.electronjs.Electron2.BaseApp): zypak redirects
# Chromium's SUID sandbox onto the Flatpak sandbox, so the app keeps an internal
# sandbox rather than running with --no-sandbox. --ozone-platform-hint=auto lets
# Chromium use Wayland when available and fall back to X11. Flatpak redirects
# $HOME, so the local-first workspace under ~/.config/AFFiNE stays sandboxed.
#
# Defensively clear ELECTRON_RUN_AS_NODE: if it leaks in from the launching
# environment (e.g. a terminal inside VS Code/Electron), the binary would start
# as plain Node instead of the GUI app.
unset ELECTRON_RUN_AS_NODE
exec zypak-wrapper /app/extra/affine/AFFiNE --ozone-platform-hint=auto "$@"
