#!/bin/bash
# helium-wrapper
#This is a production environment packaging script for launching the Helium browser.

#Obtain the absolute path where the script is located (typically /opt/helium)
HERE="$(dirname "$(readlink -f "${0}")")"

#Settings LD_LIBRARY_PATH
# The current directory must be added because libEGL.so, libGLESv2.so Everything is here.
# while retaining the system's original LD_LIBRARY_PATH (If there is)
export LD_LIBRARY_PATH="$HERE:$HERE/lib:$HERE/lib.target${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

# Settings CHROME_WRAPPER Variables, certain Chromium Internal logic may need to perceive that it is derived from wrapper Launched
export CHROME_WRAPPER="${0}"

# EXTRA: Add extra arguments
EXTRA_ARGS=()

# Detect if running under Wayland session
if [[ "${XDG_SESSION_TYPE}" == "wayland" ]] || [[ -n "${WAYLAND_DISPLAY}" ]]; then
    EXTRA_ARGS+=( "--disable-features=GlobalShortcutsPortal" )
    EXTRA_ARGS+=( "--ozone-platform=wayland" )
fi

# Launch the browser's main program
# "$@" Ensure all command-line arguments (such as URL or --incognito）can be accurately conveyed
exec "$HERE/chrome" "${EXTRA_ARGS[@]}" "$@"
