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
153
src/mini/main.tsx
Normal file
153
src/mini/main.tsx
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
* The miniplayer window's page (mini.html; src-tauri/src/mini.rs). The video
|
||||
* is drawn beneath this transparent page by the native side; this page draws
|
||||
* the controls, mirrors the main window's player (src/player/miniWindow.ts)
|
||||
* and sends its buttons back. Dragging moves the whole window natively.
|
||||
*/
|
||||
import { StrictMode, useEffect, useState, type PointerEvent as ReactPointerEvent } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { emitTo, listen } from '@tauri-apps/api/event';
|
||||
import '@fontsource-variable/inter';
|
||||
import '../styles/base.css';
|
||||
import '../styles/ui.css';
|
||||
import '../styles/player.css';
|
||||
import './mini.css';
|
||||
import { Icon } from '../ui/Icon';
|
||||
import { MINI_CORNER_KEY, type MiniAction, type MiniState } from './types';
|
||||
|
||||
const send = (type: MiniAction) => emitTo('main', 'mini:action', { type }).catch(() => {});
|
||||
|
||||
window.addEventListener('contextmenu', (e) => e.preventDefault());
|
||||
|
||||
/**
|
||||
* Drags the window: moves go to the native side one at a time, latest first
|
||||
* (each is relative to where the drag began), and letting go glides it to a
|
||||
* corner. A drag that ends over a button doesn't press it.
|
||||
*/
|
||||
function startDrag(e: ReactPointerEvent<HTMLElement>) {
|
||||
if (e.button !== 0) return;
|
||||
const el = e.currentTarget;
|
||||
const pointer = e.pointerId;
|
||||
const origin = { x: e.screenX, y: e.screenY };
|
||||
const trail: { t: number; x: number; y: number }[] = [];
|
||||
let dragging = false;
|
||||
let started: Promise<unknown> | null = null;
|
||||
let inFlight: Promise<unknown> | null = null;
|
||||
let latest: { dx: number; dy: number } | null = null;
|
||||
|
||||
const pump = () => {
|
||||
if (inFlight || !latest || !started) return;
|
||||
const next = latest;
|
||||
latest = null;
|
||||
inFlight = started
|
||||
.then(() => invoke('mini_drag', next))
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
inFlight = null;
|
||||
pump();
|
||||
});
|
||||
};
|
||||
|
||||
const move = (ev: PointerEvent) => {
|
||||
const dx = ev.screenX - origin.x;
|
||||
const dy = ev.screenY - origin.y;
|
||||
trail.push({ t: ev.timeStamp, x: ev.screenX, y: ev.screenY });
|
||||
while (trail.length > 2 && ev.timeStamp - trail[0].t > 100) trail.shift();
|
||||
if (!dragging) {
|
||||
if (Math.hypot(dx, dy) < 4) return;
|
||||
dragging = true;
|
||||
document.documentElement.classList.add('dragging');
|
||||
el.setPointerCapture(pointer);
|
||||
started = invoke('mini_drag_start').catch(() => {});
|
||||
}
|
||||
latest = { dx, dy };
|
||||
pump();
|
||||
};
|
||||
|
||||
const up = async () => {
|
||||
window.removeEventListener('pointermove', move);
|
||||
window.removeEventListener('pointerup', up);
|
||||
window.removeEventListener('pointercancel', up);
|
||||
if (!dragging) return;
|
||||
document.documentElement.classList.remove('dragging');
|
||||
const swallow = (c: MouseEvent) => {
|
||||
c.stopPropagation();
|
||||
c.preventDefault();
|
||||
};
|
||||
window.addEventListener('click', swallow, { capture: true, once: true });
|
||||
setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0);
|
||||
|
||||
const first = trail[0];
|
||||
const last = trail[trail.length - 1];
|
||||
const dt = first && last ? Math.max(1, last.t - first.t) : 1;
|
||||
const vx = first && last ? (last.x - first.x) / dt : 0;
|
||||
const vy = first && last ? (last.y - first.y) / dt : 0;
|
||||
// The last move lands before the glide begins.
|
||||
while (inFlight || latest) await (inFlight ?? Promise.resolve(pump()));
|
||||
const corner = await invoke<string>('mini_snap', { vx, vy }).catch(() => '');
|
||||
if (corner) localStorage.setItem(MINI_CORNER_KEY, corner);
|
||||
};
|
||||
|
||||
window.addEventListener('pointermove', move);
|
||||
window.addEventListener('pointerup', up);
|
||||
window.addEventListener('pointercancel', up);
|
||||
}
|
||||
|
||||
function Mini() {
|
||||
const [s, setS] = useState<MiniState | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = listen<MiniState>('mini:state', (e) => setS(e.payload));
|
||||
unlisten.then(() => send('ready'));
|
||||
return () => void unlisten.then((f) => f());
|
||||
}, []);
|
||||
|
||||
if (!s) return <div className="mini-player loading" />;
|
||||
const pct = s.duration ? Math.min(100, (s.position / s.duration) * 100) : 0;
|
||||
return (
|
||||
<div className={`mini-player${s.loading || s.error ? ' loading' : ''}`} onPointerDown={startDrag} onDoubleClick={() => send('expand')}>
|
||||
<div className="mini-scrim" />
|
||||
<div className="mini-top">
|
||||
<button className="mini-icon" aria-label="Back to full screen player" title="Expand" onClick={() => send('expand')}>
|
||||
<Icon name="expand" size={17} />
|
||||
</button>
|
||||
<button className="mini-icon" aria-label="Stop playback" title="Close" onClick={() => send('close')}>
|
||||
<Icon name="x" size={18} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="mini-center">
|
||||
{(s.loading || s.buffering) && !s.error ? (
|
||||
<span className="spinner" style={{ width: 30, height: 30 }} aria-label="Loading" />
|
||||
) : s.error ? (
|
||||
<span className="mini-error">Playback stopped</span>
|
||||
) : (
|
||||
<>
|
||||
<button className="mini-icon" aria-label="Back 10 seconds" onClick={() => send('back')}>
|
||||
<Icon name="replay10" size={22} />
|
||||
</button>
|
||||
<button className="mini-icon big" aria-label={s.paused ? 'Play' : 'Pause'} onClick={() => send('toggle')}>
|
||||
<Icon name={s.paused || s.ended ? 'play' : 'pause'} size={26} />
|
||||
</button>
|
||||
<button className="mini-icon" aria-label="Forward 10 seconds" onClick={() => send('forward')}>
|
||||
<Icon name="forward10" size={22} />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="mini-caption">
|
||||
<b>{s.title}</b>
|
||||
{s.subtitle && <span>{s.subtitle}</span>}
|
||||
</div>
|
||||
<div className="mini-progress">
|
||||
<i style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<Mini />
|
||||
</StrictMode>,
|
||||
);
|
||||
32
src/mini/mini.css
Normal file
32
src/mini/mini.css
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* The miniplayer window (mini.html): the page is transparent over the video
|
||||
and the box fills the window, whose corners Windows rounds. */
|
||||
html.mini-window,
|
||||
html.mini-window body,
|
||||
html.mini-window #root {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
}
|
||||
html.mini-window .mini-player {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
animation: none;
|
||||
cursor: default;
|
||||
}
|
||||
html.mini-window.dragging .mini-player {
|
||||
cursor: grabbing;
|
||||
}
|
||||
/* While dragged, the title stays and the buttons step back. */
|
||||
html.mini-window.dragging .mini-scrim,
|
||||
html.mini-window.dragging .mini-caption {
|
||||
opacity: 1;
|
||||
}
|
||||
html.mini-window.dragging .mini-top,
|
||||
html.mini-window.dragging .mini-center {
|
||||
opacity: 0;
|
||||
}
|
||||
17
src/mini/types.ts
Normal file
17
src/mini/types.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/** What the miniplayer window shows, sent from the main window (src/player/miniWindow.ts). */
|
||||
export interface MiniState {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
paused: boolean;
|
||||
ended: boolean;
|
||||
position: number;
|
||||
duration: number;
|
||||
loading: boolean;
|
||||
buffering: boolean;
|
||||
error: boolean;
|
||||
}
|
||||
|
||||
/** Buttons and gestures in the miniplayer window, carried out by the main window's player. */
|
||||
export type MiniAction = 'ready' | 'toggle' | 'back' | 'forward' | 'expand' | 'close';
|
||||
|
||||
export const MINI_CORNER_KEY = 'kaleido.miniCorner';
|
||||
Loading…
Add table
Add a link
Reference in a new issue