mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +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,45 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { installQueueUndoHotkey } from '../store/playerStore';
|
||||
import { getWindowKind } from './windowKind';
|
||||
|
||||
/** Sync backend HTTP User-Agent from the main webview once at startup. */
|
||||
export function pushUserAgentToBackend(): void {
|
||||
try {
|
||||
if (getWindowKind() !== 'main') return;
|
||||
const ua = window.navigator.userAgent?.trim();
|
||||
if (ua) {
|
||||
void invoke('set_subsonic_wire_user_agent', { userAgent: ua, windowLabel: 'main' });
|
||||
}
|
||||
} catch {
|
||||
// Ignore in non-Tauri runtimes.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the persisted logging mode to Rust before React mounts. Zustand rehydrate
|
||||
* runs after first paint; AppShell's useEffect can miss the user's persisted
|
||||
* `loggingMode` until then — but waveform/audio may already run. Matches the
|
||||
* `psysonic-auth` localStorage key.
|
||||
*/
|
||||
export function pushLoggingModeToBackend(): void {
|
||||
try {
|
||||
const raw = localStorage.getItem('psysonic-auth');
|
||||
if (!raw) return;
|
||||
const parsed = JSON.parse(raw) as { state?: { loggingMode?: string } };
|
||||
const mode = parsed.state?.loggingMode;
|
||||
if (mode === 'off' || mode === 'normal' || mode === 'debug') {
|
||||
void invoke('set_logging_mode', { mode });
|
||||
}
|
||||
} catch {
|
||||
// Ignore parse / non-Tauri.
|
||||
}
|
||||
}
|
||||
|
||||
/** Orchestrates everything that must run before React mounts. */
|
||||
export function runPreReactBootstrap(): void {
|
||||
// Pre-warm the window-kind cache so subsequent reads are sync + safe.
|
||||
getWindowKind();
|
||||
pushUserAgentToBackend();
|
||||
pushLoggingModeToBackend();
|
||||
installQueueUndoHotkey();
|
||||
}
|
||||
Reference in New Issue
Block a user