When the server owner stops a stream, Plex cuts the connection and repeats the termination in every timeline reply to the client until it reports a stop. The player now reads those replies (also when playback stalls or fails), stops mpv, shows the owner's message and acknowledges it; a termination on a session's first reply is left over from an earlier stream and is cleared instead of cancelling the new one. Each title also starts unpaused, as mpv keeps pause across files. The dashboard's bandwidth graph refreshes every second. Plex's real-time samples are bytes per second with idle seconds omitted, so they are laid on a gap-free per-second axis (they were divided by six before). Upscaling: Balanced is now the strongest shader chain, light nlmeans, FSRCNNX 16, KrigBilateral and debanding. Measured against 1080p references shrunk to 480p it beat FSRCNNX 8, two network passes, RAVU and SSimSuperRes. The denoiser is AN3223's light profile with luma strength at 60%, which keeps texture the default profile smoothed away. Quality is now NVIDIA RTX Video Super Resolution through mpv's d3d11vpp filter, sized to the window and re-applied when it changes; it is offered only on Windows with an NVIDIA RTX GPU (app_info now lists the adapters), runs Balanced for HDR or at native size, and drops a tier if the driver refuses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
6 KiB
TypeScript
170 lines
6 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;
|
|
/** Graphics adapters by name (empty where not reported). */
|
|
gpus: 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', gpus: [] };
|
|
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(() => {});
|
|
}
|