mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
b591a1cb5f
* refactor(app-shell): extract appShellHelpers.ts
Move SIDEBAR_COLLAPSED_STORAGE_KEY + read/persist helpers and the
shouldSuppressQueueResizerMouseDown geometry helper out of AppShell.tsx
into utils/appShellHelpers.ts.
AppShell.tsx: 691 → 639 LOC.
* refactor(app-shell): extract usePlatformShellSetup hook
Bundle the one-shot platform/window-shell effects (tiling-WM detection,
no-compositing class, data-platform attr, custom titlebar sync, kinetic
scroll toggle, logging mode push) into hooks/usePlatformShellSetup.ts.
Returns isTilingWm so AppShell can still gate the custom titlebar.
AppShell.tsx: 639 → 604 LOC.
* refactor(app-shell): extract 5 lifecycle hooks
Pull these effect islands into hooks/:
- useOrbitBodyAttrs — orbit role/phase → <html data-orbit-*> attrs
- useWindowFullscreenState — Tauri isFullscreen() tracker
- useNowPlayingTrayTitle — title + tray tooltip sync
- useTrayMenuI18n — tray menu labels via i18n
- useServerCapabilitiesProbe — music folders + rating support + orbit
orphan sweep on login
AppShell.tsx: 604 → 497 LOC.
* refactor(app-shell): extract useQueueResizer hook
Bundle queueWidth state, drag listeners, sidebar-aligned handle position,
and the click-vs-drag mousedown handler into hooks/useQueueResizer.ts.
AppShell drops shouldSuppressQueueResizerMouseDown wiring and 4 local
state pieces.
AppShell.tsx: 497 → 403 LOC.
* refactor(app-shell): extract 4 misc lifecycle hooks
- useGlobalDndAndSelectionBlockers — document-level DnD/select-all/
selectstart blockers (Linux/WebKitGTK + Wayland workarounds).
- useAppActivityTracking — <html data-app-hidden> + <html data-app-blurred>
so CSS can pause cosmetic animation when the app isn't being looked at.
- useMainScrollingIndicator — scroll-idle tracker for main + np viewports.
- useOfflineAutoNav — connStatus transitions push to /offline or back.
AppShell.tsx: 403 → 282 LOC.
* refactor(app-shell): extract AppShellQueueResizerSeam subcomponent
The 6px resizer strip and the round resize/toggle handle (~50 LOC of JSX
with embedded scrollbar-collision suppression + self-heal logic) move
into components/AppShellQueueResizerSeam.tsx. Desktop-only.
AppShell.tsx: 282 → 248 LOC.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
import { useAuthStore } from '../store/authStore';
|
|
import { IS_LINUX, IS_MACOS, IS_WINDOWS } from '../utils/platform';
|
|
|
|
/**
|
|
* One-shot platform + window-shell configuration. Reads tiling-WM state,
|
|
* applies platform-specific document attributes/classes, and pushes
|
|
* preference changes (custom titlebar, kinetic scroll, log level) into
|
|
* Rust as the user toggles them. Returns the live `isTilingWm` flag so
|
|
* AppShell can decide whether to mount the custom titlebar.
|
|
*/
|
|
export function usePlatformShellSetup(): { isTilingWm: boolean } {
|
|
const [isTilingWm, setIsTilingWm] = useState(false);
|
|
const useCustomTitlebar = useAuthStore(s => s.useCustomTitlebar);
|
|
const linuxWebkitKineticScroll = useAuthStore(s => s.linuxWebkitKineticScroll);
|
|
const loggingMode = useAuthStore(s => s.loggingMode);
|
|
|
|
useEffect(() => {
|
|
if (!IS_LINUX) return;
|
|
invoke<boolean>('is_tiling_wm_cmd').then(setIsTilingWm).catch(() => {});
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!IS_LINUX) return;
|
|
invoke<boolean>('no_compositing_mode').then(noComp => {
|
|
if (noComp) document.documentElement.classList.add('no-compositing');
|
|
}).catch(() => {});
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
const platform = IS_LINUX ? 'linux' : IS_MACOS ? 'macos' : IS_WINDOWS ? 'windows' : 'unknown';
|
|
document.documentElement.setAttribute('data-platform', platform);
|
|
}, []);
|
|
|
|
// Sync custom titlebar preference with native decorations on Linux.
|
|
// On tiling WMs decorations are always off (no native title bar to replace).
|
|
useEffect(() => {
|
|
if (!IS_LINUX) return;
|
|
const enabled = isTilingWm ? false : !useCustomTitlebar;
|
|
invoke('set_window_decorations', { enabled }).catch(() => {});
|
|
}, [useCustomTitlebar, isTilingWm]);
|
|
|
|
useEffect(() => {
|
|
if (!IS_LINUX) return;
|
|
invoke('set_linux_webkit_smooth_scrolling', { enabled: linuxWebkitKineticScroll }).catch(() => {});
|
|
}, [linuxWebkitKineticScroll]);
|
|
|
|
useEffect(() => {
|
|
invoke('set_logging_mode', { mode: loggingMode }).catch(() => {});
|
|
}, [loggingMode]);
|
|
|
|
return { isTilingWm };
|
|
}
|