Skip to content

Commit

Permalink
spotify-player: add support for actions
Browse files Browse the repository at this point in the history
Actions were added in the v0.19.1 release.
  • Loading branch information
diniamo committed Sep 29, 2024
1 parent ffe2d07 commit 05d2833
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
44 changes: 37 additions & 7 deletions modules/programs/spotify-player.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ config, lib, pkgs, ... }:

let
inherit (lib)
mkEnableOption mkPackageOption mkOption types literalExpression mkIf;
inherit (lib) mkEnableOption mkPackageOption mkOption literalExpression mkIf;
inherit (lib.types) listOf;

cfg = config.programs.spotify-player;
tomlFormat = pkgs.formats.toml { };

tomlType = tomlFormat.type;
in {
meta.maintainers = with lib.hm.maintainers; [ diniamo ];

Expand All @@ -16,7 +16,7 @@ in {
package = mkPackageOption pkgs "spotify-player" { };

settings = mkOption {
type = tomlFormat.type;
type = tomlType;
default = { };
example = literalExpression ''
{
Expand All @@ -43,7 +43,7 @@ in {
};

themes = mkOption {
type = types.listOf tomlFormat.type;
type = listOf tomlType;
default = [ ];
example = literalExpression ''
[
Expand Down Expand Up @@ -94,7 +94,7 @@ in {
};

keymaps = mkOption {
type = types.listOf tomlFormat.type;
type = listOf tomlType;
default = [ ];
example = literalExpression ''
[
Expand Down Expand Up @@ -129,6 +129,36 @@ in {
for the full list of options.
'';
};

actions = mkOption {
type = listOf tomlType;
default = [ ];
example = literalExpression ''
[
{
action = "GoToArtist";
key_sequence = "g A";
}
{
action = "GoToAlbum";
key_sequence = "g B";
target = "PlayingTrack";
}
{
action = "ToggleLiked";
key_sequence = "C-l";
}
]
'';
description = ''
Configuration written to the `actions` field of
{file}`$XDG_CONFIG_HOME/spotify-player/keymap.toml`.
See
<https://github.com/aome510/spotify-player/blob/master/docs/config.md#actions>
for the full list of options.
'';
};
};

config = mkIf cfg.enable {
Expand All @@ -146,7 +176,7 @@ in {

"spotify-player/keymap.toml" = mkIf (cfg.keymaps != [ ]) {
source = tomlFormat.generate "spotify-player-keymap" {
inherit (cfg) keymaps;
inherit (cfg) keymaps actions;
};
};
};
Expand Down
13 changes: 13 additions & 0 deletions tests/modules/programs/spotify-player/keymap.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[[actions]]
action = "GoToArtist"
key_sequence = "g A"

[[actions]]
action = "GoToAlbum"
key_sequence = "g B"
target = "PlayingTrack"

[[actions]]
action = "ToggleLiked"
key_sequence = "C-l"

[[keymaps]]
command = "NextTrack"
key_sequence = "g n"
Expand Down
16 changes: 16 additions & 0 deletions tests/modules/programs/spotify-player/settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@
key_sequence = "q";
}
];

actions = [
{
action = "GoToArtist";
key_sequence = "g A";
}
{
action = "GoToAlbum";
key_sequence = "g B";
target = "PlayingTrack";
}
{
action = "ToggleLiked";
key_sequence = "C-l";
}
];
};

test.stubs.spotify-player = { };
Expand Down

0 comments on commit 05d2833

Please sign in to comment.