Kaleido-Desktop/src/app/TopBar.tsx
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

124 lines
5.5 KiB
TypeScript

import { useEffect, useState } from 'react';
import { navigate, topLevel, useRouter } from './router';
import { useSession } from './session';
import { useSettings } from './settings';
import { Icon } from '../ui/Icon';
import { KaleidoMark } from '../ui/primitives';
import { openMenu, type MenuItem } from '../ui/overlays';
import { isMac, isNative, shortcut, win } from '../platform/native';
import { useDownloads } from '../downloads/store';
import { useHomeUsers } from './useHomeUsers';
const NAV = [
{ id: 'home', label: 'Home', route: { name: 'home' } as const },
{ id: 'movies', label: 'Movies', route: { name: 'section', kind: 'movie', tab: 'discover' } as const },
{ id: 'shows', label: 'TV Shows', route: { name: 'section', kind: 'show', tab: 'discover' } as const },
{ id: 'downloads', label: 'Downloads', route: { name: 'downloads' } as const },
];
/** Caption buttons drawn by the page; macOS shows its own traffic lights instead. */
export function WindowControls() {
const [maximized, setMaximized] = useState(false);
useEffect(() => {
if (!isNative || isMac) return;
let off: (() => void) | undefined;
const sync = () => win.isMaximized().then(setMaximized);
sync();
win.onResized(sync).then((u) => (off = u));
return () => off?.();
}, []);
if (!isNative || isMac) return null;
return (
<div className="window-controls">
<button aria-label="Minimize" onClick={() => win.minimize()}>
<Icon name="minimize" size={15} strokeWidth={1.4} />
</button>
<button aria-label={maximized ? 'Restore' : 'Maximize'} onClick={() => win.toggleMaximize()}>
<Icon name={maximized ? 'restore' : 'maximize'} size={13} strokeWidth={1.4} />
</button>
<button aria-label="Close" className="close" onClick={() => win.close()}>
<Icon name="x" size={15} strokeWidth={1.4} />
</button>
</div>
);
}
function Avatar() {
const user = useSession((s) => s.user);
const server = useSession((s) => s.server);
const connection = useSession((s) => s.connection);
const showServerPicker = useSession((s) => s.showServerPicker);
const signOut = useSession((s) => s.signOut);
const home = useHomeUsers();
const initial = (user?.title || server?.name || 'K').slice(0, 1).toUpperCase();
const menu = (el: HTMLElement) => {
const items: MenuItem[] = [
{ heading: user ? user.title : 'Kaleido' },
{
label: server ? `${server.name}` : 'No server',
hint: connection ? (connection.relay ? 'Relay' : connection.local ? 'Local' : 'Remote') : '',
icon: 'server',
onSelect: showServerPicker,
},
];
if (home.users.length > 1) {
items.push({
label: 'Switch profile',
icon: 'users',
submenu: home.users.map((u) => ({ label: u.title, checked: u.uuid === user?.uuid, onSelect: () => home.switchTo(u) })),
});
}
// Settings has its own button in the bar; the menu keeps account actions.
if (server?.owned) items.push({ divider: true }, { label: 'Server dashboard', icon: 'activity', onSelect: () => navigate({ name: 'settings', mode: 'server', tab: 'dashboard' }) });
items.push({ divider: true }, { label: 'Sign out', icon: 'logout', onSelect: signOut });
openMenu(items, el, { align: 'end', minWidth: 250 });
};
return (
<button className="avatar-btn" aria-label="Account" onClick={(e) => menu(e.currentTarget)}>
{user?.thumb ? <img src={user.thumb} alt="" draggable={false} /> : <span>{initial}</span>}
</button>
);
}
export function TopBar({ solid }: { solid: boolean }) {
const current = useRouter((s) => s.current.route);
const canBack = useRouter((s) => s.index > 0);
const back = useRouter((s) => s.back);
const active = topLevel(current);
const activeDownloads = useDownloads((s) => s.items.filter((d) => d.status === 'downloading' || d.status === 'queued').length);
const startPage = useSettings((s) => s.startPage);
void startPage;
const showBack = canBack && !active;
return (
<header className={`topbar${solid ? ' solid' : ''}`} data-tauri-drag-region>
<div className="topbar-left" data-tauri-drag-region>
<button className={`nav-back${showBack ? ' show' : ''}`} aria-label="Back" onClick={back} tabIndex={showBack ? 0 : -1}>
<Icon name="arrowLeft" size={19} />
</button>
<button className="brand" onClick={() => navigate({ name: 'home' })} aria-label="Kaleido home">
<KaleidoMark size={24} />
<span>KALEIDO</span>
</button>
<nav className="primary-nav" aria-label="Main navigation" data-tauri-drag-region>
{NAV.map((n) => (
<button key={n.id} className={`nav-item${active === n.id ? ' active' : ''}`} onClick={() => navigate(n.route)}>
{n.label}
{n.id === 'downloads' && activeDownloads > 0 && <span className="nav-count">{activeDownloads}</span>}
</button>
))}
</nav>
</div>
<div className="topbar-right" data-tauri-drag-region>
<button className={`icon-btn${active === 'search' ? ' on' : ''}`} aria-label="Search" title={`Search (${shortcut('K')})`} onClick={() => navigate({ name: 'search' })}>
<Icon name="search" size={19} />
</button>
<button className={`icon-btn${active === 'settings' ? ' on' : ''}`} aria-label="Settings" title="Settings" onClick={() => navigate({ name: 'settings', mode: 'app', tab: 'general' })}>
<Icon name="settings" size={19} />
</button>
<Avatar />
<WindowControls />
</div>
</header>
);
}