feat(slint): cast picker modal + cast teardown on logout/exit (Phase 4)

- CastPicker.slint: real modal (scrim + 400px card) replacing the static
  PlayerBar/PlayerBarSmall cast-menu PopupWindow stubs. Two rectangular tabs
  (Chromecast/DLNA, no pills, plain count) + per-tab device list from
  CastState.devices, connect-on-click (DLNA rows gate on can-play), connected
  banner with Disconnect + delivered-quality line (D3), scanning/empty states,
  error line. Mounted last in AppShell (on top).
- PlayerBar + PlayerBarSmall cast buttons now open the modal
  (CastState.picker-open = true; CastActions.open()) instead of the dead popup.
- Cast teardown wired: shutdown() on logout (fixes the Tauri connection + poll
  leak #33) and best-effort on app exit (renderer Stop + media server, #32).

cargo check -p qbz-slint: clean (only the 6 pre-existing warnings).

cc
This commit is contained in:
vicrodh committed 2026-06-18 10:04:59 -06:00
1 parent 3e1101ff64
commit 6429273d77
6 files changed
+346 -179

No files matched your search

+3
View File
@@ -533,6 +533,9 @@ impl SlintCastService {
Ok(true)
}
// No transport "stop" button in the bar today; kept for parity + a future
// stop control.
#[allow(dead_code)]
pub async fn stop_if_cast(&self) -> Result<bool, String> {
if !self.is_casting().await {
return Ok(false);
+13
View File
@@ -4825,6 +4825,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let runtime = runtime.clone();
let weak = weak.clone();
handle.spawn(async move {
// Tear down any live cast session + poll (fixes the Tauri
// logout leak where the connection + position interval lived on).
if let Some(cast) = cast_service::service() {
cast.shutdown().await;
}
if let Err(e) = auth::logout(&runtime).await {
log::error!("[qbz-slint] logout failed: {e}");
}
@@ -12993,6 +12998,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// on + the tray is live, otherwise quit. Required because the loop runs
// with quit_on_last_window_closed = false (so a tray-hide keeps the app
// alive) — without this, the native close would leave a headless process.
let cast_exit_handle = tokio_rt.handle().clone();
window.window().on_close_requested(move || {
let settings = tray_settings::get();
if settings.close_to_tray && tray::handle().is_some() {
@@ -13007,6 +13013,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
slint::CloseRequestResponse::HideWindow
} else {
log::info!("[qbz-slint] WM close requested: quitting");
// Best-effort: stop the renderer + media server so a cast device
// doesn't keep playing after the app quits (Tauri parity, #32).
if let Some(cast) = cast_service::service() {
cast_exit_handle.block_on(async move {
cast.shutdown().await;
});
}
let _ = slint::quit_event_loop();
slint::CloseRequestResponse::HideWindow
}
+7
View File
@@ -36,6 +36,7 @@ import { TrackInfoModal } from "../album/TrackInfoModal.slint";
import { AlbumCreditsModal } from "../album/AlbumCreditsModal.slint";
import { ImmersiveView } from "../immersive/ImmersiveView.slint";
import { QconnectDevModal } from "QconnectDevModal.slint";
import { CastPicker } from "CastPicker.slint";
import { DiscoverConfigModal } from "../discover/DiscoverConfigModal.slint";
import { DragGhost } from "../primitives/DragGhost.slint";
import { Toast } from "../primitives/Toast.slint";
@@ -522,6 +523,12 @@ export component AppShell inherits Rectangle {
height: 100%;
}
// Cast (Chromecast / DLNA) device picker.
CastPicker {
width: 100%;
height: 100%;
}
// Floating track-drag ghost (follows the cursor, on top of all).
DragGhost { }
+315
View File
@@ -0,0 +1,315 @@
// Cast (Chromecast / DLNA) device picker modal. Replaces the old static
// PlayerBar cast-menu PopupWindow. Mounted last in AppShell so it sits on top
// (Slint mount-order z; ADR-009 intent). Driven by CastState / CastActions:
// - open: PlayerBar sets CastState.picker-open = true + CastActions.open()
// - close: scrim/X sets picker-open = false + CastActions.close()
// No pills (ADR-008): tabs are rectangular, counts are plain trailing text.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { CastState, CastActions } from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
// One discovered-device row.
component CastDeviceRow inherits Rectangle {
in property <string> id;
in property <string> name;
in property <string> ip;
in property <string> protocol;
in property <bool> can-play: true;
height: 52px;
border-radius: Radius.sm;
background: ta.has-hover && root.can-play ? Theme.surface-hover : transparent;
ta := TouchArea {
mouse-cursor: root.can-play ? pointer : default;
enabled: root.can-play;
clicked => {
CastActions.connect(root.id, root.protocol);
}
}
HorizontalLayout {
padding-left: 10px;
padding-right: 10px;
spacing: 10px;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/cast.svg");
width: 18px;
height: 18px;
tint: Theme.text-secondary;
}
}
VerticalLayout {
alignment: center;
spacing: 2px;
horizontal-stretch: 1;
Text {
text: root.name;
color: root.can-play ? Theme.text-primary : Theme.text-muted;
font-size: Typography.body;
overflow: elide;
}
Text {
text: root.can-play ? root.ip : @tr("{} (not playable)", root.ip);
color: Theme.text-muted;
font-size: Typography.legal;
overflow: elide;
}
}
}
}
// A rectangular tab button with a trailing count (no pills).
component CastTab inherits Rectangle {
in property <string> label;
in property <int> count;
in property <bool> selected;
callback clicked();
height: 34px;
horizontal-stretch: 1;
border-radius: Radius.sm;
background: root.selected ? Theme.accent : (tta.has-hover ? Theme.surface-hover : Theme.surface-elevated);
tta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.clicked();
}
}
HorizontalLayout {
alignment: center;
spacing: 6px;
Text {
text: root.label;
color: root.selected ? #ffffff : Theme.text-primary;
font-size: Typography.body;
font-weight: root.selected ? Typography.semibold : Typography.regular;
vertical-alignment: center;
}
if root.count > 0: Text {
text: "\{root.count}";
color: root.selected ? #ffffffcc : Theme.text-muted;
font-size: Typography.legal;
vertical-alignment: center;
}
}
}
export component CastPicker inherits Rectangle {
visible: CastState.picker-open;
if CastState.picker-open: Rectangle {
background: #000000bf;
// Scrim — click closes + stops discovery.
TouchArea {
mouse-cursor: default;
clicked => {
CastState.picker-open = false;
CastActions.close();
}
}
Rectangle {
width: Math.min(root.width - 80px, 400px);
height: 420px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
border-radius: Radius.md;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
// Swallow clicks so they don't reach the scrim.
TouchArea { }
VerticalLayout {
padding: 18px;
spacing: 14px;
// Header.
HorizontalLayout {
spacing: 8px;
QbzIcon {
source: @image-url("../assets/icons/cast.svg");
width: 18px;
height: 18px;
tint: Theme.text-primary;
}
Text {
text: @tr("Cast");
color: Theme.text-primary;
font-size: Typography.heading;
font-weight: Typography.semibold;
vertical-alignment: center;
horizontal-stretch: 1;
}
close-x := TouchArea {
width: 28px;
height: 28px;
mouse-cursor: pointer;
clicked => {
CastState.picker-open = false;
CastActions.close();
}
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 17px;
height: 17px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
}
}
}
// ---- Connected banner (replaces tabs + list) ----
if CastState.connected: Rectangle {
height: 64px;
border-radius: Radius.sm;
background: #1f3d2e;
border-width: 1px;
border-color: #3fae6a;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 10px;
VerticalLayout {
alignment: center;
Rectangle {
width: 10px;
height: 10px;
border-radius: 5px;
background: #3fae6a;
}
}
VerticalLayout {
alignment: center;
spacing: 2px;
horizontal-stretch: 1;
Text {
text: @tr("Connected to");
color: Theme.text-muted;
font-size: Typography.legal;
}
Text {
text: CastState.device-name;
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.semibold;
overflow: elide;
}
}
VerticalLayout {
alignment: center;
Rectangle {
width: discon-label.preferred-width + 24px;
height: 32px;
border-radius: Radius.sm;
background: discon-ta.has-hover ? #d44a4a : #b23b3b;
discon-label := Text {
text: @tr("Disconnect");
color: #ffffff;
font-size: Typography.legal;
font-weight: Typography.semibold;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
}
discon-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
CastActions.disconnect();
}
}
}
}
}
}
// Delivered quality (D3) under the banner, when known.
if CastState.connected && CastState.quality-detail != "": Text {
text: @tr("Streaming {} · {}", CastState.protocol == "dlna" ? "DLNA" : "Chromecast", CastState.quality-detail);
color: Theme.text-muted;
font-size: Typography.legal;
}
// ---- Tabs + device list (when not connected) ----
if !CastState.connected: HorizontalLayout {
spacing: 8px;
CastTab {
label: "Chromecast";
count: CastState.chromecast-count;
selected: CastState.selected-tab == "chromecast";
clicked => {
CastState.selected-tab = "chromecast";
}
}
CastTab {
label: "DLNA";
count: CastState.dlna-count;
selected: CastState.selected-tab == "dlna";
clicked => {
CastState.selected-tab = "dlna";
}
}
}
if !CastState.connected: Rectangle {
vertical-stretch: 1;
border-radius: Radius.sm;
background: Theme.surface-elevated;
// Device list for the selected tab.
Flickable {
viewport-width: self.width;
VerticalLayout {
padding: 6px;
spacing: 2px;
for d in CastState.devices: Rectangle {
height: d.protocol == CastState.selected-tab ? 52px : 0px;
visible: d.protocol == CastState.selected-tab;
if d.protocol == CastState.selected-tab: CastDeviceRow {
id: d.id;
name: d.name;
ip: d.ip;
protocol: d.protocol;
can-play: d.can-play;
}
}
}
}
// Empty / scanning overlay (shown when the selected tab has
// no devices).
if (CastState.selected-tab == "chromecast" && CastState.chromecast-count == 0)
|| (CastState.selected-tab == "dlna" && CastState.dlna-count == 0): VerticalLayout {
alignment: center;
spacing: 4px;
Text {
text: CastState.scanning ? @tr("Searching…") : @tr("No devices found");
color: Theme.text-secondary;
font-size: Typography.body;
horizontal-alignment: center;
}
Text {
text: @tr("Looking for Chromecast & DLNA on your network");
color: Theme.text-muted;
font-size: Typography.legal;
horizontal-alignment: center;
wrap: word-wrap;
}
}
}
// Error line.
if CastState.error != "": Text {
text: CastState.error;
color: #d46a6a;
font-size: Typography.legal;
wrap: word-wrap;
}
}
}
}
}
+4 -87
View File
@@ -20,7 +20,7 @@ import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
import { SeekBar } from "SeekBar.slint";
import { SongCard } from "SongCard.slint";
import { TransportControls } from "TransportControls.slint";
import { NowPlayingState, ShellState, AppearanceState, SettingsState, TooltipState, QconnectDevState, QconnectDevice } from "../state.slint";
import { NowPlayingState, ShellState, AppearanceState, SettingsState, TooltipState, QconnectDevState, QconnectDevice, CastState, CastActions } from "../state.slint";
// IconButton + PlayButton now live in primitives/BarControls.slint (shared
// with TransportControls). ConnectButton + ToggleRow stay local (bar-only).
@@ -583,7 +583,7 @@ export component PlayerBar inherits Rectangle {
}
}
// Cast (Chromecast / DLNA) — opens the cast flyout.
// Cast (Chromecast / DLNA) — opens the cast picker modal.
VerticalLayout {
alignment: center;
Rectangle {
@@ -596,91 +596,8 @@ export component PlayerBar inherits Rectangle {
tooltip: @tr("Cast");
active: NowPlayingState.cast-active;
clicked => {
cast-menu.show();
}
}
cast-menu := PopupWindow {
x: 32px - 280px;
y: -252px;
width: 280px;
height: 244px;
close-policy: close-on-click-outside;
Rectangle {
background: Theme.surface-main;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-muted;
drop-shadow-blur: 22px;
drop-shadow-color: Theme.card-shadow;
drop-shadow-offset-y: 6px;
VerticalLayout {
padding: 14px;
spacing: 12px;
HorizontalLayout {
spacing: 8px;
QbzIcon {
source: @image-url("../assets/icons/cast.svg");
width: 16px;
height: 16px;
tint: Theme.text-primary;
}
Text {
text: @tr("Cast");
color: Theme.text-primary;
font-size: 14px;
font-weight: 600;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
HorizontalLayout {
spacing: 8px;
VerticalLayout {
alignment: center;
Rectangle {
width: 8px;
height: 8px;
border-radius: 4px;
background: NowPlayingState.cast-active ? #a855f7 : Theme.text-muted;
}
}
Text {
text: NowPlayingState.cast-active
? @tr("Casting")
: @tr("Not casting");
color: Theme.text-secondary;
font-size: 12px;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
Rectangle {
vertical-stretch: 1;
background: Theme.surface-elevated;
border-radius: Radius.sm;
VerticalLayout {
alignment: center;
spacing: 4px;
Text {
text: @tr("No cast devices found");
color: Theme.text-secondary;
font-size: 12px;
horizontal-alignment: center;
}
Text {
text: @tr("Looking for Chromecast & DLNA on your network");
color: Theme.text-muted;
font-size: 10px;
horizontal-alignment: center;
wrap: word-wrap;
}
}
}
}
CastState.picker-open = true;
CastActions.open();
}
}
}
+4 -92
View File
@@ -46,7 +46,7 @@ import { ContextMenuItem } from "../primitives/ContextMenuItem.slint";
import { SeekBar } from "SeekBar.slint";
import { SongCard } from "SongCard.slint";
import { TransportControls } from "TransportControls.slint";
import { NowPlayingState, ShellState, SettingsState, QconnectDevState } from "../state.slint";
import { NowPlayingState, ShellState, SettingsState, QconnectDevState, CastState, CastActions } from "../state.slint";
// Qobuz Connect button — monitor-speaker glyph; golden over a soft golden tint
// when a Qobuz Connect session owns playback. A local copy of PlayerBar's
@@ -786,9 +786,7 @@ export component PlayerBarSmall inherits Rectangle {
}
}
// Cast (Chromecast / DLNA) — opens the cast flyout. Mirrors
// PlayerBar's cast button + popup verbatim (NOT a dead stub;
// the popup is the same placeholder New ships today).
// Cast (Chromecast / DLNA) — opens the cast picker modal.
VerticalLayout {
alignment: center;
Rectangle {
@@ -801,94 +799,8 @@ export component PlayerBarSmall inherits Rectangle {
tooltip: @tr("Cast");
active: NowPlayingState.cast-active;
clicked => {
cast-menu.show();
}
}
cast-menu := PopupWindow {
// Inner Rectangle FILLS the popup, so the visible
// bottom == y + height. Homologated to -7 (flush
// just above the 3px seekbar; bar top ≈ -6.5).
x: 32px - 280px;
y: -251px;
width: 280px;
height: 244px;
close-policy: close-on-click-outside;
Rectangle {
background: Theme.surface-main;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-muted;
drop-shadow-blur: 22px;
drop-shadow-color: Theme.card-shadow;
drop-shadow-offset-y: 6px;
VerticalLayout {
padding: 14px;
spacing: 12px;
HorizontalLayout {
spacing: 8px;
QbzIcon {
source: @image-url("../assets/icons/cast.svg");
width: 16px;
height: 16px;
tint: Theme.text-primary;
}
Text {
text: @tr("Cast");
color: Theme.text-primary;
font-size: 14px;
font-weight: 600;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
Rectangle {
height: 1px;
background: Theme.border-subtle;
}
HorizontalLayout {
spacing: 8px;
VerticalLayout {
alignment: center;
Rectangle {
width: 8px;
height: 8px;
border-radius: 4px;
background: NowPlayingState.cast-active ? #a855f7 : Theme.text-muted;
}
}
Text {
text: NowPlayingState.cast-active
? @tr("Casting")
: @tr("Not casting");
color: Theme.text-secondary;
font-size: 12px;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
Rectangle {
vertical-stretch: 1;
background: Theme.surface-elevated;
border-radius: Radius.sm;
VerticalLayout {
alignment: center;
spacing: 4px;
Text {
text: @tr("No cast devices found");
color: Theme.text-secondary;
font-size: 12px;
horizontal-alignment: center;
}
Text {
text: @tr("Looking for Chromecast & DLNA on your network");
color: Theme.text-muted;
font-size: 10px;
horizontal-alignment: center;
wrap: word-wrap;
}
}
}
}
CastState.picker-open = true;
CastActions.open();
}
}
}