Merge bugfix/pre-1.2.13: graphics recommendation cleanup, faster track resume

cc
This commit is contained in:
vicrodh committed 2026-05-16 13:53:24 -06:00
commit bf734546d1
12 files changed
+127 -145

No files matched your search

+40 -47
View File
@@ -200,69 +200,52 @@ pub fn compute_recommendation(env: &Environment) -> Recommendation {
}
let is_wayland = env.display_server == "Wayland";
let desktop_lower = env.desktop.to_lowercase();
let is_gnome = desktop_lower.contains("gnome");
let has_hybrid_igpu = env.gpu_nvidia && (env.gpu_intel || env.gpu_amd);
// Hybrid laptops (NVIDIA dGPU + Intel/AMD iGPU). WebKit composes via
// the iGPU through EGL/GLX defaults - the NVIDIA card sits idle for
// PRIME render offload. Forcing GSK_RENDERER=gl here was hurting
// performance because the GL renderer biases toward the dGPU stack
// even when the iGPU is the actual paint target. Auto (None) lets
// GTK4 pick NGL/Vulkan as appropriate for the iGPU. DMA-BUF stays
// disabled - that one is fragile on any NVIDIA-touching setup.
// PRIME render offload. Auto (None) lets GTK4 pick NGL/Vulkan as
// appropriate for the iGPU. DMA-BUF is safe here: the compositing
// path runs on the stable iGPU stack, not the NVIDIA driver, so the
// instability that affects NVIDIA-only systems does not apply. The
// user must still pick the iGPU explicitly in the rendering GPU
// selector - leaving it on Auto can resolve to the NVIDIA card.
if has_hybrid_igpu {
let igpu_label = if env.gpu_intel { "Intel" } else { "AMD" };
rationale.push(format!(
"NVIDIA + {} hybrid: iGPU handles WebKit compositing, leaving GSK at Auto",
igpu_label
));
rationale.push(format!(
"Select the {} integrated GPU explicitly in the rendering GPU selector instead of Auto",
igpu_label
));
return Recommendation {
hardware_acceleration: true,
force_x11: false,
gsk_renderer: None,
disable_dmabuf: true,
disable_dmabuf: false,
disable_blur_background: false,
rationale,
};
}
// NVIDIA + Wayland + GNOME: known stutter combo
if env.gpu_nvidia && is_wayland && is_gnome {
rationale.push("NVIDIA + Wayland + GNOME: using GL renderer, DMA-BUF off".to_string());
rationale.push("This combination has known compositing issues".to_string());
return Recommendation {
hardware_acceleration: true,
force_x11: false,
gsk_renderer: Some("gl".to_string()),
disable_dmabuf: true,
disable_blur_background: false,
rationale,
};
}
// NVIDIA + Wayland (non-GNOME)
if env.gpu_nvidia && is_wayland {
rationale.push("NVIDIA + Wayland: using GL renderer, DMA-BUF off".to_string());
return Recommendation {
hardware_acceleration: true,
force_x11: false,
gsk_renderer: Some("gl".to_string()),
disable_dmabuf: true,
disable_blur_background: false,
rationale,
};
}
// NVIDIA + X11
// NVIDIA-only (no iGPU to offload WebKit compositing to). WebKitGTK
// on the proprietary NVIDIA driver has long-standing compositing
// stutter that XWayland does not solve. Rather than recommend
// hardware acceleration that visibly stutters, fall back to CPU
// rendering: trimmed but smooth. DMA-BUF stays off - there is no
// stable GPU compositing path on this configuration.
if env.gpu_nvidia {
rationale.push("NVIDIA + X11: full hardware acceleration, DMA-BUF off".to_string());
rationale.push("NVIDIA-only system: using CPU rendering for a smooth UI".to_string());
rationale
.push("WebKit GPU compositing on the NVIDIA driver has unresolved stutter".to_string());
return Recommendation {
hardware_acceleration: true,
hardware_acceleration: false,
force_x11: false,
gsk_renderer: Some("gl".to_string()),
gsk_renderer: Some("cairo".to_string()),
disable_dmabuf: true,
disable_blur_background: false,
disable_blur_background: true,
rationale,
};
}
@@ -361,7 +344,7 @@ mod tests {
}
#[test]
fn nvidia_hybrid_leaves_renderer_auto_and_disables_dmabuf() {
fn nvidia_hybrid_leaves_renderer_auto_and_allows_dmabuf() {
let mut environment = env("Wayland");
environment.gpu_nvidia = true;
environment.gpu_intel = true;
@@ -370,30 +353,40 @@ mod tests {
assert!(recommendation.hardware_acceleration);
assert_eq!(recommendation.gsk_renderer, None);
assert!(recommendation.disable_dmabuf);
// DMA-BUF is safe on hybrid: the iGPU does the compositing.
assert!(!recommendation.disable_dmabuf);
// The user is told to pick the iGPU explicitly, not leave Auto.
assert!(recommendation
.rationale
.iter()
.any(|line| line.contains("integrated GPU")));
}
#[test]
fn nvidia_wayland_gnome_uses_gl_and_disables_dmabuf() {
fn nvidia_only_wayland_uses_cpu_rendering() {
let mut environment = env("Wayland");
environment.gpu_nvidia = true;
environment.desktop = "GNOME".to_string();
let recommendation = compute_recommendation(&environment);
assert_eq!(recommendation.gsk_renderer.as_deref(), Some("gl"));
assert!(!recommendation.hardware_acceleration);
assert_eq!(recommendation.gsk_renderer.as_deref(), Some("cairo"));
assert!(recommendation.disable_dmabuf);
assert!(recommendation.disable_blur_background);
}
#[test]
fn nvidia_x11_uses_gl_and_disables_dmabuf() {
fn nvidia_only_x11_uses_cpu_rendering() {
let mut environment = env("X11");
environment.gpu_nvidia = true;
let recommendation = compute_recommendation(&environment);
assert_eq!(recommendation.gsk_renderer.as_deref(), Some("gl"));
// X11/XWayland does not rescue NVIDIA-only: CPU rendering either way.
assert!(!recommendation.hardware_acceleration);
assert_eq!(recommendation.gsk_renderer.as_deref(), Some("cairo"));
assert!(recommendation.disable_dmabuf);
assert!(!recommendation.force_x11);
}
#[test]
+5 -5
View File
@@ -106,17 +106,17 @@ fn apply_recommendation(rec: &Recommendation) {
}
}
/// Apply the recommendation to the persistence layer. Shared between the CLI
/// prompt (`apply_recommendation`) and the V2 command surface. Returns the
/// list of write errors so the caller can surface them appropriately (stderr
/// for CLI, frontend toast for the Settings UI).
/// Apply the recommendation to the persistence layer. Used by the CLI prompt
/// (`apply_recommendation`); the Settings UI is advisory-only and no longer
/// writes the recommendation. Returns the list of write errors so the caller
/// can surface them on stderr.
///
/// DMA-BUF semantics after the 1.2.13 opt-in flip:
/// - `rec.disable_dmabuf = true` -> force_dmabuf = false (matches default;
/// runtime keeps DMA-BUF off).
/// - `rec.disable_dmabuf = false` -> force_dmabuf = true (user opts in via
/// this recommendation; runtime turns DMA-BUF on).
pub fn write_recommendation(rec: &Recommendation) -> Result<(), Vec<String>> {
fn write_recommendation(rec: &Recommendation) -> Result<(), Vec<String>> {
let mut errors = Vec::new();
match GraphicsSettingsStore::new() {
@@ -4,7 +4,6 @@
//! tool); this module is just the Tauri surface that the Graphics tab uses
//! to render the "Detected / Recommended" banner.
use crate::autoconfig_graphics::write_recommendation;
use qbz_app::graphics_autoconfig::{
compute_recommendation, detect_environment, Environment, Recommendation,
};
@@ -34,21 +33,6 @@ pub fn v2_get_graphics_recommendation() -> GraphicsRecommendationPayload {
}
}
/// Write the current recommendation to the persistence layer.
/// `force_dmabuf` is derived from `disable_dmabuf` per the 1.2.13
/// opt-in semantics (see `write_recommendation` in autoconfig_graphics).
/// Returns the list of per-field errors so the UI can surface them.
/// Empty `Ok(Vec)` means "everything written, restart required".
#[tauri::command]
pub fn v2_apply_graphics_recommendation() -> Result<Vec<String>, Vec<String>> {
let environment = detect_environment();
let recommendation = compute_recommendation(&environment);
match write_recommendation(&recommendation) {
Ok(()) => Ok(Vec::new()),
Err(errors) => Err(errors),
}
}
/// Payload for the rendering-GPU dropdown in Settings > Graphics.
/// `gpus` is the full list (physical PCI devices intersected with
/// available EGL vendor stacks, plus the Software fallback).
-1
View File
@@ -1661,7 +1661,6 @@ pub fn run(qconnect_cli_override: Option<bool>) {
commands_v2::v2_set_preferred_gpu,
commands_v2::v2_set_nvidia_compat_mode,
commands_v2::v2_get_graphics_recommendation,
commands_v2::v2_apply_graphics_recommendation,
commands_v2::v2_enumerate_gpus,
commands_v2::v2_mark_boot_succeeded,
commands_v2::v2_get_crash_flags,
+31 -49
View File
@@ -440,10 +440,10 @@
// Graphics recommendation surfaced in the Graphics tab. Populated on
// mount via v2_get_graphics_recommendation (matrix lives in
// autoconfig_graphics.rs). The banner fires only when at least one
// recommended value differs from the currently persisted setting; the
// "Apply" button writes the entire recommendation via
// v2_apply_graphics_recommendation.
// autoconfig_graphics.rs). The banner is advisory-only: it fires when
// at least one recommended value differs from the currently persisted
// setting and tells the user what to change. There is no Apply button
// by design - the user toggles the real settings manually.
type GraphicsRecommendation = {
environment: {
display_server: string;
@@ -4248,6 +4248,11 @@
}
const preferredGpuOptions = $derived.by(() => {
// On a hybrid NVIDIA + iGPU host, the iGPU is the recommended pick:
// WebKit composites there and the NVIDIA card stays idle. Mark it so
// the user does not leave the dropdown on the ambiguous Auto.
const env = graphicsRecommendation?.environment;
const igpuRecommended = !!env && env.gpu_nvidia && (env.gpu_intel || env.gpu_amd);
const autoTarget = autoResolvedGpuId
? detectedGpus.find((g) => g.id === autoResolvedGpuId)
: null;
@@ -4262,7 +4267,13 @@
for (const g of detectedGpus) {
if (!g.is_usable) continue;
if (g.kind === 'integrated' && !hasIntegrated) {
opts.push({ value: 'integrated', label: $t('settings.graphics.gpu.integrated', { values: { name: g.name } }) });
const integratedLabel = $t('settings.graphics.gpu.integrated', { values: { name: g.name } });
opts.push({
value: 'integrated',
label: igpuRecommended
? `${integratedLabel} ${$t('settings.graphics.gpu.recommendedSuffix')}`
: integratedLabel,
});
hasIntegrated = true;
}
if (g.kind === 'discrete' && !hasDiscrete) {
@@ -4310,32 +4321,21 @@
return recommendationSignature(graphicsRecommendation) !== dismissedRecommendationSignature;
});
async function handleApplyGraphicsRecommendation() {
try {
const errors = await invoke<string[]>('v2_apply_graphics_recommendation');
if (errors && errors.length > 0) {
console.error('Failed to apply some graphics settings:', errors);
showToast(errors.join('; '), 'error');
return;
}
// Refresh local state from DB so the toggles snap to the new values
const gs = await invoke<any>('v2_get_graphics_settings');
forceX11 = gs.force_x11;
gskRenderer = gs.gsk_renderer || '';
hardwareAcceleration = gs.hardware_acceleration;
const ds = await invoke<any>('v2_get_developer_settings');
forceDmabuf = ds.force_dmabuf;
// Banner will hide naturally because diff is now false. Clear the
// dismiss flag too so the next environment change re-evaluates
// cleanly without a stale signature blocking the new banner.
dismissedRecommendationSignature = null;
removeUserItem(RECOMMENDATION_DISMISS_KEY);
showToast($t('settings.graphics.recommendation.applied'), 'success');
} catch (err) {
console.error('Failed to apply graphics recommendation:', err);
showToast(String(err), 'error');
// DMA-BUF help text is GPU-aware. The instability warning only
// applies to NVIDIA-only systems; non-NVIDIA and hybrid setups (the
// iGPU composites) can enable it safely. Returns an i18n key so $t()
// stays in the template, not inside $derived (CSS-extraction rule).
const forceDmabufDescKey = $derived.by(() => {
const env = graphicsRecommendation?.environment;
if (!env) return 'settings.graphics.forceDmabufDesc';
if (env.gpu_nvidia && (env.gpu_intel || env.gpu_amd)) {
return 'settings.graphics.forceDmabufDescHybrid';
}
}
if (env.gpu_nvidia) {
return 'settings.graphics.forceDmabufDescNvidiaOnly';
}
return 'settings.graphics.forceDmabufDescSafe';
});
function handleDismissRecommendation() {
if (!graphicsRecommendation) return;
@@ -5547,9 +5547,6 @@
{/if}
</div>
<div class="recommendation-actions">
<button class="primary-btn" onclick={handleApplyGraphicsRecommendation}>
{$t('settings.graphics.recommendation.apply')}
</button>
<button class="secondary-btn" onclick={handleDismissRecommendation}>
{$t('settings.graphics.recommendation.dismiss')}
</button>
@@ -5663,7 +5660,7 @@
<div class="setting-row">
<div class="setting-info">
<span class="setting-label">{$t('settings.graphics.forceDmabuf')}</span>
<span class="setting-desc">{$t('settings.graphics.forceDmabufDesc')}</span>
<span class="setting-desc">{$t(forceDmabufDescKey)}</span>
</div>
<Toggle enabled={forceDmabuf} onchange={(v) => handleForceDmabufChange(v)} />
</div>
@@ -7581,21 +7578,6 @@ flatpak override --user --filesystem=/home/USUARIO/Música com.blitzfc.qbz</pre>
filter: brightness(1.15);
}
.primary-btn {
background: var(--accent-primary, #7c3aed);
color: var(--btn-primary-text, #fff);
border: 1px solid transparent;
border-radius: 6px;
padding: 6px 14px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.primary-btn:hover {
filter: brightness(1.1);
}
.secondary-btn {
background: transparent;
color: var(--text-secondary);
+4 -2
View File
@@ -2792,6 +2792,9 @@
"hardwareAccelerationDesc": "GPU-Rendering aktivieren. Deaktivieren erzwingt Software-Rendering (nur CPU). Deaktivieren bei Abstuerzen oder visuellen Artefakten.",
"forceDmabuf": "DMA-BUF-Renderer erzwingen",
"forceDmabufDesc": "DMA-BUF-Pufferfreigabe mit dem Compositor erzwingen. Kann die Leistung verbessern, aber auf manchen Systemen abstuerzen (besonders NVIDIA + Wayland).",
"forceDmabufDescSafe": "Aktiviert die DMA-BUF-Pufferfreigabe mit dem Compositor für flüssigeres Rendering. Auf deiner Hardware unbedenklich. Neustart erforderlich.",
"forceDmabufDescHybrid": "Deine integrierte GPU übernimmt das Rendering, daher ist DMA-BUF hier unbedenklich. Verbessert die Render-Flüssigkeit. Neustart erforderlich.",
"forceDmabufDescNvidiaOnly": "Auf reinen NVIDIA-Systemen nicht empfohlen — DMA-BUF kann Rendering-Instabilität verursachen. Neustart erforderlich.",
"forceX11": "X11-Backend erzwingen (Wayland)",
"forceX11Desc": "XWayland statt nativem Wayland verwenden. Empfohlen fuer NVIDIA-GPUs mit Wayland-Abstuerzen.",
"gdkScale": "Anzeigeskalierung (XWayland)",
@@ -2826,8 +2829,6 @@
"recommendation": {
"title": "Empfohlen für dein System",
"detected": "Erkannt",
"apply": "Übernehmen",
"applied": "Konfiguration übernommen. QBZ neu starten, damit es wirksam wird.",
"dismiss": "Verwerfen",
"redetect": "Empfohlene Einstellungen erkennen",
"noChanges": "Die Einstellungen entsprechen bereits der Empfehlung für dieses System."
@@ -2839,6 +2840,7 @@
"auto": "Automatisch (System-Standard)",
"autoWithTarget": "Automatisch ({name})",
"integrated": "Integriert — {name}",
"recommendedSuffix": "(empfohlen)",
"discrete": "Dediziert — {name}",
"software": "Software (CPU, llvmpipe)"
},
+4 -2
View File
@@ -2798,6 +2798,9 @@
"hardwareAccelerationDesc": "Enable GPU rendering. Disabling forces software rendering (CPU only). Turn off if you experience crashes or visual artifacts.",
"forceDmabuf": "Force DMA-BUF Renderer",
"forceDmabufDesc": "Force DMA-BUF buffer sharing with compositor. May improve performance but can crash on some systems (especially NVIDIA + Wayland).",
"forceDmabufDescSafe": "Enables DMA-BUF buffer sharing with the compositor for smoother rendering. Safe on your hardware. Restart required.",
"forceDmabufDescHybrid": "Your integrated GPU handles rendering, so DMA-BUF is safe to enable here. Improves rendering smoothness. Restart required.",
"forceDmabufDescNvidiaOnly": "Not recommended on NVIDIA-only systems — DMA-BUF can cause rendering instability. Restart required.",
"forceX11": "Force X11 backend (Wayland)",
"forceX11Desc": "Use XWayland instead of native Wayland. Recommended for NVIDIA GPUs that crash on Wayland.",
"gdkScale": "Display scale (XWayland)",
@@ -2832,8 +2835,6 @@
"recommendation": {
"title": "Recommended for your system",
"detected": "Detected",
"apply": "Apply",
"applied": "Configuration applied. Restart QBZ to take effect.",
"dismiss": "Dismiss",
"redetect": "Detect recommended settings",
"noChanges": "Settings already match the recommendation for this system."
@@ -2845,6 +2846,7 @@
"auto": "Auto (system default)",
"autoWithTarget": "Auto ({name})",
"integrated": "Integrated — {name}",
"recommendedSuffix": "(recommended)",
"discrete": "Discrete — {name}",
"software": "Software (CPU, llvmpipe)"
},
+4 -2
View File
@@ -2798,6 +2798,9 @@
"hardwareAccelerationDesc": "Habilitar renderizado GPU. Desactivar fuerza renderizado por software (solo CPU). Desactivar si experimentas crashes o artefactos visuales.",
"forceDmabuf": "Forzar Renderizador DMA-BUF",
"forceDmabufDesc": "Forzar comparticion de buffers DMA-BUF con el compositor. Puede mejorar rendimiento pero puede crashear en algunos sistemas (especialmente NVIDIA + Wayland).",
"forceDmabufDescSafe": "Activa el uso compartido de buffers DMA-BUF con el compositor para un render más fluido. Es seguro en tu hardware. Requiere reiniciar.",
"forceDmabufDescHybrid": "Tu GPU integrada se encarga del render, así que aquí es seguro activar DMA-BUF. Mejora la fluidez del render. Requiere reiniciar.",
"forceDmabufDescNvidiaOnly": "No se recomienda en sistemas solo con NVIDIA: DMA-BUF puede causar inestabilidad de render. Requiere reiniciar.",
"forceX11": "Forzar X11 (Wayland)",
"forceX11Desc": "Usar XWayland en lugar de Wayland nativo. Recomendado para GPUs NVIDIA con crashes en Wayland.",
"gdkScale": "Escala de pantalla (XWayland)",
@@ -2832,8 +2835,6 @@
"recommendation": {
"title": "Recomendado para tu sistema",
"detected": "Detectado",
"apply": "Aplicar",
"applied": "Configuracion aplicada. Reinicia QBZ para que surta efecto.",
"dismiss": "Descartar",
"redetect": "Detectar configuracion recomendada",
"noChanges": "La configuracion actual ya coincide con la recomendacion para este sistema."
@@ -2845,6 +2846,7 @@
"auto": "Auto (predeterminado del sistema)",
"autoWithTarget": "Auto ({name})",
"integrated": "Integrada — {name}",
"recommendedSuffix": "(recomendada)",
"discrete": "Dedicada — {name}",
"software": "Software (CPU, llvmpipe)"
},
+4 -2
View File
@@ -2792,6 +2792,9 @@
"hardwareAccelerationDesc": "Activer le rendu GPU. Désactiver force le rendu logiciel (CPU uniquement). Désactiver en cas de crashes ou d'artéfacts visuels.",
"forceDmabuf": "Forcer le rendu DMA-BUF",
"forceDmabufDesc": "Forcer le partage de tampons DMA-BUF avec le compositeur. Peut améliorer les performances mais peut planter sur certains systèmes (en particulier NVIDIA + Wayland).",
"forceDmabufDescSafe": "Active le partage de tampons DMA-BUF avec le compositeur pour un rendu plus fluide. Sans risque sur votre matériel. Redémarrage requis.",
"forceDmabufDescHybrid": "Votre GPU intégré gère le rendu, donc DMA-BUF peut être activé ici sans risque. Améliore la fluidité du rendu. Redémarrage requis.",
"forceDmabufDescNvidiaOnly": "Déconseillé sur les systèmes NVIDIA uniquement — DMA-BUF peut provoquer une instabilité du rendu. Redémarrage requis.",
"forceX11": "Forcer le backend X11 (Wayland)",
"forceX11Desc": "Utiliser XWayland au lieu du Wayland natif. Recommandé pour les GPU NVIDIA avec des crashes sous Wayland.",
"gdkScale": "Échelle d'affichage (XWayland)",
@@ -2826,8 +2829,6 @@
"recommendation": {
"title": "Recommandé pour votre système",
"detected": "Détecté",
"apply": "Appliquer",
"applied": "Configuration appliquée. Redémarrez QBZ pour qu'elle prenne effet.",
"dismiss": "Ignorer",
"redetect": "Détecter les paramètres recommandés",
"noChanges": "Les paramètres correspondent déjà à la recommandation pour ce système."
@@ -2839,6 +2840,7 @@
"auto": "Auto (par défaut)",
"autoWithTarget": "Auto ({name})",
"integrated": "Intégré — {name}",
"recommendedSuffix": "(recommandé)",
"discrete": "Dédié — {name}",
"software": "Logiciel (CPU, llvmpipe)"
},
+4 -2
View File
@@ -2792,6 +2792,9 @@
"hardwareAccelerationDesc": "Ativar renderização por GPU. Desativar força renderização por software (apenas CPU). Desative se tiver travamentos ou artefatos visuais.",
"forceDmabuf": "Forçar Renderizador DMA-BUF",
"forceDmabufDesc": "Forçar compartilhamento de buffer DMA-BUF com o compositor. Pode melhorar o desempenho, mas pode travar em alguns sistemas (especialmente NVIDIA + Wayland).",
"forceDmabufDescSafe": "Ativa o compartilhamento de buffers DMA-BUF com o compositor para uma renderização mais fluida. Seguro no seu hardware. Reinício necessário.",
"forceDmabufDescHybrid": "Sua GPU integrada faz a renderização, então é seguro ativar o DMA-BUF aqui. Melhora a fluidez da renderização. Reinício necessário.",
"forceDmabufDescNvidiaOnly": "Não recomendado em sistemas apenas com NVIDIA — o DMA-BUF pode causar instabilidade de renderização. Reinício necessário.",
"forceX11": "Forçar backend X11 (Wayland)",
"forceX11Desc": "Usar XWayland em vez do Wayland nativo. Recomendado para GPUs NVIDIA que travam no Wayland.",
"gdkScale": "Escala de exibição (XWayland)",
@@ -2826,8 +2829,6 @@
"recommendation": {
"title": "Recomendado para o seu sistema",
"detected": "Detectado",
"apply": "Aplicar",
"applied": "Configuracao aplicada. Reinicie o QBZ para que tenha efeito.",
"dismiss": "Descartar",
"redetect": "Detectar configuracoes recomendadas",
"noChanges": "As configuracoes ja correspondem a recomendacao para este sistema."
@@ -2839,6 +2840,7 @@
"auto": "Auto (padrao do sistema)",
"autoWithTarget": "Auto ({name})",
"integrated": "Integrada — {name}",
"recommendedSuffix": "(recomendada)",
"discrete": "Dedicada — {name}",
"software": "Software (CPU, llvmpipe)"
},
+4 -4
View File
@@ -116,10 +116,10 @@ export async function cmdPlayTrack(
// start_position_secs). duration_secs is required on the streaming
// path — without it the backend stores duration=0 and
// current_position() clamps to 0, freezing the seekbar (seen on
// session-restore first play). start_position_secs > 0 turns the
// call into a session-resume play (#315): backend buffers enough
// bytes to cover the offset and pre-skips decoder output before
// engaging audio, avoiding the play-then-seek race.
// session-restore first play). start_position_secs is still accepted
// by the backend but the frontend no longer uses it: session resume
// now seeks to the saved offset only on a cache hit, where the audio
// is fully in memory and Seek lands (see playerStore togglePlay).
return invoke('v2_play_track', {
trackId,
quality: quality ?? null,
+27 -13
View File
@@ -559,25 +559,39 @@ export async function togglePlay(): Promise<void> {
void flushPendingSeek();
}
} else {
// Qobuz track — use v2_play_track. Pass duration so the
// Qobuz track session restore (#315 within-track resume).
// Play from the start: v2_play_track serves a cache hit
// instantly or streams from byte 0. Pass duration so the
// streaming backend's current_position() doesn't clamp to 0
// (the value flows into thread_state.duration and seekbar
// progress is capped by .min(duration)). For session resume,
// hand the restore offset directly to v2_play_track via
// startPositionSecs (#315 extension): the streaming path
// waits for enough buffer to cover the offset and pre-skips
// decoder output before engaging audio, instead of the
// play-then-seek dance that silently dropped the seek
// because the audio thread's Seek handler bails when there
// is no `current_audio_data` (streaming uses
// `current_streaming_source` instead).
await cmdPlayTrack(
// progress is capped by .min(duration)).
//
// Resume the saved offset ONLY on a cache hit (format_id ===
// null): the audio is then a full in-memory buffer
// (current_audio_data) so the Seek handler lands, exactly
// like a local file. On a cache miss the track streams via
// CMAF — seeking mid-track would block on the buffer filling
// sequentially from byte 0, far too slow to feel like a
// feature, so we deliberately start fresh from 0:00.
const result = (await cmdPlayTrack(
currentTrack.id,
getStreamingQuality(),
currentTrack.duration ? Math.round(currentTrack.duration) : null,
null,
restorePosition > 1 ? restorePosition : null,
);
null,
)) as { format_id?: number | null } | null | undefined;
const servedFromCache = result != null && result.format_id === null;
if (restorePosition > 1 && servedFromCache) {
pendingSeekPosition = restorePosition;
void flushPendingSeek();
} else if (restorePosition > 1) {
// Cache miss — undo the seekbar pre-anchor (setPendingSessionRestore
// pre-set currentTime to the saved offset) so the bar matches
// the actual start at 0:00 instead of flashing the saved time.
currentTime = 0;
anchorPosition(0);
notifyListeners();
}
}
} else {