mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
383bbbd75f
* refactor(mini-player): H6 — extract helpers + constants
Pure code-move: window-size constants, localStorage keys + read helpers,
toMini track shape, initialSnapshot, and fmt(seconds) → utils/miniPlayerHelpers.ts.
MiniPlayer.tsx: 820 → 745 LOC.
* refactor(mini-player): H6 — extract MiniTitlebar + MiniMeta + MiniControls
Three small visual subcomponents move into components/miniPlayer/.
MiniPlayer drops the now-unused Pin/PinOff/Maximize2/X/Play/Pause/
SkipBack/SkipForward lucide icons and the CachedImage import.
MiniPlayer.tsx: 745 → 665 LOC.
* refactor(mini-player): H6 — extract MiniToolbar + useMiniVolumePopover
The whole toolbar (volume button + portaled popover, shuffle, gapless/
crossfade/infinite, queue toggle) moves into MiniToolbar.tsx. The volume
popover open-state + ref/style positioning + outside-click/Escape close
move into the useMiniVolumePopover hook.
MiniPlayer.tsx: 665 → 492 LOC.
* refactor(mini-player): H6 — extract MiniQueue + useMiniQueueDrag
The OverlayScrollArea + queue.map block moves into MiniQueue.tsx. The
PsyDnD wiring (drop-inside emits mini:reorder, drop-outside emits
mini:remove, reorder math collapsing same-position + adjusting for shift)
moves into the useMiniQueueDrag hook.
MiniPlayer.tsx: 492 → 346 LOC.
* refactor(mini-player): H6 — extract useMiniSync + useMiniWindowSetup + useMiniKeyboardShortcuts
Three more hooks pull the remaining side-effect islands out of MiniPlayer:
- useMiniSync owns mini:ready emit on mount + focus, plus the
mini:sync / audio:progress / audio:ended listeners. The hidden-window
visibility ref that gates progress now lives inside the hook.
- useMiniWindowSetup bundles three small window-bound effects:
Linux WebKitGTK smooth-scroll, the cold-start expanded-size restore
when queueOpen=true, and always-on-top reapply on mount + focus.
- useMiniKeyboardShortcuts moves the keyboard-shortcut bridge wiring.
MiniPlayer.tsx: 346 → 218 LOC.
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
import { useAuthStore } from '../store/authStore';
|
|
import { IS_LINUX } from '../utils/platform';
|
|
import {
|
|
EXPANDED_SIZE, EXPANDED_MIN, readStoredExpandedHeight,
|
|
} from '../utils/miniPlayerHelpers';
|
|
|
|
/** Three window-bound setup effects bundled together:
|
|
* - Linux WebKitGTK smooth-scroll per-window (re-applies after auth hydrates
|
|
* so preloaded/hidden mini matches the Settings toggle).
|
|
* - Initial expanded-size restore: Rust always builds the window at the
|
|
* collapsed size, so on cold start with queueOpen=true we resize once.
|
|
* - Always-on-top reapply on mount and on focus: WMs silently drop the
|
|
* constraint after Hide/Show cycles, so we re-assert it whenever the user
|
|
* actually brings the window to the foreground. */
|
|
export function useMiniWindowSetup(alwaysOnTop: boolean, initialQueueOpen: boolean) {
|
|
useEffect(() => {
|
|
if (!IS_LINUX) return;
|
|
const apply = () => {
|
|
invoke('set_linux_webkit_smooth_scrolling', {
|
|
enabled: useAuthStore.getState().linuxWebkitKineticScroll,
|
|
}).catch(() => {});
|
|
};
|
|
apply();
|
|
return useAuthStore.persist.onFinishHydration(() => {
|
|
apply();
|
|
});
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!initialQueueOpen) return;
|
|
invoke('resize_mini_player', {
|
|
width: EXPANDED_SIZE.w,
|
|
height: readStoredExpandedHeight(),
|
|
minWidth: EXPANDED_MIN.w,
|
|
minHeight: EXPANDED_MIN.h,
|
|
}).catch(() => {});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
invoke('set_mini_player_always_on_top', { onTop: alwaysOnTop }).catch(() => {});
|
|
const reapply = () => {
|
|
if (alwaysOnTop) {
|
|
invoke('set_mini_player_always_on_top', { onTop: true }).catch(() => {});
|
|
}
|
|
};
|
|
window.addEventListener('focus', reapply);
|
|
return () => window.removeEventListener('focus', reapply);
|
|
}, [alwaysOnTop]);
|
|
}
|