Upscaling is chosen in the player (Playback options, or U): Performance uses spline36 scaling, debanding and AMD CAS sharpening; Balanced adds FSRCNNX neural luma upscaling and KrigBilateral chroma reconstruction. The shaders ship in src-tauri/shaders and their WHEN conditions decide whether they run for the current video and window size; HDR titles skip CAS, which assumes SDR gamma. The title above the scrub bar now opens its show, movie or episode page with playback moving to the miniplayer. Leaving the miniplayer any way (including starting another title, which left the app invisible) puts the video back over the whole window. The scrub bar separates played and buffered sections more clearly, and its preview keeps its size at the end of the bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
168 lines
5.9 KiB
TypeScript
168 lines
5.9 KiB
TypeScript
/**
|
|
* 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);
|
|
}
|
|
|
|
/** Absolute path of a file bundled with the app (Tauri resources), or '' in a browser. */
|
|
export async function resourcePath(relative: string): Promise<string> {
|
|
if (!isNative) return '';
|
|
const { resolveResource } = await import('@tauri-apps/api/path');
|
|
return resolveResource(relative);
|
|
}
|
|
|
|
export function keepAwake(enabled: boolean) {
|
|
if (isNative) invoke('keep_awake', { enabled }).catch(() => {});
|
|
}
|