-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWallmart.xm
379 lines (303 loc) · 12.8 KB
/
Wallmart.xm
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//
// Wallmart.xm
// Wallmart
//
// Created by Timm Kandziora on 16.01.15.
// Copyright (c) 2015 Timm Kandziora. All rights reserved.
//
#import "WallmartHeader.h"
/* HELPER VARIABLES, TWEAK ONLY */
static BOOL unlockedOnce = NO;
static ALAssetsLibrary *assetsLibrary;
static int currentIndexHomeScreen = 0;
static int currentIndexLockScreen = 0;
/* INFORMATION FROM SETTINGS */
static BOOL wallmartGeneralEnabled = YES;
static BOOL wallmartEnabled = YES;
static int wallpaperModeWallmart = 0;
static BOOL blurEnabledWallmart = NO;
static int blurStrengthWallmart = 5;
static int blurModeWallmart = 0;
static BOOL perspectiveZoomWallmart = YES;
static BOOL shuffleWallmart = NO;
static BOOL cycleEnabledWallmart = NO;
static NSString *cycleStartTime = @"10:00";
static NSString *cycleEndTime = @"20:00";
static NSString *albumNameLockscreenWallmart;
static NSString *albumNameHomescreenWallmart;
static UIImage* BlurImage(UIImage *image)
{
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
[gaussianBlurFilter setValue:[CIImage imageWithCGImage:image.CGImage] forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:@(blurStrengthWallmart) forKey:kCIInputRadiusKey];
CIImage *outputImage = [gaussianBlurFilter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGRect rect = [outputImage extent];
rect.origin.x += (rect.size.width - image.size.width ) / 2;
rect.origin.y += (rect.size.height - image.size.height) / 2;
rect.size = image.size;
CGImageRef cgimg = [context createCGImage:outputImage fromRect:rect];
UIImage *blurredImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
return blurredImage;
}
static UIImage* GetBlurredImageFrom(UIImage *image, PLWallpaperMode wallpaperMode)
{
if ((wallpaperMode == PLWallpaperModeHomeScreen && blurModeWallmart == 0) || (wallpaperMode == PLWallpaperModeHomeScreen && blurModeWallmart == 1)) {
return BlurImage(image);
} else if ((wallpaperMode == PLWallpaperModeLockScreen && blurModeWallmart == 0) || (wallpaperMode == PLWallpaperModeLockScreen && blurModeWallmart == 2)) {
return BlurImage(image);
} else {
return image;
}
}
static void SetWallpaperWithImage(UIImage *image, PLWallpaperMode wallpaperMode)
{
PLStaticWallpaperImageViewController *wallpaperViewController = [[PLStaticWallpaperImageViewController alloc] initWithUIImage:image];
wallpaperViewController.saveWallpaperData = YES;
PLWallpaperMode wallpaperModeToSet = wallpaperMode;
uintptr_t address = (uintptr_t)&wallpaperModeToSet;
object_setInstanceVariable(wallpaperViewController, "_wallpaperMode", *(PLWallpaperMode **)address);
[wallpaperViewController _savePhoto];
[wallpaperViewController release];
}
static void ChangeWallpaperForMode(PLWallpaperMode wallpaperMode)
{
if (wallpaperMode == PLWallpaperModeBoth) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumNameHomescreenWallmart]) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (index == currentIndexHomeScreen) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
if (blurEnabledWallmart) {
SetWallpaperWithImage(GetBlurredImageFrom(image, PLWallpaperModeHomeScreen), PLWallpaperModeHomeScreen);
} else {
SetWallpaperWithImage(image, PLWallpaperModeHomeScreen);
}
if (shuffleWallmart) {
currentIndexHomeScreen = arc4random_uniform([group numberOfAssets]);
} else {
currentIndexHomeScreen++;
if (currentIndexHomeScreen == [group numberOfAssets]) {
currentIndexHomeScreen = 0;
}
}
*stop = YES;
}
}];
}
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumNameLockscreenWallmart]) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (index == currentIndexLockScreen) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
if (blurEnabledWallmart) {
SetWallpaperWithImage(GetBlurredImageFrom(image, PLWallpaperModeLockScreen), PLWallpaperModeLockScreen);
} else {
SetWallpaperWithImage(image, PLWallpaperModeLockScreen);
}
if (shuffleWallmart) {
currentIndexLockScreen = arc4random_uniform([group numberOfAssets]);
} else {
currentIndexLockScreen++;
if (currentIndexLockScreen == [group numberOfAssets]) {
currentIndexLockScreen = 0;
}
}
*stop = YES;
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"\n\n [Wallmart] Following error occured: %@", [error description]);
}];
} else if (wallpaperMode == PLWallpaperModeHomeScreen) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumNameHomescreenWallmart]) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (index == currentIndexHomeScreen) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
if (blurEnabledWallmart) {
SetWallpaperWithImage(GetBlurredImageFrom(image, wallpaperMode), wallpaperMode);
} else {
SetWallpaperWithImage(image, wallpaperMode);
}
if (shuffleWallmart) {
currentIndexHomeScreen = arc4random_uniform([group numberOfAssets]);
} else {
currentIndexHomeScreen++;
if (currentIndexHomeScreen == [group numberOfAssets]) {
currentIndexHomeScreen = 0;
}
}
*stop = YES;
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"\n\n [Wallmart] Following error occured: %@", [error description]);
}];
} else {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumNameLockscreenWallmart]) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (index == currentIndexLockScreen) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
if (blurEnabledWallmart) {
SetWallpaperWithImage(GetBlurredImageFrom(image, wallpaperMode), wallpaperMode);
} else {
SetWallpaperWithImage(image, wallpaperMode);
}
if (shuffleWallmart) {
currentIndexLockScreen = arc4random_uniform([group numberOfAssets]);
} else {
currentIndexLockScreen++;
if (currentIndexLockScreen == [group numberOfAssets]) {
currentIndexLockScreen = 0;
}
}
*stop = YES;
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"\n\n [Wallmart] Following error occured: %@", [error description]);
}];
}
}
static BOOL CurrentTimeIsLaterThan(NSString *timeToCompareString)
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"HH:mm"];
NSString *currentTimeString = [dateFormatter stringFromDate:[NSDate date]];
NSDate *currentTime= [dateFormatter dateFromString:currentTimeString];
NSDate *timeToCompare = [dateFormatter dateFromString:timeToCompareString];
NSComparisonResult result = [currentTime compare:timeToCompare];
if (result == NSOrderedDescending) {
return YES;
} else if (result == NSOrderedAscending) {
return NO;
} else {
return MAYBE;
}
}
%hook SBLockScreenManager
- (void)lockUIFromSource:(int)source withOptions:(id)options
{
%orig;
if (unlockedOnce && wallmartGeneralEnabled && wallmartEnabled) {
if (cycleEnabledWallmart) {
if (CurrentTimeIsLaterThan(cycleStartTime) && !CurrentTimeIsLaterThan(cycleEndTime)) {
goto CHANGE;
} else {
return;
}
}
CHANGE:
ChangeWallpaperForMode(wallpaperModeWallmart);
}
}
- (void)_finishUIUnlockFromSource:(int)source withOptions:(id)options
{
%orig;
if (!unlockedOnce) {
unlockedOnce = YES;
assetsLibrary = [[ALAssetsLibrary alloc] init];
}
}
%end
%hook PLStaticWallpaperImageViewController
- (void)providerLegibilitySettingsChanged:(SBSUIWallpaperPreviewViewController *)wallpaperPreviewViewController
{
[wallpaperPreviewViewController setMotionEnabled:perspectiveZoomWallmart];
%orig(wallpaperPreviewViewController);
}
%end
static void ReloadSettings()
{
NSMutableDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
if (settings) {
if ([settings objectForKey:@"wallmartGeneralEnabled"]) {
wallmartGeneralEnabled = [[settings objectForKey:@"wallmartGeneralEnabled"] boolValue];
}
if ([settings objectForKey:@"wallmartEnabled"]) {
wallmartEnabled = [[settings objectForKey:@"wallmartEnabled"] boolValue];
}
if ([settings objectForKey:@"wallpaperModeWallmart"]) {
wallpaperModeWallmart = [[settings objectForKey:@"wallpaperModeWallmart"] intValue];
}
if ([settings objectForKey:@"blurEnabledWallmart"]) {
blurEnabledWallmart = [[settings objectForKey:@"blurEnabledWallmart"] boolValue];
}
if ([settings objectForKey:@"blurStrengthWallmart"]) {
blurStrengthWallmart = [[settings objectForKey:@"blurStrengthWallmart"] intValue];
}
if ([settings objectForKey:@"blurModeWallmart"]) {
blurModeWallmart = [[settings objectForKey:@"blurModeWallmart"] intValue];
}
if ([settings objectForKey:@"perspectiveZoomWallmart"]) {
perspectiveZoomWallmart = [[settings objectForKey:@"perspectiveZoomWallmart"] boolValue];
}
if ([settings objectForKey:@"shuffleWallmart"]) {
shuffleWallmart = [[settings objectForKey:@"shuffleWallmart"] boolValue];
}
if ([settings objectForKey:@"cycleEnabledWallmart"]) {
cycleEnabledWallmart = [[settings objectForKey:@"cycleEnabledWallmart"] boolValue];
}
if ([settings objectForKey:@"cycleStartTime"]) {
cycleStartTime = [[settings objectForKey:@"cycleStartTime"] mutableCopy];
}
if ([settings objectForKey:@"cycleEndTime"]) {
cycleEndTime = [[settings objectForKey:@"cycleEndTime"] mutableCopy];
}
if ([settings objectForKey:@"albumNameLockscreenWallmart"]) {
if (unlockedOnce && ![[settings objectForKey:@"albumNameLockscreenWallmart"] isEqualToString:albumNameLockscreenWallmart]) {
currentIndexHomeScreen = 0;
currentIndexLockScreen = 0;
}
albumNameLockscreenWallmart = [[settings objectForKey:@"albumNameLockscreenWallmart"] mutableCopy];
}
if ([settings objectForKey:@"albumNameHomescreenWallmart"]) {
if (unlockedOnce && ![[settings objectForKey:@"albumNameHomescreenWallmart"] isEqualToString:albumNameHomescreenWallmart]) {
currentIndexHomeScreen = 0;
currentIndexLockScreen = 0;
}
albumNameHomescreenWallmart = [[settings objectForKey:@"albumNameHomescreenWallmart"] mutableCopy];
}
}
[settings release];
}
%ctor {
@autoreleasepool {
ReloadSettings();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)ReloadSettings, CFSTR("com.shinvou.wallmart/reloadWallmartSettings"), NULL, CFNotificationSuspensionBehaviorCoalesce);
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"WallmartEventSwitchBothWallpapers" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
if (unlockedOnce) {
ChangeWallpaperForMode(PLWallpaperModeBoth);
}
}];
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"WallmartEventSwitchLockScreenWallpaper" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
if (unlockedOnce) {
ChangeWallpaperForMode(PLWallpaperModeLockScreen);
}
}];
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"WallmartEventSwitchHomeScreenWallpaper" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
if (unlockedOnce) {
if (unlockedOnce) {
ChangeWallpaperForMode(PLWallpaperModeHomeScreen);
}
}
}];
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"WallmartEventToggleWallmartEnabled" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:settingsPath]];
[settings setObject:@(!wallmartEnabled) forKey:@"wallmartEnabled"];
[settings writeToFile:settingsPath atomically:YES];
wallmartEnabled = !wallmartEnabled;
}];
}
}