Skip to content

Commit

Permalink
dock: refactor persistent-apps option
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Jan 26, 2025
1 parent 53cdccf commit 48a6b5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 34 deletions.
26 changes: 8 additions & 18 deletions modules/system/defaults/dock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ in {
taggedType = types.attrTag {
app = mkOption {
description = "An application to be added to the dock.";
type = types.submodule {
options.path = mkOption {
description = "Path to the application.";
type = types.str;
};
};
type = types.str;
};
spacer = mkOption {
description = "A spacer to be added to the dock. Can be small or regular size.";
Expand All @@ -151,25 +146,20 @@ in {
};
folder = mkOption {
description = "A folder to be added to the dock.";
type = types.submodule {
options.path = mkOption {
description = "Path to the folder.";
type = types.str;
};
};
type = types.str;
};
};

simpleType = types.either types.str types.path;
toTagged = (path: {app = {inherit path;};});
toTagged = path: { app = path; };
in
types.nullOr (types.listOf (types.coercedTo simpleType toTagged taggedType));
default = null;
example = [
{ app = { path = "/Applications/Safari.app"; }; }
{ app = "/Applications/Safari.app"; }
{ spacer = { small = false; }; }
{ spacer = { small = true; }; }
{ folder = { path = "/System/Applications/Utilities"; }; }
{ folder = "/System/Applications/Utilities"; }
];
description = ''
Persistent applications, spacers, and folders in the dock.
Expand All @@ -178,18 +168,18 @@ in {
let
toTile = item: if item ? app then {
tile-data.file-data = {
_CFURLString = item.app.path;
_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.path;
_CFURLString = "file://" + item.folder;
_CFURLStringType = 15;
};
tile-type = if strings.hasInfix "." (last (splitString "/" item.folder.path)) then "file-tile" else "directory-tile";
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;
Expand Down
12 changes: 0 additions & 12 deletions tests/fixtures/system-defaults-write/activate-user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,6 @@ defaults write com.apple.dock 'persistent-apps' $'<?xml version="1.0" encoding="
</dict>
</dict>
</dict>
<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>/Applications/MyApp.app</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
</dict>
</dict>
<dict>
<key>tile-data</key>
<dict>
Expand Down
7 changes: 3 additions & 4 deletions tests/system-defaults-write.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@
system.defaults.dock.autohide-delay = 0.24;
system.defaults.dock.orientation = "left";
system.defaults.dock.persistent-apps = [
"/Applications/MyApp.app"
{ app = { path = "/Applications/MyApp.app"; }; }
{ app = { path = "/Applications/Cool.app"; }; }
"/Applications/MyApp.app"
{ app = "/Applications/Cool.app"; }
{ spacer = { small = true; }; }
{ spacer = { small = false; }; }
{ folder = { path = "/Applications/Utilities"; }; }
{ folder = "/Applications/Utilities"; }
];
system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"];
system.defaults.dock.scroll-to-open = false;
Expand Down

0 comments on commit 48a6b5a

Please sign in to comment.