Files
psysonic/src/app/bootstrap.ts
T
cucadmuh 820f71c421 feat(dev): run dev alongside release with shared app data (#866)
* feat(dev): run dev alongside release with shared app data

Skip tauri-plugin-single-instance in debug builds so `tauri dev` can run
while an installed release instance is open. Keep the same bundle identifier
and data directory; label the dev window "Psysonic (Dev)".

* fix(dev): gate on_second_instance behind release cfg

Avoid dead_code warning in debug builds where single-instance is skipped.

* feat(dev): red sidebar brand and monochrome titlebar chrome

Tag the document in Vite dev and style the logo header with a red
background plus gray window controls so dev is obvious at a glance.

* feat(dev): skip OS hotkeys and add mobile DEV markers

Debug builds no longer register global shortcuts, MPRIS, or Windows
taskbar media controls so release keeps system input when both run.
Flip the tray icon horizontally in dev and show a fixed DEV badge on
narrow layouts.

* docs(changelog): note PR #866 parallel dev alongside release

* fix(dev): satisfy clippy needless_return in debug-only paths
2026-05-24 23:39:57 +03:00

54 lines
1.8 KiB
TypeScript

import { installQueueUndoHotkey } from '../store/queueUndoHotkey';
import { invoke } from '@tauri-apps/api/core';
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.
}
}
/** Mark the document in Vite dev so CSS can show dev-only chrome. */
export function markDevBuildDocument(): void {
if (import.meta.env.DEV) {
document.documentElement.dataset.devBuild = 'true';
}
}
/** 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();
markDevBuildDocument();
pushUserAgentToBackend();
pushLoggingModeToBackend();
installQueueUndoHotkey();
}