mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
0cd8998dc9
main.tsx shrinks from 56 -> 17 LOC. New module surface:
- src/app/windowKind.ts: cached getWindowKind() detector,
replaces the global __PSY_WINDOW_LABEL__ string everywhere
- src/app/bootstrap.ts: pushUserAgentToBackend +
pushLoggingModeToBackend + runPreReactBootstrap orchestrator
App.tsx + playerStore.ts now read getWindowKind() instead of poking
window.__PSY_WINDOW_LABEL__ directly. Behaviour-preserving.
31 lines
900 B
TypeScript
31 lines
900 B
TypeScript
import { getCurrentWindow } from '@tauri-apps/api/window';
|
|
|
|
export type WindowKind = 'main' | 'mini';
|
|
|
|
let cached: WindowKind | null = null;
|
|
|
|
/**
|
|
* Tauri window-label detection, cached after the first call. The result
|
|
* decides whether App() renders the full main UI tree or the standalone
|
|
* mini-player tree, and it must be consistent for the lifetime of the
|
|
* webview — Tauri never changes a window's label.
|
|
*
|
|
* Falls back to 'main' in non-Tauri environments (jsdom, plain browser).
|
|
*/
|
|
export function getWindowKind(): WindowKind {
|
|
if (cached !== null) return cached;
|
|
let label: string;
|
|
try {
|
|
label = getCurrentWindow().label;
|
|
} catch {
|
|
label = 'main';
|
|
}
|
|
cached = label === 'mini' ? 'mini' : 'main';
|
|
return cached;
|
|
}
|
|
|
|
/** Test-only: clears the cached window kind so each test starts clean. */
|
|
export function _resetWindowKindCacheForTest(): void {
|
|
cached = null;
|
|
}
|