mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 23:35:44 +00:00
refactor(app): Phase B.1 — extract pre-React bootstrap into src/app/ (#555)
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.
This commit is contained in:
committed by
GitHub
parent
d3a8160b37
commit
0cd8998dc9
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user