Kaleido-Desktop/scripts/fetch-libmpv.sh
Elijah Kuntz 7d0803481b Port Kaleido Desktop to macOS
macOS (Apple silicon) now plays, browses and updates like Windows:

- Video: libmpv's render API draws into a CAOpenGLLayer beneath the
  WKWebView, with the miniplayer rectangle, HDR passthrough through
  extended dynamic range (PQ/BT.2020) and display-sleep prevention.
- Window: native traffic lights on the top bar's centre line, hidden
  with the player's controls; the page's caption buttons are Windows-only.
- Interface: macOS shortcut labels (⌘K, ⌘[, ⌃⌘F), Plex identifies the
  player as a Mac, and header values are kept ASCII (Mac computer names
  usually contain a curly apostrophe).
- The window appears without waiting for an animation frame, which
  WKWebView doesn't run in a hidden window.
- Credentials: release builds use the Keychain and are signed with a
  lasting self-signed certificate so access survives updates; debug
  builds keep tokens in a private file to avoid prompts on every rebuild.
- Bundling: scripts/fetch-libmpv.sh makes Homebrew's libmpv and its
  libraries self-contained; scripts/build.sh builds the .app, .dmg and
  signed update archive.

Releases now carry both platforms: publish-release.mjs uploads each
machine's build into one release, and update-manifest.mjs writes the
feed from that release's assets, refusing while a platform is missing.

The updater uses a new signing key (public key in tauri.conf.json), so
existing installs must be reinstalled once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 15:14:40 -07:00

40 lines
2.3 KiB
Bash

#!/usr/bin/env sh
# macOS: copies Homebrew's libmpv and every library it links (ffmpeg, libplacebo, ...)
# into vendor/mpv/macos, pointing them at each other with @loader_path so the folder is
# self-contained; the bundle ships it as Contents/Frameworks.
# Linux: libmpv comes from the system package (libmpv2); nothing to copy.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
case "$(uname -s)" in
Darwin)
out="$root/vendor/mpv/macos"
if [ -f "$out/libmpv.2.dylib" ] && [ "${1:-}" != "--force" ]; then
echo "libmpv already in vendor/mpv/macos (pass --force to refresh)"
exit 0
fi
brew list mpv >/dev/null 2>&1 || brew install mpv
command -v dylibbundler >/dev/null 2>&1 || brew install dylibbundler
rm -rf "$out" && mkdir -p "$out"
cp "$(brew --prefix mpv)/lib/libmpv.2.dylib" "$out/"
chmod u+w "$out/libmpv.2.dylib"
install_name_tool -id @loader_path/libmpv.2.dylib "$out/libmpv.2.dylib"
# -of: overwrite, -b: bundle dependencies, -x: fix this file, -d: where they go,
# -p: how they're referenced, -s: also search Homebrew's lib folder for @rpath names.
dylibbundler -of -b -x "$out/libmpv.2.dylib" -d "$out" -p @loader_path/ -s "$(brew --prefix)/lib" >/dev/null
for f in "$out"/*.dylib; do
# dylibbundler can repeat an rpath, which dyld refuses to load; keep one of each.
for rpath in $(otool -l "$f" | awk '/cmd LC_RPATH/{getline; getline; print $2}' | sort | uniq -d); do
while [ "$(otool -l "$f" | awk '/cmd LC_RPATH/{getline; getline; print $2}' | grep -cx "$rpath")" -gt 1 ]; do
install_name_tool -delete_rpath "$rpath" "$f" 2>/dev/null
done
done
# Rewriting load commands invalidates signatures; Apple silicon refuses unsigned code.
codesign --force --sign - "$f" 2>/dev/null
done
# Homebrew builds for the macOS it runs on: the oldest macOS these libraries load on.
minos=$(for f in "$out"/*.dylib; do otool -l "$f" | awk '/LC_BUILD_VERSION/{b=1} b&&/minos/{print $2; b=0}'; done | sort -V | tail -1)
echo "libmpv and $(($(ls "$out" | wc -l) - 1)) libraries copied to vendor/mpv/macos (need macOS $minos or later)" ;;
Linux)
echo "Install libmpv from your distribution (e.g. apt install libmpv2 libmpv-dev)." ;;
*) echo "Use scripts/fetch-libmpv.ps1 on Windows." ;;
esac