diff --git a/crates/qbz-app/src/shell.rs b/crates/qbz-app/src/shell.rs index 4abf82938..31ca79198 100644 --- a/crates/qbz-app/src/shell.rs +++ b/crates/qbz-app/src/shell.rs @@ -193,6 +193,7 @@ impl AppRuntime { /// activates against them, and persists the last-user marker so the /// session can be restored on the next launch. pub async fn activate(&self, user_id: u64) -> Result<(), String> { + Self::adopt_guest_profile(user_id); self.user_paths.set_user(user_id); let data_dir = self.user_paths.user_data_dir()?; let cache_dir = self.user_paths.user_cache_dir()?; @@ -201,6 +202,45 @@ impl AppRuntime { Ok(()) } + /// First real login takes possession of the guest profile (#553): data + /// built while logged off (local library, mixtapes, per-user prefs — + /// `users/0/`) is renamed to this account IF the account has no profile + /// on this machine yet. An existing profile always wins — the guest + /// dirs then stay parked at user 0, no merge is attempted. Best-effort: + /// a failed rename logs and falls through to a fresh profile; login + /// must never break here. + fn adopt_guest_profile(user_id: u64) { + if user_id == 0 { + return; + } + for (kind, guest, target) in [ + ( + "data", + UserDataPaths::data_dir_for(0), + UserDataPaths::data_dir_for(user_id), + ), + ( + "cache", + UserDataPaths::cache_dir_for(0), + UserDataPaths::cache_dir_for(user_id), + ), + ] { + let (Ok(guest), Ok(target)) = (guest, target) else { + continue; + }; + if guest.is_dir() && !target.exists() { + match std::fs::rename(&guest, &target) { + Ok(()) => { + log::info!("[AppRuntime] guest profile {kind} adopted by the new session") + } + Err(e) => log::warn!( + "[AppRuntime] guest profile {kind} adoption failed ({e}); starting fresh" + ), + } + } + } + } + /// Activate an offline-only session using the last known user. /// /// Falls back to user id `0` (an empty profile) when no previous session diff --git a/crates/qbz-app/src/user_data.rs b/crates/qbz-app/src/user_data.rs index 9db44d858..10d9c7b2f 100644 --- a/crates/qbz-app/src/user_data.rs +++ b/crates/qbz-app/src/user_data.rs @@ -82,6 +82,23 @@ impl UserDataPaths { Ok(base) } + /// Data directory for an ARBITRARY user id (no active-user requirement): + /// ~/.local/share/qbz/users/{uid}/ — the same layout `user_data_dir` + /// resolves for the active user. Used by the guest-profile adoption + /// (#553), which must compare two users' paths before either is active. + pub fn data_dir_for(user_id: u64) -> Result { + Ok(Self::global_data_dir()? + .join("users") + .join(user_id.to_string())) + } + + /// Cache twin of [`Self::data_dir_for`]: ~/.cache/qbz/users/{uid}/. + pub fn cache_dir_for(user_id: u64) -> Result { + Ok(Self::global_cache_dir()? + .join("users") + .join(user_id.to_string())) + } + /// Get the global (non-user-scoped) data directory: ~/.local/share/qbz/ pub fn global_data_dir() -> Result { dirs::data_dir() diff --git a/crates/qbz-ui/translations/de/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/de/LC_MESSAGES/qbz-ui.po index 972177cc2..5d0409755 100644 --- a/crates/qbz-ui/translations/de/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/de/LC_MESSAGES/qbz-ui.po @@ -4458,3 +4458,6 @@ msgstr "Keine verfügbaren Titel zum Abspielen" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Protokolle teilen" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZ kann ohne Qobuz™-Konto als Offline-Player genutzt werden (kein Zugriff auf die Qobuz™-Bibliothek)." diff --git a/crates/qbz-ui/translations/en/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/en/LC_MESSAGES/qbz-ui.po index 1c5990c7a..28e0354c5 100644 --- a/crates/qbz-ui/translations/en/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/en/LC_MESSAGES/qbz-ui.po @@ -227,3 +227,6 @@ msgstr "Favorite" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Share logs" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." diff --git a/crates/qbz-ui/translations/es/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/es/LC_MESSAGES/qbz-ui.po index 9ce697180..024838ee4 100644 --- a/crates/qbz-ui/translations/es/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/es/LC_MESSAGES/qbz-ui.po @@ -4488,3 +4488,6 @@ msgstr "No hay pistas disponibles para reproducir" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Compartir registros" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZ puede usarse como reproductor sin conexión sin una cuenta de Qobuz™ (sin acceso a la biblioteca de Qobuz™)." diff --git a/crates/qbz-ui/translations/fr/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/fr/LC_MESSAGES/qbz-ui.po index 1356d974e..4e33dcf42 100644 --- a/crates/qbz-ui/translations/fr/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/fr/LC_MESSAGES/qbz-ui.po @@ -4458,3 +4458,6 @@ msgstr "Aucune piste disponible à lire" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Partager les journaux" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZ peut être utilisé comme lecteur hors ligne sans compte Qobuz™ (pas d'accès à la bibliothèque Qobuz™)." diff --git a/crates/qbz-ui/translations/ja/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/ja/LC_MESSAGES/qbz-ui.po index 796596460..51ef539ad 100644 --- a/crates/qbz-ui/translations/ja/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/ja/LC_MESSAGES/qbz-ui.po @@ -4447,3 +4447,6 @@ msgstr "再生できるトラックがありません" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "ログを共有" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZはQobuz™アカウントなしでオフラインプレーヤーとして使用できます(Qobuz™ライブラリにはアクセスできません)。" diff --git a/crates/qbz-ui/translations/pt/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/pt/LC_MESSAGES/qbz-ui.po index 9fdd79326..f9a1c1eb9 100644 --- a/crates/qbz-ui/translations/pt/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/pt/LC_MESSAGES/qbz-ui.po @@ -4458,3 +4458,6 @@ msgstr "Nenhuma faixa disponível para reprodução" # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Compartilhar registros" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "O QBZ pode ser usado como reprodutor offline sem conta Qobuz™ (sem acesso à biblioteca Qobuz™)." diff --git a/crates/qbz-ui/translations/ru/LC_MESSAGES/qbz-ui.po b/crates/qbz-ui/translations/ru/LC_MESSAGES/qbz-ui.po index 7c6e85105..d31bf0c9e 100644 --- a/crates/qbz-ui/translations/ru/LC_MESSAGES/qbz-ui.po +++ b/crates/qbz-ui/translations/ru/LC_MESSAGES/qbz-ui.po @@ -4471,3 +4471,6 @@ msgstr "Нет доступных треков для воспроизведен # Always-visible log uploader entry (settings sub-nav footer) msgid "Share logs" msgstr "Поделиться журналами" +# Guest local-only mode disclaimer line (login screen, #553) +msgid "QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library)." +msgstr "QBZ можно использовать как офлайн-плеер без учётной записи Qobuz™ (без доступа к библиотеке Qobuz™)." diff --git a/crates/qbz-ui/ui/login/LoginScreen.slint b/crates/qbz-ui/ui/login/LoginScreen.slint index 80d8eb1b5..cda2097aa 100644 --- a/crates/qbz-ui/ui/login/LoginScreen.slint +++ b/crates/qbz-ui/ui/login/LoginScreen.slint @@ -258,7 +258,10 @@ export component LoginScreen inherits Rectangle { Rectangle { height: Spacing.sm; } } - if OfflineState.has-previous-session: HorizontalLayout { + // Always visible (#553): without a previous session this + // opens the GUEST profile (user 0) — Local Library only, + // adopted by the account on the first real login. + HorizontalLayout { alignment: center; QbzTextLink { label: @tr("Start offline (no access to Qobuz™ services)"); @@ -273,6 +276,8 @@ export component LoginScreen inherits Rectangle { // --- Legal disclaimer ------------------------------------ Text { text: @tr("QBZ requires an active Qobuz™ subscription. Your credentials are sent directly to Qobuz™.") + + "\n" + + @tr("QBZ can be used as an offline player without a Qobuz™ account (no access to the Qobuz™ library).") + "\n" + @tr("This application uses the Qobuz API but is not certified by Qobuz.") + " " diff --git a/crates/qbz/src/main.rs b/crates/qbz/src/main.rs index 8cc93c347..951ecc420 100644 --- a/crates/qbz/src/main.rs +++ b/crates/qbz/src/main.rs @@ -539,12 +539,19 @@ async fn enter_shell_offline( image_cache: artwork::ImageCache, settings_ctx: Arc, ) -> Result<(), String> { - // Never open the empty user-0 profile: offline mode needs a previous - // session's data (Tauri falls back to user 0; the port refuses — the - // login UI hides the link in that case, this is the backstop). - let Some(user_id) = qbz_app::user_data::UserDataPaths::load_last_user_id() else { - return Err("no previous session — offline mode requires a prior login".to_string()); - }; + // No previous session → the GUEST profile, user 0 (#553; restores the + // Tauri fallback this port used to refuse). The guest builds a real + // per-user store set (local library, mixtapes, prefs) under users/0; + // the first successful login ADOPTS it (AppRuntime::activate renames + // users/0 to the real id when that account has no profile here yet). + // `activate_offline` below resolves the same id — 0 is never persisted + // as the last-user marker, so it never masquerades as a real session. + let user_id = qbz_app::user_data::UserDataPaths::load_last_user_id().unwrap_or(0); + if user_id == 0 { + log::info!( + "[qbz-slint] offline shell: no previous session — entering the guest profile (user 0)" + ); + } // Session scaffolding at the last user (session store, runtime state). runtime.activate_offline().await?;