#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
root_dir="$( cd -P "$( dirname "$SOURCE" )"/.. >/dev/null 2>&1 && pwd )"
# 启用检查更新 for electron-updater
export APPIMAGE=0
sed -i 's#http://localhost:22331##' ~/.config/bilibili/.runtime
if [ "$DEBUG" == '1' ]; then
  echo "Debug Mode"
  ELECTRON_FORCE_IS_PACKAGED=true "/usr/bin/electron21" "$root_dir/tmp/bili/resources/app" --no-sandbox "$@"
elif [ "$DEBUG" == '2' ]; then
  echo "Debug Mode"
  ELECTRON_FORCE_IS_PACKAGED=true "/usr/bin/electron21" "/usr/share/bilibili/app" --no-sandbox "$@"
else
  echo "Release Mode"
  ELECTRON_FORCE_IS_PACKAGED=true "/usr/bin/electron21" "/usr/share/bilibili/app.asar" --no-sandbox "$@"
fi