.chromium-app.lib.sh 698 B

1234567891011121314151617181920212223242526272829303132333435
  1. # vim: ft=sh
  2. # shellcheck shell=sh
  3. run_app() {
  4. set -ue
  5. name="${1:?provide app name}"
  6. app="${2:-}"
  7. chromium="chromium${CHROMIUM_NO_VPN:+-nv}"
  8. if [ -n "${CHROMIUM_TEMPORARY:-}" ]; then
  9. apps_dir="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/chromium-apps"
  10. else
  11. apps_dir="${HOME}/.cache/chromium-apps"
  12. fi
  13. dir="${apps_dir}/${name}"
  14. [ -z "${app}" ] && echo 'WARNING: no app url provided' 1>&2
  15. mkdir -p "${dir}"
  16. cd "${dir}"
  17. [ -n "${CHROMIUM_TEMPORARY:-}" ] && {
  18. ppid="${$}"
  19. # shellcheck disable=2016
  20. chromium_tmp_dir="${dir}" \
  21. waitpid "${ppid}" \
  22. 'exec rm -rf -- "${chromium_tmp_dir:?}"' &
  23. }
  24. exec "${chromium}" \
  25. --user-data-dir="../${dir##*/}" \
  26. ${app:+--app="${app}"}
  27. }