Tauri 2 shell with a React/TypeScript interface and libmpv playback composed beneath the web view (DirectComposition on Windows). Shared code with per-OS platform modules and configs so macOS and Linux can follow. - Plex sign-in (browser, plex.tv/link or manual), server selection, Plex Home - Home, Movies and TV Shows (Discover, Library, Collections), search, people - Title pages with logos, ratings, cast, extras, seasons and episodes - Direct play with Plex conversion fallback, tracks, markers, autoplay - Metadata editing, artwork, fix match, refresh, analyze and deletion - Resumable offline downloads - App settings and Plex server administration with a live dashboard - Signed updater feed and Forgejo CI Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { getHomeUsers, switchHomeUser } from '../plex/account';
|
|
import type { HomeUser } from '../plex/types';
|
|
import { promptDialog, toastError } from '../ui/overlays';
|
|
import { useSession } from './session';
|
|
import { queryClient } from './queries';
|
|
|
|
/** Plex Home profiles available to the signed-in account. */
|
|
export function useHomeUsers() {
|
|
const token = useSession((s) => s.accountToken);
|
|
const home = useSession((s) => s.user?.home);
|
|
const { data } = useQuery({
|
|
queryKey: ['homeUsers', token],
|
|
queryFn: () => getHomeUsers(token!),
|
|
enabled: !!token && !!home,
|
|
staleTime: 10 * 60_000,
|
|
});
|
|
return {
|
|
users: data ?? [],
|
|
async switchTo(u: HomeUser) {
|
|
try {
|
|
let pin: string | undefined;
|
|
if (u.protected) {
|
|
const v = await promptDialog({
|
|
title: `Switch to ${u.title}`,
|
|
message: 'This profile is protected by a PIN.',
|
|
confirm: 'Switch',
|
|
input: { label: 'PIN', type: 'password', placeholder: '4-digit PIN' },
|
|
});
|
|
if (v === null) return;
|
|
pin = v;
|
|
}
|
|
const next = await switchHomeUser(token!, u.uuid, pin);
|
|
queryClient.clear();
|
|
await useSession.getState().switchUser(next);
|
|
} catch (e) {
|
|
toastError(e);
|
|
}
|
|
},
|
|
};
|
|
}
|