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:
Frank Stellmacher
2026-05-12 01:39:39 +02:00
committed by GitHub
parent d3a8160b37
commit 0cd8998dc9
8 changed files with 298 additions and 46 deletions
+2 -41
View File
@@ -1,53 +1,14 @@
import { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';
import { invoke } from '@tauri-apps/api/core';
import { getCurrentWindow } from '@tauri-apps/api/window';
import App from './App';
import { installQueueUndoHotkey } from './store/playerStore';
import { runPreReactBootstrap } from './app/bootstrap';
import './i18n';
import './styles/theme.css';
import './styles/layout.css';
import './styles/components.css';
import './styles/tracks.css';
// Expose the Tauri window label synchronously so App() can pick its root
// component (main app vs mini player) on first render without flicker.
try {
(window as any).__PSY_WINDOW_LABEL__ = getCurrentWindow().label;
} catch {
(window as any).__PSY_WINDOW_LABEL__ = 'main';
}
// Sync backend HTTP User-Agent from the main webview once at startup.
try {
const windowLabel = (window as any).__PSY_WINDOW_LABEL__ ?? 'main';
if (windowLabel === 'main') {
const ua = window.navigator.userAgent?.trim();
if (ua) {
void invoke('set_subsonic_wire_user_agent', { userAgent: ua, windowLabel });
}
}
} catch {
// Ignore in non-Tauri runtimes.
}
// Zustand rehydrate runs after first paint; AppShell's useEffect can miss the
// user's persisted `loggingMode` until then — but waveform/audio may already
// run. Push persisted mode to Rust before React mounts (matches `psysonic-auth`).
try {
const raw = localStorage.getItem('psysonic-auth');
if (raw) {
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.
}
installQueueUndoHotkey();
runPreReactBootstrap();
ReactDOM.createRoot(document.getElementById('root')!).render(
<StrictMode>