mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
9609da6bc2
`▶` (U+25B6, Geometric-Shapes) renders well below the baseline in most OS title-bar fonts (Segoe UI on Windows, Cantarell on GNOME, etc.), while `⏸` (U+23F8, Miscellaneous-Technical) sits correctly centred. Switching the play glyph to `⏵` (U+23F5) — the designated `⏸` pair from the same Unicode block — keeps the two states visually aligned with the surrounding text. In-app custom title bar already looks correct and is left untouched.
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import { useEffect } from 'react';
|
||
import { invoke } from '@tauri-apps/api/core';
|
||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||
import type { Track } from '../store/playerStoreTypes';
|
||
|
||
/**
|
||
* Keep `document.title`, the OS window title, and the tray tooltip in sync
|
||
* with the currently playing track. Tray tooltip uses an en-dash separator
|
||
* (` – `) and tags playback state for the tray badge.
|
||
*/
|
||
export function useNowPlayingTrayTitle(currentTrack: Track | null, isPlaying: boolean): void {
|
||
useEffect(() => {
|
||
const fn = async () => {
|
||
try {
|
||
const appWindow = getCurrentWindow();
|
||
if (currentTrack) {
|
||
// `⏵` (U+23F5) instead of `▶` (U+25B6): the Geometric-Shapes triangle
|
||
// renders well below the baseline in most OS title-bar fonts (Segoe UI,
|
||
// GNOME Cantarell, etc.), while the Miscellaneous-Technical pair
|
||
// `⏵`/`⏸` shares metrics and stays centred next to the text.
|
||
const state = isPlaying ? '⏵' : '⏸';
|
||
const title = `${state} ${currentTrack.artist} - ${currentTrack.title} | Psysonic`;
|
||
document.title = title;
|
||
await appWindow.setTitle(title);
|
||
await invoke('set_tray_tooltip', {
|
||
tooltip: `${currentTrack.artist} – ${currentTrack.title}`,
|
||
playbackState: isPlaying ? 'play' : 'pause',
|
||
}).catch(() => {});
|
||
} else {
|
||
document.title = 'Psysonic';
|
||
await appWindow.setTitle('Psysonic');
|
||
await invoke('set_tray_tooltip', {
|
||
tooltip: '',
|
||
playbackState: 'stop',
|
||
}).catch(() => {});
|
||
}
|
||
} catch {
|
||
// Ignore Tauri IPC failures — title sync is best-effort.
|
||
}
|
||
};
|
||
fn();
|
||
}, [currentTrack, isPlaying]);
|
||
}
|