You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4KB

  1. #include "TFDTSRootListController.h"
  2. #import <Preferences/PSSpecifier.h>
  3. @implementation TFDTSRootListController
  4. - (NSArray *)specifiers {
  5. if (!_specifiers) {
  6. _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
  7. }
  8. return _specifiers;
  9. }
  10. - (id)readPreferenceValue:(PSSpecifier*)specifier {
  11. NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
  12. NSMutableDictionary *settings = [NSMutableDictionary dictionary];
  13. [settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
  14. return (settings[specifier.properties[@"key"]]) ?: specifier.properties[@"default"];
  15. }
  16. - (void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier {
  17. NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
  18. NSMutableDictionary *settings = [NSMutableDictionary dictionary];
  19. [settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
  20. [settings setObject:value forKey:specifier.properties[@"key"]];
  21. [settings writeToFile:path atomically:YES];
  22. CFStringRef notificationName = (__bridge CFStringRef)specifier.properties[@"PostNotification"];
  23. if (notificationName) {
  24. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL, YES);
  25. }
  26. }
  27. @end