Release Kaleido Desktop 0.1.0-beta.12
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m22s
All checks were successful
Validate Kaleido Desktop / validate (push) Successful in 1m22s
On Windows the miniplayer is now a window of its own (mini.rs, mini.html): a borderless window owned by the main one that the video moves into (VideoSurface::set_host swaps composition targets in one commit). Dragging moves the whole window, so video and controls move together with no edge flicker; release glides it to the nearest corner or the one it's flicked towards, remembered, and it follows the main window. Its page mirrors the player over events (mini:state / mini:action). Shown and hidden natively without activation, so the main window keeps focus. macOS keeps the in-page miniplayer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c3d2f4b6a7
commit
8ed44c2fe4
22 changed files with 871 additions and 26 deletions
|
|
@ -10,6 +10,7 @@ import { win, isNative } from '../platform/native';
|
|||
import { WindowControls } from '../app/TopBar';
|
||||
import { navigate } from '../app/router';
|
||||
import { mpv } from './engine';
|
||||
import { separateMini } from './miniWindow';
|
||||
import { PREPARING_NOTICE_MS, UPSCALING_ORDER, hasFailed, readDiagnostics, requestEnhancement, tierAvailable, toggleBypass, type Diagnostics } from './enhance';
|
||||
import { toast } from '../ui/overlays';
|
||||
import type { Item } from '../plex/types';
|
||||
|
|
@ -887,7 +888,8 @@ export function PlayerOverlay() {
|
|||
}, [chromeHidden]);
|
||||
|
||||
if (!st.open || !st.item) return null;
|
||||
if (st.mini) return <MiniPlayer />;
|
||||
// On Windows the miniplayer is a window of its own (miniWindow.ts).
|
||||
if (st.mini) return separateMini ? null : <MiniPlayer />;
|
||||
const item = st.item;
|
||||
const loading = !st.firstFrame && !st.error;
|
||||
const art = item.type === 'episode' ? item.grandparentArt || item.art : item.art;
|
||||
|
|
|
|||
97
src/player/miniWindow.ts
Normal file
97
src/player/miniWindow.ts
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* The miniplayer as a window of its own (Windows, src-tauri/src/mini.rs): the
|
||||
* video moves into it, so it drags as one piece. This side keeps its page
|
||||
* (src/mini/) up to date and carries out its buttons; macOS keeps the
|
||||
* in-page miniplayer (PlayerOverlay).
|
||||
*/
|
||||
import { hostOS, invoke, isNative, listen } from '../platform/native';
|
||||
import { episodeLabel } from '../app/format';
|
||||
import { MINI_CORNER_KEY, type MiniAction, type MiniState } from '../mini/types';
|
||||
import type { Item } from '../plex/types';
|
||||
|
||||
export const separateMini = isNative && hostOS === 'windows';
|
||||
|
||||
export async function showMiniWindow() {
|
||||
await invoke('mini_show', { corner: localStorage.getItem(MINI_CORNER_KEY) ?? 'br' });
|
||||
}
|
||||
|
||||
/** Moves the video back to the main window; harmless when already there. */
|
||||
export async function hideMiniWindow() {
|
||||
await invoke('mini_hide').catch(() => {});
|
||||
}
|
||||
|
||||
interface PlayerView {
|
||||
open: boolean;
|
||||
mini: boolean;
|
||||
item: Item | null;
|
||||
paused: boolean;
|
||||
ended: boolean;
|
||||
position: number;
|
||||
duration: number;
|
||||
firstFrame: boolean;
|
||||
buffering: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
interface PlayerActions {
|
||||
togglePause(): void;
|
||||
seekBy(delta: number): void;
|
||||
expand(): void;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
|
||||
function view(st: PlayerView): MiniState {
|
||||
const item = st.item;
|
||||
return {
|
||||
title: item ? (item.type === 'episode' ? item.grandparentTitle : item.title) : '',
|
||||
subtitle: item?.type === 'episode' ? `${episodeLabel(item)} · ${item.title}` : '',
|
||||
paused: st.paused,
|
||||
ended: st.ended,
|
||||
position: st.position,
|
||||
duration: st.duration,
|
||||
loading: !st.firstFrame && !st.error,
|
||||
buffering: st.buffering,
|
||||
error: !!st.error,
|
||||
};
|
||||
}
|
||||
|
||||
/** Mirrors the player into the miniplayer window and listens for its buttons. */
|
||||
export function bridgeMiniWindow(store: { getState(): PlayerView & PlayerActions; subscribe(listener: (st: PlayerView, prev: PlayerView) => void): () => void }) {
|
||||
if (!separateMini) return;
|
||||
let lastSent = 0;
|
||||
let pending: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const send = async () => {
|
||||
pending = null;
|
||||
lastSent = Date.now();
|
||||
const st = store.getState();
|
||||
if (!st.open) return;
|
||||
const { emitTo } = await import('@tauri-apps/api/event');
|
||||
emitTo('mini', 'mini:state', view(st)).catch(() => {});
|
||||
};
|
||||
|
||||
store.subscribe((st, prev) => {
|
||||
if (!st.open || !st.mini) return;
|
||||
// Everything but the position goes straight away; the position a few times a second.
|
||||
const a = view(st);
|
||||
const b = view(prev);
|
||||
const only = (Object.keys(a) as (keyof MiniState)[]).every((k) => k === 'position' || a[k] === b[k]);
|
||||
if (!only || st.mini !== prev.mini) {
|
||||
if (pending) clearTimeout(pending);
|
||||
send();
|
||||
} else if (!pending) {
|
||||
pending = setTimeout(send, Math.max(0, 250 - (Date.now() - lastSent)));
|
||||
}
|
||||
});
|
||||
|
||||
listen<{ type: MiniAction }>('mini:action', ({ type }) => {
|
||||
const st = store.getState();
|
||||
if (type === 'ready') return send();
|
||||
if (!st.open) return;
|
||||
if (type === 'toggle') st.togglePause();
|
||||
else if (type === 'back') st.seekBy(-10);
|
||||
else if (type === 'forward') st.seekBy(10);
|
||||
else if (type === 'expand') st.expand();
|
||||
else if (type === 'close') st.close();
|
||||
});
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import { keepAwake, isNative, win } from '../platform/native';
|
|||
import { mpv, type MpvEvent, type MpvTrack } from './engine';
|
||||
import { toast } from '../ui/overlays';
|
||||
import { stopThemeMusic } from './theme';
|
||||
import { bridgeMiniWindow, hideMiniWindow, separateMini, showMiniWindow } from './miniWindow';
|
||||
|
||||
export interface Track {
|
||||
key: string; // stable UI key
|
||||
|
|
@ -700,6 +701,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
keepAwake(false);
|
||||
watchPerformance(false);
|
||||
if (isNative) {
|
||||
// From the miniplayer window, the video goes home first (and stays hidden).
|
||||
if (separateMini && st.mini) await hideMiniWindow();
|
||||
await mpv.command('stop').catch(() => {});
|
||||
await mpv.show(false).catch(() => {});
|
||||
}
|
||||
|
|
@ -767,10 +770,19 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
await win.setFullscreen(false).catch(() => {});
|
||||
set({ fullscreen: false });
|
||||
}
|
||||
if (separateMini) {
|
||||
// Once the page is opaque again (no video in it), the video moves into
|
||||
// the miniplayer's own window (miniWindow.ts).
|
||||
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
||||
if (get().open && get().mini) await showMiniWindow().catch((e) => console.warn('[mini]', e));
|
||||
}
|
||||
},
|
||||
|
||||
expand() {
|
||||
if (get().mini) set({ mini: false });
|
||||
if (!get().mini) return;
|
||||
// The video comes back behind the still-opaque page before it turns transparent.
|
||||
if (separateMini) hideMiniWindow().finally(() => set({ mini: false }));
|
||||
else set({ mini: false });
|
||||
},
|
||||
|
||||
async selectAudio(key) {
|
||||
|
|
@ -854,15 +866,21 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
usePlayer.subscribe((st, prev) => {
|
||||
if (st.firstFrame !== prev.firstFrame || st.open !== prev.open || st.error !== prev.error || st.mini !== prev.mini) {
|
||||
const html = document.documentElement.classList;
|
||||
html.toggle('video-active', st.open && st.firstFrame && !st.error);
|
||||
// With a miniplayer window, the video has left this page entirely.
|
||||
html.toggle('video-active', st.open && st.firstFrame && !st.error && !(st.mini && separateMini));
|
||||
html.toggle('player-open', st.open && !st.mini);
|
||||
html.toggle('player-mini', st.open && st.mini);
|
||||
}
|
||||
// However the miniplayer is left (expanding, playing another title, closing),
|
||||
// the video returns to the whole window.
|
||||
if (prev.mini && !st.mini && isNative) mpv.rect(null).catch(() => {});
|
||||
if (prev.mini && !st.mini && isNative) {
|
||||
if (separateMini) hideMiniWindow();
|
||||
else mpv.rect(null).catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
bridgeMiniWindow(usePlayer);
|
||||
|
||||
/** Subtitle look changes apply to the playing video straight away. */
|
||||
const SUBTITLE_PREFS = ['subtitleScale', 'subtitleColor', 'subtitleEdge', 'subtitleBox', 'subtitleBold', 'subtitlePosition'] as const;
|
||||
useSettings.subscribe((prefs, prev) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue