From d71aa30b41bac3b2e38bd4b8f49e12811cd27ec1 Mon Sep 17 00:00:00 2001 From: Lucas Mendes Loureiro Date: Sun, 10 Nov 2024 23:12:44 +0000 Subject: [PATCH] feat(defaults): adding support to control center --- modules/module-list.nix | 1 + modules/system/defaults-write.nix | 3 + modules/system/defaults/controlcenter.nix | 100 ++++++++++++++++++ .../system-defaults-write/activate-user.txt | 35 ++++++ tests/system-defaults-write.nix | 7 ++ 5 files changed, 146 insertions(+) create mode 100644 modules/system/defaults/controlcenter.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 3725c7e..aa190c7 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -14,6 +14,7 @@ ./system/activation-scripts.nix ./system/applications.nix ./system/defaults-write.nix + ./system/defaults/controlcenter.nix ./system/defaults/LaunchServices.nix ./system/defaults/NSGlobalDomain.nix ./system/defaults/GlobalPreferences.nix diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index 7af972d..4249af9 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -17,6 +17,7 @@ let SoftwareUpdate = defaultsToList "/Library/Preferences/com.apple.SoftwareUpdate" cfg.SoftwareUpdate; # userDefaults + controlcenter = defaultsToList "~/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter; GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences"; LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices; NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain; @@ -71,6 +72,7 @@ in system.activationScripts.userDefaults.text = mkIfAttrs [ + controlcenter GlobalPreferences LaunchServices NSGlobalDomain @@ -113,6 +115,7 @@ in ${concatStringsSep "\n" ActivityMonitor} ${concatStringsSep "\n" CustomUserPreferences} ${concatStringsSep "\n" WindowManager} + ${concatStringsSep "\n" controlcenter} ${optionalString (length dock > 0) '' # Only restart Dock if current user is logged in diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix new file mode 100644 index 0000000..91532fa --- /dev/null +++ b/modules/system/defaults/controlcenter.nix @@ -0,0 +1,100 @@ +{ config, lib, ... }: + +{ + options = { + + system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Battery + + Show a battery percentage in menu bar. Default is null. + ''; + }; + + system.defaults.controlcenter.Sound = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Sound + + Show a sound control in menu bar . Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + + system.defaults.controlcenter.Bluetooth = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Bluetooth + + Show a bluetooth control in menu bar. Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + + system.defaults.controlcenter.AirDrop = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > AirDrop + + Show a AirDrop control in menu bar. Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + + system.defaults.controlcenter.Display = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Display + + Show a Screen Brightness control in menu bar. Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + + system.defaults.controlcenter.FocusModes = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Focus + + Show a Focus control in menu bar. Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + + system.defaults.controlcenter.NowPlaying = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Now Playing + + Show a Now Playing control in menu bar. Default is null. + + 18 = Display icon in menu bar + 24 = Hide icon in menu bar + ''; + }; + }; +} diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index 51b7574..57cfe67 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -489,3 +489,38 @@ defaults write com.apple.WindowManager 'StandardHideWidgets' $' ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'AirDrop' $' + + +18 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowPercentage' $' + + + +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' $' + + +18 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $' + + +24 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $' + + +24 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'NowPlaying' $' + + +18 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' + + +24 +' \ No newline at end of file diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index ab26ef1..c5c9b75 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -94,6 +94,13 @@ true; }; }; + system.defaults.controlcenter.BatteryShowPercentage = true; + system.defaults.controlcenter.Sound = false; + system.defaults.controlcenter.Bluetooth = true; + system.defaults.controlcenter.AirDrop = true; + system.defaults.controlcenter.Display = false; + system.defaults.controlcenter.FocusModes = false; + system.defaults.controlcenter.NowPlaying = true; test = lib.strings.concatMapStringsSep "\n" (x: '' echo >&2 "checking defaults write in /${x}"