Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow modifying display type of persistent-others #1223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://~/Applications</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
15 changes: 14 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 = "~/Appications";
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 Expand Up @@ -122,6 +131,10 @@
out = '${config.out}/${x}'
if Path(fixture).read_text() not in Path(out).read_text():
print("Did not find content from %s in %s" % (fixture, out), file=sys.stderr)
print("Expected:", file=sys.stderr)
print(Path(fixture).read_text(), file=sys.stderr)
print("Got:", file=sys.stderr)
print(Path(out).read_text(), file=sys.stderr)
sys.exit(1)
EOL
'') [
Expand Down
Loading