diff --git a/home-manager/fred.nix b/home-manager/fred.nix index f5fdb37..ba3ebe8 100644 --- a/home-manager/fred.nix +++ b/home-manager/fred.nix @@ -74,6 +74,25 @@ in inherit src; hash = "sha256-CSZ5sZ+d7Jhi43ipaWXKupYPFgWCbCx4RMTQN8emu9o="; }; + # Always claim playback on our own device at launch, instead of having to + # pick it from the device popup every time. Two upstream guards in + # client/mod.rs stop that from happening: + # 1. initialize_playback skips connecting entirely if any playback + # already exists — a phone or web player holding a paused playback + # is enough. + # 2. find_available_device returns the currently *active* device before + # it ever gets to the "prefer the integrated device" branch. + # Disabling both leaves the integrated device as the startup target. + # The CLI can't do this from the outside: `connect --name` resolves names + # against the Web API device list, which usually doesn't contain our + # freshly registered librespot device at all. + postPatch = (old.postPatch or "") + '' + substituteInPlace spotify_player/src/client/mod.rs \ + --replace-fail "if state.player.read().playback.is_some() {" \ + "if false {" \ + --replace-fail "if let Some(d) = devices.iter().find(|d| d.is_active) {" \ + "if let Some(d) = devices.iter().find(|d| false && d.is_active) {" + ''; }); settings = { enable_audio_visualization = true; @@ -88,23 +107,10 @@ in }; # Upstream ships no .desktop file (TUI only), so the launcher can't find it. - # The launcher also force-connects to our own librespot device: upstream only - # auto-connects when *no* playback exists anywhere on the account - # (client/mod.rs `initialize_playback` bails out when playback.is_some()), so - # a phone or web player still holding a paused playback means we'd otherwise - # have to pick the device by hand every launch. Retry because the device takes - # a few seconds to register with Spotify. xdg.desktopEntries.spotify-player = lib.mkIf isDesktop { name = "Spotify Player"; genericName = "Music Player"; - exec = "ghostty --title=spotify-player -e ${pkgs.writeShellScript "spotify-player-connected" '' - sp=${config.programs.spotify-player.package}/bin/spotify_player - for _ in $(seq 15); do - sleep 2 - "$sp" connect --name spotify-player && break - done & - exec "$sp" - ''}"; + exec = "ghostty --title=spotify-player -e spotify_player"; icon = "spotify"; terminal = false; categories = [ "Audio" "Music" "Player" "AudioVideo" ];