-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f83f107
commit 796fcd6
Showing
11 changed files
with
171 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <Foundation/Foundation.h> | ||
|
||
typedef NS_ENUM(NSInteger, CRDockAlignment) { | ||
CRDockAlignmentLeft = 0, | ||
CRDockAlignmentRight, | ||
CRDockAlignmentAuto, | ||
}; | ||
|
||
@interface CRPreferences : NSObject | ||
|
||
@property (nonatomic, retain) NSDictionary *cachedPreferences; | ||
|
||
+ (instancetype)sharedInstance; | ||
|
||
- (void)reloadPreferences; | ||
- (void)writePreferences; | ||
- (void)updateValue:(id)value forPreferenceKey:(NSString *)key; | ||
|
||
- (NSArray *)excludedApplications; | ||
- (CRDockAlignment)dockAlignment; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "common.h" | ||
|
||
@implementation CRPreferences | ||
|
||
+ (instancetype)sharedInstance | ||
{ | ||
static CRPreferences *sharedInstance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
sharedInstance = [[CRPreferences alloc] init]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
- (id)init | ||
{ | ||
if ((self = [super init])) | ||
{ | ||
[self reloadPreferences]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)reloadPreferences | ||
{ | ||
if ([[NSFileManager defaultManager] fileExistsAtPath:PREFERENCES_PLIST_PATH]) | ||
{ | ||
_cachedPreferences = [[NSDictionary alloc] initWithContentsOfFile:PREFERENCES_PLIST_PATH]; | ||
} | ||
else { | ||
_cachedPreferences = @{}; | ||
} | ||
} | ||
|
||
- (void)writePreferences | ||
{ | ||
[_cachedPreferences writeToFile:PREFERENCES_PLIST_PATH atomically:NO]; | ||
} | ||
|
||
- (void)updateValue:(id)value forPreferenceKey:(NSString *)key | ||
{ | ||
NSMutableDictionary *copy = [_cachedPreferences mutableCopy]; | ||
copy[key] = value; | ||
_cachedPreferences = copy; | ||
[self writePreferences]; | ||
} | ||
|
||
- (NSArray *)excludedApplications | ||
{ | ||
if (_cachedPreferences && [_cachedPreferences valueForKey:@"excludedApps"]) | ||
{ | ||
return [_cachedPreferences valueForKey:@"excludedApps"]; | ||
} | ||
|
||
return @[]; | ||
} | ||
|
||
- (CRDockAlignment)dockAlignment | ||
{ | ||
if (_cachedPreferences && [_cachedPreferences valueForKey:@"dockAlignment"]) | ||
{ | ||
return (CRDockAlignment)[[_cachedPreferences valueForKey:@"dockAlignment"] intValue]; | ||
} | ||
|
||
return CRDockAlignmentAuto; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.