-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathOSPreferences.m
71 lines (51 loc) · 2 KB
/
OSPreferences.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#import "OSPreferences.h"
#define PREFS_PATH @"/var/mobile/Library/Preferences/com.eswick.osexperience.plist"
/* Dictionary tools */
#define dictionary [NSDictionary dictionaryWithContentsOfFile:PREFS_PATH]
#define getPrefValue(key) ([dictionary objectForKey:@#key] ? [dictionary objectForKey:@#key] : [DEFAULTS objectForKey:@#key])
#define setPrefValue(key,value) \
({ \
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithDictionary:dictionary]; \
[tempDict setObject:value forKey:@#key];\
[tempDict writeToFile:PREFS_PATH atomically:true];\
})
#define getBoolValue(key) [getPrefValue(key) boolValue]
#define setBoolValue(key,value) setPrefValue(key,[NSNumber numberWithBool:value])
#define fileManager [NSFileManager defaultManager]
/* Value helpers */
#define FLOAT_RDONLY(name) - (float)name{ return [getPrefValue(name) floatValue]; }
#define FLOAT_RDWT(name) - (float)name{ return [getPrefValue(name) floatValue]; } - (void)set##name:(float)value{ setPrefValue(name,[NSNumber numberWithFloat:value]); }
#define BOOL_RDWT(name) - (BOOL)name { return getBoolValue(name); } - (void)set##name:(BOOL)value{ setBoolValue(name,value); }
#define VALUE(name,default) @#name : @(default),
/* ======== */
#define DEFAULTS \
@{\
VALUE(ENABLED, true)\
VALUE(SNAP_MARGIN, 20)\
VALUE(PANE_SEPARATOR_SIZE, 40)\
VALUE(SCROLL_TO_PANE_DURATION, 1.0)\
VALUE(LIVE_PREVIEWS, true)\
VALUE(TUTORIAL_SHOWN, false)\
VALUE(SHOW_MG_POPUP, true)\
}
@implementation OSPreferences
BOOL_RDWT (ENABLED);
BOOL_RDWT (LIVE_PREVIEWS);
BOOL_RDWT (TUTORIAL_SHOWN);
BOOL_RDWT (SHOW_MG_POPUP);
FLOAT_RDONLY (SNAP_MARGIN);
FLOAT_RDONLY (PANE_SEPARATOR_SIZE);
FLOAT_RDWT (SCROLL_TO_PANE_DURATION);
+ (id)sharedInstance{
static OSPreferences *_prefs;
if (_prefs == nil)
{
_prefs = [[self alloc] init];
if(![fileManager fileExistsAtPath:PREFS_PATH]){
/* Write defaults */
[DEFAULTS writeToFile:PREFS_PATH atomically:true];
}
}
return _prefs;
}
@end