-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCSettings.m
154 lines (126 loc) · 4.2 KB
/
DCSettings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#import "DCSettings.h"
#import "DCTypes.h"
static NSString * const kSettingsPlistPath = @"/User/Library/Preferences/com.protosphere.displaycandy.plist";
@interface DCSettings ()
- (DCTransition)_transitionForMode:(DCTransitionMode)mode processRandom:(BOOL)processRandom;
@end
@implementation DCSettings
+ (DCSettings *)sharedSettings
{
@synchronized([DCSettings class]) {
static DCSettings *sharedSettings = nil;
if (!sharedSettings) {
sharedSettings = [[self alloc] init];
}
return sharedSettings;
}
return nil;
}
- (id)init
{
self = [super init];
if (self) {
[self reload];
}
return self;
}
- (BOOL)isEnabled
{
return ([_settings objectForKey:@"enabled"] ? [[_settings objectForKey:@"enabled"] boolValue] : YES);
}
- (DCTransition)transitionForMode:(DCTransitionMode)mode
{
DCTransition transition = [self _transitionForMode:mode processRandom:YES];
return transition;
}
- (DCTransition)_transitionForMode:(DCTransitionMode)mode processRandom:(BOOL)processRandom
{
static DCTransition validSwitchModes[11] = {DCTransitionDefault,
DCTransitionCube,
DCTransitionFlip,
DCTransitionPageCurl,
DCTransitionPageUncurl,
DCTransitionRipple,
DCTransitionFade,
DCTransitionCover,
DCTransitionReveal,
DCTransitionPush,
DCTransitionCameraIris};
DCTransition transition;
switch (mode) {
case DCTransitionModeLaunch:
transition = ([_settings objectForKey:@"launchAnimation"] ? [[_settings objectForKey:@"launchAnimation"] intValue] : DCTransitionSwing);
break;
case DCTransitionModeSuspend:
transition = ([_settings objectForKey:@"suspendAnimation"] ? [[_settings objectForKey:@"suspendAnimation"] intValue] : DCTransitionSwing);
break;
case DCTransitionModeSwitch:
transition = ([_settings objectForKey:@"switchAnimation"] ? [[_settings objectForKey:@"switchAnimation"] intValue] : DCTransitionRipple);
break;
default:
transition = DCTransitionDefault;
}
if ((transition == DCTransitionRandom) && processRandom) {
unsigned i;
unsigned i_max = (DCTransitionModeSwitch ? 10 : 13);
i = arc4random_uniform(i_max);
if (mode == DCTransitionModeSwitch)
transition = validSwitchModes[i];
else
transition = i;
}
return transition;
}
- (DCTransitionDirection)directionForMode:(DCTransitionMode)mode
{
DCTransition transition = [self _transitionForMode:mode processRandom:NO];
DCTransitionDirection direction;
switch (mode) {
case DCTransitionModeLaunch:
direction = ([_settings objectForKey:@"launchAnimationDirection"] ? [[_settings objectForKey:@"launchAnimationDirection"] intValue] : DCTransitionDirectionRight);
break;
case DCTransitionModeSuspend:
direction = [[_settings objectForKey:@"suspendAnimationDirection"] intValue];
break;
case DCTransitionModeSwitch:
direction = ([_settings objectForKey:@"switchAnimationDirection"] ? [[_settings objectForKey:@"switchAnimationDirection"] intValue] : DCTransitionDirectionRight);
break;
default:
direction = DCTransitionDirectionRight;
}
if (transition == DCTransitionRandom) {
unsigned i = arc4random_uniform(3);
direction = i;
}
return direction;
}
- (NSInteger)suckPointForMode:(DCTransitionMode)mode
{
switch (mode) {
case DCTransitionModeLaunch:
return [[_settings objectForKey:@"launchAnimationSuckPoint"] intValue];
case DCTransitionModeSuspend:
return [[_settings objectForKey:@"suspendAnimationSuckPoint"] intValue];
default:
return 0;
}
}
- (CGFloat)durationForMode:(DCTransitionMode)mode
{
switch (mode) {
case DCTransitionModeLaunch:
return ([_settings objectForKey:@"launchAnimationDuration"] ? [[_settings objectForKey:@"launchAnimationDuration"] floatValue] : 0.5f);
case DCTransitionModeSuspend:
return ([_settings objectForKey:@"suspendAnimationDuration"] ? [[_settings objectForKey:@"suspendAnimationDuration"] floatValue] : 0.5f);
case DCTransitionModeSwitch:
return ([_settings objectForKey:@"switchAnimationDuration"] ? [[_settings objectForKey:@"switchAnimationDuration"] floatValue] : 0.5f);
default:
return 0;
}
}
- (void)reload
{
[_settings release];
_settings = [[NSDictionary alloc] initWithContentsOfFile:kSettingsPlistPath];
}
@end