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>
This commit is contained in:
parent
a3c05e9062
commit
7d0803481b
39 changed files with 1191 additions and 230 deletions
54
scripts/build.sh
Normal file
54
scripts/build.sh
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env sh
|
||||
# Builds Kaleido for macOS: the .app, a .dmg for first installs and the signed updater
|
||||
# archive, renamed Kaleido_<version>_<arch>.app.tar.gz for the release.
|
||||
# sh scripts/build.sh # release build
|
||||
# sh scripts/build.sh --debug # faster unoptimized build
|
||||
set -eu
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd "$root"
|
||||
profile=release
|
||||
[ "${1:-}" = "--debug" ] && profile=debug
|
||||
|
||||
sh scripts/fetch-libmpv.sh
|
||||
|
||||
# The bundled libraries decide the oldest macOS Kaleido runs on (Homebrew builds them
|
||||
# for the macOS of the machine that installed them).
|
||||
minos=$(for f in vendor/mpv/macos/*.dylib; do otool -l "$f" | awk '/LC_BUILD_VERSION/{b=1} b&&/minos/{print $2; b=0}'; done | sort -V | tail -1)
|
||||
|
||||
# Signing with one lasting certificate keeps the app's identity across updates, so the
|
||||
# Keychain keeps trusting it with the Plex token (ad hoc signatures change every build).
|
||||
# "Kaleido Self-Signed" lives in the login keychain; .tools/macos-signing.p12 backs it up.
|
||||
identity=${KALEIDO_SIGNING_IDENTITY:-Kaleido Self-Signed}
|
||||
if security find-identity -p codesigning | grep -q "\"$identity\""; then
|
||||
codesign --force --sign "$identity" vendor/mpv/macos/*.dylib 2>/dev/null
|
||||
else
|
||||
echo "warning: no \"$identity\" signing certificate; signing ad hoc (the Keychain will ask again after updates)." >&2
|
||||
identity=-
|
||||
fi
|
||||
|
||||
# The updater signing key stays outside git (.tools/), as on Windows.
|
||||
updater=true
|
||||
if [ -z "${TAURI_SIGNING_PRIVATE_KEY:-}" ]; then
|
||||
if [ -f .tools/updater.key ]; then
|
||||
TAURI_SIGNING_PRIVATE_KEY=$(cat .tools/updater.key)
|
||||
TAURI_SIGNING_PRIVATE_KEY_PASSWORD=${TAURI_SIGNING_PRIVATE_KEY_PASSWORD:-}
|
||||
export TAURI_SIGNING_PRIVATE_KEY TAURI_SIGNING_PRIVATE_KEY_PASSWORD
|
||||
else
|
||||
echo "warning: no updater signing key (.tools/updater.key); building without update artifacts." >&2
|
||||
updater=false
|
||||
fi
|
||||
fi
|
||||
config="{\"bundle\":{\"createUpdaterArtifacts\":$updater,\"macOS\":{\"minimumSystemVersion\":\"$minos\",\"signingIdentity\":\"$identity\"}}}"
|
||||
|
||||
[ -d node_modules ] || npm ci
|
||||
if [ "$profile" = debug ]; then npx tauri build --debug --config "$config"; else npx tauri build --config "$config"; fi
|
||||
|
||||
version=$(node -p "require('./package.json').version")
|
||||
arch=$(uname -m | sed 's/arm64/aarch64/; s/x86_64/x64/')
|
||||
bundle="src-tauri/target/$profile/bundle"
|
||||
if [ -f "$bundle/macos/Kaleido.app.tar.gz" ]; then
|
||||
cp "$bundle/macos/Kaleido.app.tar.gz" "$bundle/macos/Kaleido_${version}_${arch}.app.tar.gz"
|
||||
cp "$bundle/macos/Kaleido.app.tar.gz.sig" "$bundle/macos/Kaleido_${version}_${arch}.app.tar.gz.sig"
|
||||
fi
|
||||
echo "Built for macOS $minos or later:"
|
||||
ls -l "$bundle/dmg" "$bundle/macos"
|
||||
|
|
@ -1,14 +1,39 @@
|
|||
#!/usr/bin/env sh
|
||||
# macOS: copies Homebrew's libmpv into vendor/mpv/macos for bundling.
|
||||
# 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
|
||||
mkdir -p "$root/vendor/mpv/macos"
|
||||
cp "$(brew --prefix mpv)/lib/libmpv.2.dylib" "$root/vendor/mpv/macos/"
|
||||
echo "libmpv copied to vendor/mpv/macos" ;;
|
||||
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." ;;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// Creates (or reuses) a Forgejo release for a tag and uploads the Windows installer and
|
||||
// its updater signature. Reads FORGEJO_TOKEN from the environment or the ignored .env.
|
||||
// Creates (or reuses) a Forgejo release for a tag and uploads this machine's build of it:
|
||||
// the Windows installer, or the macOS disk image and updater archive, each with its
|
||||
// updater signature. Run it on each OS after building; both land in the same release.
|
||||
// Reads FORGEJO_TOKEN from the environment or the ignored .env.
|
||||
// Usage: node scripts/publish-release.mjs <version> [--prerelease]
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { api, bundleDir, releaseNotes, token } from './release-common.mjs';
|
||||
|
||||
const API = 'https://git.elijahkuntz.com/api/v1/repos/Elijah/Kaleido-Desktop';
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
const version = process.argv[2];
|
||||
const prerelease = process.argv.includes('--prerelease');
|
||||
if (!version) {
|
||||
|
|
@ -13,43 +14,38 @@ if (!version) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
let token = process.env.FORGEJO_TOKEN;
|
||||
if (!token && fs.existsSync(path.join(root, '.env'))) {
|
||||
token = fs.readFileSync(path.join(root, '.env'), 'utf8').match(/^FORGEJO_TOKEN=(.*)$/m)?.[1]?.trim().replace(/^"|"$/g, '');
|
||||
/** This version's release files as built on this OS (scripts/build.ps1 or scripts/build.sh). */
|
||||
function builtFiles() {
|
||||
if (process.platform === 'win32') {
|
||||
const dir = path.join(bundleDir, 'nsis');
|
||||
return [`Kaleido_${version}_x64-setup.exe`, `Kaleido_${version}_x64-setup.exe.sig`].map((n) => path.join(dir, n));
|
||||
}
|
||||
if (process.platform === 'darwin') {
|
||||
const arch = process.arch === 'arm64' ? 'aarch64' : 'x64';
|
||||
return [
|
||||
path.join(bundleDir, 'dmg', `Kaleido_${version}_${arch}.dmg`),
|
||||
path.join(bundleDir, 'macos', `Kaleido_${version}_${arch}.app.tar.gz`),
|
||||
path.join(bundleDir, 'macos', `Kaleido_${version}_${arch}.app.tar.gz.sig`),
|
||||
];
|
||||
}
|
||||
throw new Error('Publish releases from Windows or macOS.');
|
||||
}
|
||||
if (!token) {
|
||||
console.error('FORGEJO_TOKEN is not set.');
|
||||
process.exit(1);
|
||||
}
|
||||
const headers = { Authorization: `token ${token}`, Accept: 'application/json' };
|
||||
|
||||
async function api(method, url, body) {
|
||||
const r = await fetch(url.startsWith('http') ? url : API + url, {
|
||||
method,
|
||||
headers: body instanceof FormData ? headers : { ...headers, 'Content-Type': 'application/json' },
|
||||
body: body === undefined ? undefined : body instanceof FormData ? body : JSON.stringify(body),
|
||||
});
|
||||
const text = await r.text();
|
||||
if (!r.ok) throw new Error(`${method} ${url} → ${r.status} ${text.slice(0, 300)}`);
|
||||
return text ? JSON.parse(text) : null;
|
||||
token(true);
|
||||
const files = builtFiles();
|
||||
for (const file of files) {
|
||||
if (!fs.existsSync(file)) throw new Error(`Missing ${file}; build this version first.`);
|
||||
}
|
||||
|
||||
const tag = `v${version}`;
|
||||
const changelog = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8');
|
||||
const section = changelog.split(/^## /m).find((s) => s.startsWith(version));
|
||||
const notes = section ? section.slice(version.length).trim() : '';
|
||||
|
||||
let release = await api('GET', `/releases/tags/${tag}`).catch(() => null);
|
||||
if (!release) {
|
||||
release = await api('POST', '/releases', { tag_name: tag, name: `Kaleido Desktop ${version}`, body: notes, prerelease, draft: false });
|
||||
release = await api('POST', '/releases', { tag_name: tag, name: `Kaleido Desktop ${version}`, body: releaseNotes(version), prerelease, draft: false });
|
||||
console.log(`Created release ${release.name}`);
|
||||
} else console.log(`Using existing release ${release.name}`);
|
||||
|
||||
const dir = path.join(root, 'src-tauri/target/release/bundle/nsis');
|
||||
const files = [`Kaleido_${version}_x64-setup.exe`, `Kaleido_${version}_x64-setup.exe.sig`];
|
||||
for (const name of files) {
|
||||
const file = path.join(dir, name);
|
||||
if (!fs.existsSync(file)) throw new Error(`Missing ${file}; run scripts/build.ps1 first.`);
|
||||
for (const file of files) {
|
||||
const name = path.basename(file);
|
||||
const existing = release.assets?.find((a) => a.name === name);
|
||||
if (existing) await api('DELETE', `/releases/${release.id}/assets/${existing.id}`);
|
||||
const form = new FormData();
|
||||
|
|
|
|||
49
scripts/release-common.mjs
Normal file
49
scripts/release-common.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Shared by the release scripts: the Forgejo API (FORGEJO_TOKEN from the environment or
|
||||
// the ignored .env, never printed), release notes and the bundle folder.
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export const API = 'https://git.elijahkuntz.com/api/v1/repos/Elijah/Kaleido-Desktop';
|
||||
export const root = path.resolve(import.meta.dirname, '..');
|
||||
export const bundleDir = path.join(root, 'src-tauri/target/release/bundle');
|
||||
|
||||
/** FORGEJO_TOKEN; reads of a public repository work without it, uploads don't. */
|
||||
export function token(required = false) {
|
||||
let t = process.env.FORGEJO_TOKEN;
|
||||
if (!t && fs.existsSync(path.join(root, '.env'))) {
|
||||
t = fs.readFileSync(path.join(root, '.env'), 'utf8').match(/^FORGEJO_TOKEN=(.*)$/m)?.[1]?.trim().replace(/^"|"$/g, '');
|
||||
}
|
||||
if (!t && required) {
|
||||
console.error('FORGEJO_TOKEN is not set.');
|
||||
process.exit(1);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
const auth = () => (token() ? { Authorization: `token ${token()}` } : {});
|
||||
|
||||
export async function api(method, url, body) {
|
||||
const headers = { ...auth(), Accept: 'application/json' };
|
||||
const r = await fetch(url.startsWith('http') ? url : API + url, {
|
||||
method,
|
||||
headers: body instanceof FormData ? headers : { ...headers, 'Content-Type': 'application/json' },
|
||||
body: body === undefined ? undefined : body instanceof FormData ? body : JSON.stringify(body),
|
||||
});
|
||||
const text = await r.text();
|
||||
if (!r.ok) throw new Error(`${method} ${url} → ${r.status} ${text.slice(0, 300)}`);
|
||||
return text ? JSON.parse(text) : null;
|
||||
}
|
||||
|
||||
/** Downloads a release asset's text (an updater signature). */
|
||||
export async function download(url) {
|
||||
const r = await fetch(url, { headers: auth() });
|
||||
if (!r.ok) throw new Error(`GET ${url} → ${r.status}`);
|
||||
return r.text();
|
||||
}
|
||||
|
||||
/** The version's section of CHANGELOG.md. */
|
||||
export function releaseNotes(version) {
|
||||
const changelog = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8');
|
||||
const section = changelog.split(/^## /m).find((s) => s.startsWith(version));
|
||||
return section ? section.slice(version.length).trim() : '';
|
||||
}
|
||||
|
|
@ -1,53 +1,56 @@
|
|||
// Writes updates/latest.json, the feed Kaleido's updater reads, from built bundles.
|
||||
// Usage: node scripts/update-manifest.mjs <version> <baseDownloadUrl> [notesFile]
|
||||
// Notes come from the version's CHANGELOG.md section unless a notes file is given.
|
||||
// Each platform's signed artifact (and its .sig) must be in src-tauri/target/release/bundle,
|
||||
// or pass several bundle folders via KALEIDO_BUNDLES (path;path) when collecting CI outputs.
|
||||
// Writes updates/latest.json, the feed Kaleido's updater reads, from a published release:
|
||||
// each platform's updater artifact and signature are taken from the release's assets, so
|
||||
// the feed only ever points at this version's files, whichever machine runs it.
|
||||
// Usage: node scripts/update-manifest.mjs <version> [--allow-missing] [notesFile]
|
||||
// Every platform in PLATFORMS must be in the release (publish from each OS first);
|
||||
// --allow-missing writes the feed anyway, leaving the missing platforms out of it, so
|
||||
// their installs simply see no update until the feed is regenerated.
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { api, download, releaseNotes, root } from './release-common.mjs';
|
||||
|
||||
const [version, baseUrl, notesFile] = process.argv.slice(2);
|
||||
if (!version || !baseUrl) {
|
||||
console.error('usage: node scripts/update-manifest.mjs <version> <baseDownloadUrl> [notesFile]');
|
||||
const args = process.argv.slice(2);
|
||||
const allowMissing = args.includes('--allow-missing');
|
||||
const [version, notesFile] = args.filter((a) => !a.startsWith('--'));
|
||||
if (!version) {
|
||||
console.error('usage: node scripts/update-manifest.mjs <version> [--allow-missing] [notesFile]');
|
||||
process.exit(1);
|
||||
}
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
const bundles = (process.env.KALEIDO_BUNDLES ?? path.join(root, 'src-tauri/target/release/bundle')).split(';');
|
||||
|
||||
/** Tauri updater platform keys and the artifact each one installs. */
|
||||
/** Tauri updater platform keys and the release asset each one installs. */
|
||||
const PLATFORMS = [
|
||||
{ key: 'windows-x86_64', dir: 'nsis', match: /-setup\.exe$/ },
|
||||
{ key: 'darwin-aarch64', dir: 'macos', match: /aarch64.*\.app\.tar\.gz$/ },
|
||||
{ key: 'darwin-x86_64', dir: 'macos', match: /x64.*\.app\.tar\.gz$/ },
|
||||
{ key: 'linux-x86_64', dir: 'appimage', match: /\.AppImage$/ },
|
||||
{ key: 'windows-x86_64', match: (f) => f === `Kaleido_${version}_x64-setup.exe` },
|
||||
{ key: 'darwin-aarch64', match: (f) => f === `Kaleido_${version}_aarch64.app.tar.gz` },
|
||||
];
|
||||
|
||||
const manifestPath = path.join(root, 'updates/latest.json');
|
||||
const manifest = fs.existsSync(manifestPath) ? JSON.parse(fs.readFileSync(manifestPath, 'utf8')) : { platforms: {} };
|
||||
manifest.version = version;
|
||||
// Notes default to this version's section of CHANGELOG.md.
|
||||
const changelogNotes = () => {
|
||||
const section = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8').split(/^## /m).find((x) => x.startsWith(version));
|
||||
return section ? section.slice(version.length).trim() : '';
|
||||
};
|
||||
manifest.notes = notesFile ? fs.readFileSync(notesFile, 'utf8').trim() : changelogNotes();
|
||||
manifest.pub_date = new Date().toISOString();
|
||||
manifest.platforms ??= {};
|
||||
const release = await api('GET', `/releases/tags/v${version}`).catch(() => null);
|
||||
if (!release) throw new Error(`No release v${version}; publish it with scripts/publish-release.mjs first.`);
|
||||
const assets = release.assets ?? [];
|
||||
|
||||
for (const bundle of bundles) {
|
||||
for (const p of PLATFORMS) {
|
||||
const dir = path.join(bundle, p.dir);
|
||||
if (!fs.existsSync(dir)) continue;
|
||||
const file = fs.readdirSync(dir).find((f) => p.match.test(f) && f.includes(version));
|
||||
if (!file || !fs.existsSync(path.join(dir, `${file}.sig`))) continue;
|
||||
manifest.platforms[p.key] = {
|
||||
signature: fs.readFileSync(path.join(dir, `${file}.sig`), 'utf8').trim(),
|
||||
url: `${baseUrl.replace(/\/$/, '')}/${encodeURIComponent(file)}`,
|
||||
};
|
||||
console.log(`${p.key}: ${file}`);
|
||||
const platforms = {};
|
||||
const missing = [];
|
||||
for (const p of PLATFORMS) {
|
||||
const artifact = assets.find((a) => p.match(a.name));
|
||||
const sig = artifact && assets.find((a) => a.name === `${artifact.name}.sig`);
|
||||
if (!artifact || !sig) {
|
||||
missing.push(p.key);
|
||||
continue;
|
||||
}
|
||||
platforms[p.key] = { signature: (await download(sig.browser_download_url)).trim(), url: artifact.browser_download_url };
|
||||
console.log(`${p.key}: ${artifact.name}`);
|
||||
}
|
||||
if (missing.length && !allowMissing) {
|
||||
console.error(`v${version} has no build for ${missing.join(', ')}. Publish it from that OS, or pass --allow-missing.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!Object.keys(platforms).length) throw new Error(`v${version} has no updater artifacts.`);
|
||||
|
||||
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
||||
const manifest = {
|
||||
version,
|
||||
notes: notesFile ? fs.readFileSync(notesFile, 'utf8').trim() : releaseNotes(version),
|
||||
pub_date: new Date().toISOString(),
|
||||
platforms,
|
||||
};
|
||||
const manifestPath = path.join(root, 'updates/latest.json');
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
|
||||
console.log(`Wrote ${path.relative(root, manifestPath)}`);
|
||||
console.log(`Wrote ${path.relative(root, manifestPath)}${missing.length ? ` (without ${missing.join(', ')})` : ''}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue