Skip to content

Commit

Permalink
allow modifying display type of persistent-others
Browse files Browse the repository at this point in the history
  • Loading branch information
fcjr committed Dec 15, 2024
1 parent a35b08d commit 8dcd81b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 4 deletions.
72 changes: 69 additions & 3 deletions modules/system/defaults/dock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@ with lib;
let
# Should only be used with options that previously used floats defined as strings.
inherit (config.lib.defaults.types) floatWithDeprecationError;

persistentOther = types.submodule {
options = {
path = lib.mkOption {
type = types.either types.path types.str;
description = "Path as either a path type or string";
};
arrangement = let
values = [
"automatic" # 0
"name" # 1
"date-added" # 2
"date-modified" # 3
"date-created" # 4
"kind" # 5
];
in lib.mkOption {
type = types.nullOr (types.enum values);
default = null;
description = "Sort items by specified criteria";
apply = value: lib.lists.findFirstIndex (x: x == value) 0 values;
};
showas = let
values = [
"automatic" # 0
"fan" # 1
"grid" # 2
"list" # 3
];
in lib.mkOption {
type = types.nullOr (types.enum values);
default = null;
description = "View content as specified style";
apply = value: lib.lists.findFirstIndex (x: x == value) 0 values;
};
displayas = let
values = [
"stack" # 0
"folder" # 1
];
in lib.mkOption {
type = types.nullOr (types.enum values);
default = null;
description = "Display item as stack or folder";
apply = value: lib.lists.findFirstIndex (x: x == value) 0 values;
};
};
};
in {
imports = [
(mkRenamedOptionModule [ "system" "defaults" "dock" "expose-group-by-app" ] [ "system" "defaults" "dock" "expose-group-apps" ])
Expand Down Expand Up @@ -141,16 +189,34 @@ in {
};

system.defaults.dock.persistent-others = mkOption {
type = types.nullOr (types.listOf (types.either types.path types.str));
type = types.nullOr (types.listOf (types.oneOf [ types.path types.str persistentOther ]));
default = null;
example = [ "~/Documents" "~/Downloads" ];
description = ''
Persistent folders in the dock.
'';
apply = value:
if !(isList value)
if !(lib.isList value)
then value
else map (folder: { tile-data = { file-data = { _CFURLString = "file://" + folder; _CFURLStringType = 15; }; }; tile-type = if strings.hasInfix "." (last (splitString "/" folder)) then "file-tile" else "directory-tile"; }) value;
else map (folder:
let
folderPath = if builtins.isAttrs folder then toString folder.path else toString folder;
isSimplePath = !(builtins.isAttrs folder);
in {
tile-data = {
file-data = {
_CFURLString = "file://" + folderPath;
_CFURLStringType = 15;
};
} // (if isSimplePath then {} else lib.filterAttrs (n: v: v != null) {
arrangement = folder.arrangement;
showas = folder.showas;
displayas = folder.displayas;
});
tile-type = if lib.strings.hasInfix "." (lib.last (lib.splitString "/" folderPath))
then "file-tile"
else "directory-tile";
}) value;
};

system.defaults.dock.scroll-to-open = mkOption {
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/system-defaults-write/activate-user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ defaults write com.apple.dock 'persistent-others' $'<?xml version="1.0" encoding
<key>tile-type</key>
<string>file-tile</string>
</dict>
<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>file:///</string>
<key>_CFURLStringType</key>
<integer>15</integer>
</dict>
<key>displayas</key>
<integer>1</integer>
<key>showas</key>
<integer>2</integer>
<key>arrangement</key>
<integer>3</integer>
</dict>
<key>tile-type</key>
<string>directory-tile</string>
</dict>
</array>
</plist>'
defaults write com.apple.dock 'scroll-to-open' $'<?xml version="1.0" encoding="UTF-8"?>
Expand Down
11 changes: 10 additions & 1 deletion tests/system-defaults-write.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@
system.defaults.dock.autohide-delay = 0.24;
system.defaults.dock.orientation = "left";
system.defaults.dock.persistent-apps = ["MyApp.app" "Cool.app"];
system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"];
system.defaults.dock.persistent-others = [
"~/Documents"
"~/Downloads/file.txt"
{
path = "/";
displayas = "folder";
showas = "fan";
arrangement = "date-modified";
}
];
system.defaults.dock.scroll-to-open = false;
system.defaults.finder.AppleShowAllFiles = true;
system.defaults.finder.ShowStatusBar = true;
Expand Down

0 comments on commit 8dcd81b

Please sign in to comment.