#!/bin/bash

# Return the per-user runtime directory used by long-lived Patchcord state.
pc_runtime_dir() {
  local root
  if [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then
    root="${TMPDIR:-$(mktemp -d 2>/dev/null || true)}"
  else
    root="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
  fi
  [ -n "$root" ] || return 1
  mkdir -p "$root" 2>/dev/null || return 1
  printf '%s\n' "${root%/}"
}
