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

dock: allow setting spacer tiles #1187

Open
wants to merge 3 commits 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
59 changes: 52 additions & 7 deletions modules/system/defaults/dock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,61 @@ in {
};

system.defaults.dock.persistent-apps = mkOption {
type = types.nullOr (types.listOf (types.either types.path types.str));
type = let
taggedType = types.attrTag {
app = mkOption {
description = "An application to be added to the dock.";
type = types.str;
};
spacer = mkOption {
description = "A spacer to be added to the dock. Can be small or regular size.";
type = types.submodule {
options.small = mkOption {
description = "Whether the spacer is small.";
type = types.bool;
default = false;
};
};
};
folder = mkOption {
description = "A folder to be added to the dock.";
type = types.str;
};
};

simpleType = types.either types.str types.path;
toTagged = path: { app = path; };
in
types.nullOr (types.listOf (types.coercedTo simpleType toTagged taggedType));
default = null;
example = [ "/Applications/Safari.app" "/System/Applications/Utilities/Terminal.app" ];
example = [
{ app = "/Applications/Safari.app"; }
{ spacer = { small = false; }; }
{ spacer = { small = true; }; }
{ folder = "/System/Applications/Utilities"; }
];
description = ''
Persistent applications in the dock.
Persistent applications, spacers, and folders in the dock.
'';
apply = value:
if !(isList value)
then value
else map (app: { tile-data = { file-data = { _CFURLString = app; _CFURLStringType = 0; }; }; }) value;
apply =
khaneliman marked this conversation as resolved.
Show resolved Hide resolved
let
toTile = item: if item ? app then {
tile-data.file-data = {
_CFURLString = item.app;
_CFURLStringType = 0;
};
} else if item ? spacer then {
tile-data = { };
tile-type = if item.spacer.small then "small-spacer-tile" else "spacer-tile";
} else if item ? folder then {
tile-data.file-data = {
_CFURLString = "file://" + item.folder;
_CFURLStringType = 15;
};
tile-type = if strings.hasInfix "." (last (splitString "/" item.folder)) then "file-tile" else "directory-tile";
} else item;
in
value: if isList value then map toTile value else value;
};

system.defaults.dock.persistent-others = mkOption {
Expand Down
34 changes: 32 additions & 2 deletions tests/fixtures/system-defaults-write/activate-user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ defaults write com.apple.dock 'persistent-apps' $'<?xml version="1.0" encoding="
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>MyApp.app</string>
<string>/Applications/MyApp.app</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
Expand All @@ -267,12 +267,42 @@ defaults write com.apple.dock 'persistent-apps' $'<?xml version="1.0" encoding="
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>Cool.app</string>
<string>/Applications/Cool.app</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
</dict>
</dict>
<dict>
<key>tile-data</key>
<dict>

</dict>
<key>tile-type</key>
<string>small-spacer-tile</string>
</dict>
<dict>
<key>tile-data</key>
<dict>

</dict>
<key>tile-type</key>
<string>spacer-tile</string>
</dict>
<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>file:///Applications/Utilities</string>
<key>_CFURLStringType</key>
<integer>15</integer>
</dict>
</dict>
<key>tile-type</key>
<string>directory-tile</string>
</dict>
</array>
</plist>'
defaults write com.apple.dock 'persistent-others' $'<?xml version="1.0" encoding="UTF-8"?>
Expand Down
8 changes: 7 additions & 1 deletion tests/system-defaults-write.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@
system.defaults.dock.appswitcher-all-displays = false;
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-apps = [
"/Applications/MyApp.app"
{ app = "/Applications/Cool.app"; }
{ spacer = { small = true; }; }
{ spacer = { small = false; }; }
{ folder = "/Applications/Utilities"; }
];
system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"];
system.defaults.dock.scroll-to-open = false;
system.defaults.finder.AppleShowAllFiles = true;
Expand Down