Create Kaleido Desktop, a cinematic Plex client for Windows
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>
This commit is contained in:
commit
00d72e70f4
121 changed files with 25315 additions and 0 deletions
161
src/platform/native.ts
Normal file
161
src/platform/native.ts
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* The boundary between Kaleido and its host. In the desktop app this talks to
|
||||
* the Rust side through Tauri; in a plain browser (used for UI development) it
|
||||
* degrades gracefully: no video, no downloads, tokens in localStorage.
|
||||
*/
|
||||
import type { UnlistenFn } from '@tauri-apps/api/event';
|
||||
|
||||
export const isNative = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
|
||||
|
||||
export async function invoke<T>(cmd: string, args?: Record<string, unknown>): Promise<T> {
|
||||
if (!isNative) throw new Error(`${cmd} is only available in the desktop app.`);
|
||||
const { invoke } = await import('@tauri-apps/api/core');
|
||||
return invoke<T>(cmd, args);
|
||||
}
|
||||
|
||||
export async function listen<T>(event: string, handler: (payload: T) => void): Promise<UnlistenFn> {
|
||||
if (!isNative) return () => {};
|
||||
const { listen } = await import('@tauri-apps/api/event');
|
||||
return listen<T>(event, (e) => handler(e.payload));
|
||||
}
|
||||
|
||||
/** HTTP for Plex APIs: native requests avoid CORS and local-network limits. */
|
||||
let nativeFetch: typeof fetch | null = null;
|
||||
export async function httpFetch(input: string, init?: RequestInit): Promise<Response> {
|
||||
if (!isNative) return fetch(input, init);
|
||||
if (!nativeFetch) nativeFetch = (await import('@tauri-apps/plugin-http')).fetch as typeof fetch;
|
||||
return nativeFetch(input, init);
|
||||
}
|
||||
|
||||
export const secrets = {
|
||||
async get(key: string): Promise<string | null> {
|
||||
if (!isNative) return localStorage.getItem(`kaleido.dev.secret.${key}`);
|
||||
return invoke<string | null>('secret_get', { key });
|
||||
},
|
||||
async set(key: string, value: string): Promise<void> {
|
||||
if (!isNative) return localStorage.setItem(`kaleido.dev.secret.${key}`, value);
|
||||
await invoke('secret_set', { key, value });
|
||||
},
|
||||
async delete(key: string): Promise<void> {
|
||||
if (!isNative) return localStorage.removeItem(`kaleido.dev.secret.${key}`);
|
||||
await invoke('secret_delete', { key });
|
||||
},
|
||||
};
|
||||
|
||||
export interface AppInfo {
|
||||
version: string;
|
||||
dataDir: string;
|
||||
defaultDownloadDir: string;
|
||||
platform: string;
|
||||
deviceName: string;
|
||||
}
|
||||
|
||||
let info: AppInfo | null = null;
|
||||
export async function appInfo(): Promise<AppInfo> {
|
||||
if (info) return info;
|
||||
info = isNative
|
||||
? await invoke<AppInfo>('app_info')
|
||||
: { version: '0.1.0-dev', dataDir: '', defaultDownloadDir: '', platform: 'browser', deviceName: 'Browser preview' };
|
||||
return info;
|
||||
}
|
||||
|
||||
/** Local development only: start signed in from the Android project's `.env`. */
|
||||
export async function devSession(): Promise<{ server: string; token: string } | null> {
|
||||
if (!import.meta.env.DEV) return null;
|
||||
try {
|
||||
if (isNative) return await invoke<{ server: string; token: string } | null>('dev_session');
|
||||
const r = await fetch('/__dev/session');
|
||||
if (!r.ok) return null;
|
||||
const j = await r.json();
|
||||
return j.server && j.token ? j : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const win = {
|
||||
async current() {
|
||||
const { getCurrentWindow } = await import('@tauri-apps/api/window');
|
||||
return getCurrentWindow();
|
||||
},
|
||||
async minimize() {
|
||||
if (isNative) (await this.current()).minimize();
|
||||
},
|
||||
async toggleMaximize() {
|
||||
if (isNative) (await this.current()).toggleMaximize();
|
||||
},
|
||||
async close() {
|
||||
if (isNative) (await this.current()).close();
|
||||
},
|
||||
async isMaximized() {
|
||||
return isNative ? (await this.current()).isMaximized() : false;
|
||||
},
|
||||
async setFullscreen(on: boolean) {
|
||||
if (isNative) return (await this.current()).setFullscreen(on);
|
||||
if (on) await document.documentElement.requestFullscreen?.().catch(() => {});
|
||||
else if (document.fullscreenElement) await document.exitFullscreen().catch(() => {});
|
||||
},
|
||||
async isFullscreen() {
|
||||
return isNative ? (await this.current()).isFullscreen() : !!document.fullscreenElement;
|
||||
},
|
||||
async show() {
|
||||
if (isNative) {
|
||||
const w = await this.current();
|
||||
await w.show();
|
||||
await w.setFocus();
|
||||
}
|
||||
},
|
||||
async onResized(cb: () => void): Promise<UnlistenFn> {
|
||||
if (!isNative) {
|
||||
window.addEventListener('resize', cb);
|
||||
return () => window.removeEventListener('resize', cb);
|
||||
}
|
||||
return (await this.current()).onResized(cb);
|
||||
},
|
||||
};
|
||||
|
||||
export async function openExternal(url: string) {
|
||||
if (!isNative) {
|
||||
window.open(url, '_blank', 'noopener');
|
||||
return;
|
||||
}
|
||||
const { openUrl } = await import('@tauri-apps/plugin-opener');
|
||||
await openUrl(url);
|
||||
}
|
||||
|
||||
export async function revealPath(path: string) {
|
||||
if (!isNative) return;
|
||||
const { revealItemInDir } = await import('@tauri-apps/plugin-opener');
|
||||
await revealItemInDir(path);
|
||||
}
|
||||
|
||||
export async function pickFolder(defaultPath?: string): Promise<string | null> {
|
||||
if (!isNative) return null;
|
||||
const { open } = await import('@tauri-apps/plugin-dialog');
|
||||
const r = await open({ directory: true, defaultPath, multiple: false });
|
||||
return typeof r === 'string' ? r : null;
|
||||
}
|
||||
|
||||
export async function pickFile(filters?: { name: string; extensions: string[] }[]): Promise<string | null> {
|
||||
if (!isNative) return null;
|
||||
const { open } = await import('@tauri-apps/plugin-dialog');
|
||||
const r = await open({ directory: false, multiple: false, filters });
|
||||
return typeof r === 'string' ? r : null;
|
||||
}
|
||||
|
||||
export async function saveFile(defaultPath: string): Promise<string | null> {
|
||||
if (!isNative) return null;
|
||||
const { save } = await import('@tauri-apps/plugin-dialog');
|
||||
return (await save({ defaultPath })) ?? null;
|
||||
}
|
||||
|
||||
/** Converts a local file path to a URL the web view may load (offline artwork). */
|
||||
export async function localFileUrl(path: string): Promise<string> {
|
||||
if (!isNative || !path) return '';
|
||||
const { convertFileSrc } = await import('@tauri-apps/api/core');
|
||||
return convertFileSrc(path);
|
||||
}
|
||||
|
||||
export function keepAwake(enabled: boolean) {
|
||||
if (isNative) invoke('keep_awake', { enabled }).catch(() => {});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue