dock: refactor persistent-apps option
This commit is contained in:
parent
02ba211ea1
commit
e21d07988b
3 changed files with 98 additions and 11 deletions
|
|
@ -128,20 +128,72 @@ 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;
|
||||
};
|
||||
file = mkOption {
|
||||
description = "A file to be added to the dock.";
|
||||
type = types.str;
|
||||
};
|
||||
folder = mkOption {
|
||||
description = "A folder 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
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"; }
|
||||
{ file = "/User/example/Downloads/test.csv"; }
|
||||
];
|
||||
description = ''
|
||||
Persistent applications in the dock.
|
||||
Persistent applications, spacers, files, and folders in the dock.
|
||||
'';
|
||||
apply =
|
||||
let
|
||||
tileTypes = ["spacer-tile" "small-spacer-tile"];
|
||||
toSpecialTile = type: { tile-data = {}; tile-type = type; };
|
||||
toAppTile = cfurl: { tile-data = { file-data = { _CFURLString = cfurl; _CFURLStringType = 0; }; }; };
|
||||
toTile = s: if elem s tileTypes then toSpecialTile s else toAppTile s;
|
||||
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 = "directory-tile";
|
||||
} else if item ? file then {
|
||||
tile-data.file-data = {
|
||||
_CFURLString = "file://" + item.file;
|
||||
_CFURLStringType = 15;
|
||||
};
|
||||
tile-type = "file-tile";
|
||||
} else item;
|
||||
in
|
||||
value: if isList value then map toTile value else value;
|
||||
value: if value == null then null else map toTile value;
|
||||
};
|
||||
|
||||
system.defaults.dock.persistent-others = mkOption {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue