]>
Commit | Line | Data |
---|---|---|
224d48e3 | 1 | /* WinterBoard - Theme Manager for the iPhone |
900dc9a5 | 2 | * Copyright (C) 2008-2014 Jay Freeman (saurik) |
224d48e3 JF |
3 | */ |
4 | ||
900dc9a5 | 5 | /* GNU Lesser General Public License, Version 3 {{{ */ |
224d48e3 | 6 | /* |
900dc9a5 JF |
7 | * WinterBoard is free software: you can redistribute it and/or modify it under |
8 | * the terms of the GNU Lesser General Public License as published by the | |
9 | * Free Software Foundation, either version 3 of the License, or (at your | |
10 | * option) any later version. | |
224d48e3 | 11 | * |
900dc9a5 JF |
12 | * WinterBoard is distributed in the hope that it will be useful, but WITHOUT |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
15 | * License for more details. | |
224d48e3 | 16 | * |
900dc9a5 JF |
17 | * You should have received a copy of the GNU Lesser General Public License |
18 | * along with WinterBoard. If not, see <http://www.gnu.org/licenses/>. | |
19 | **/ | |
20 | /* }}} */ | |
224d48e3 JF |
21 | |
22 | #import <Foundation/Foundation.h> | |
23 | #import <UIKit/UIKit.h> | |
b39b993d DH |
24 | #import <Preferences/PSRootController.h> |
25 | #import <Preferences/PSViewController.h> | |
224d48e3 JF |
26 | #import <Preferences/PSListController.h> |
27 | #import <Preferences/PSSpecifier.h> | |
28 | #import <Preferences/PSTableCell.h> | |
29 | #import <UIKit/UINavigationButton.h> | |
30 | ||
7c88a3f1 | 31 | #include <dlfcn.h> |
b39b993d | 32 | #include <objc/runtime.h> |
7c88a3f1 | 33 | |
e0c66475 | 34 | static void *libhide; |
7c88a3f1 JF |
35 | static BOOL (*IsIconHiddenDisplayId)(NSString *); |
36 | static BOOL (*HideIconViaDisplayId)(NSString *); | |
37 | static BOOL (*UnHideIconViaDisplayId)(NSString *); | |
38 | ||
fdac1738 | 39 | static NSString *WinterBoardDisplayID = @"com.saurik.WinterBoard"; |
7c88a3f1 | 40 | |
224d48e3 JF |
41 | extern NSString *PSTableCellKey; |
42 | extern "C" UIImage *_UIImageWithName(NSString *); | |
43 | ||
44 | static UIImage *checkImage; | |
45 | static UIImage *uncheckedImage; | |
46 | ||
47 | static BOOL settingsChanged; | |
48 | static NSMutableDictionary *_settings; | |
49 | static NSString *_plist; | |
50 | ||
265e19b2 JF |
51 | /* [NSObject yieldToSelector:(withObject:)] {{{*/ |
52 | @interface NSObject (wb$yieldToSelector) | |
53 | - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object; | |
54 | - (id) wb$yieldToSelector:(SEL)selector; | |
55 | @end | |
56 | ||
57 | @implementation NSObject (Cydia) | |
58 | ||
59 | - (void) wb$doNothing { | |
60 | } | |
61 | ||
62 | - (void) wb$_yieldToContext:(NSMutableArray *)context { | |
63 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); | |
64 | ||
65 | SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue])); | |
66 | id object([[context objectAtIndex:1] nonretainedObjectValue]); | |
67 | volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue])); | |
68 | ||
69 | /* XXX: deal with exceptions */ | |
70 | id value([self performSelector:selector withObject:object]); | |
71 | ||
72 | NSMethodSignature *signature([self methodSignatureForSelector:selector]); | |
73 | [context removeAllObjects]; | |
74 | if ([signature methodReturnLength] != 0 && value != nil) | |
75 | [context addObject:value]; | |
76 | ||
77 | stopped = true; | |
78 | ||
79 | [self | |
80 | performSelectorOnMainThread:@selector(wb$doNothing) | |
81 | withObject:nil | |
82 | waitUntilDone:NO | |
83 | ]; | |
84 | ||
85 | [pool release]; | |
86 | } | |
87 | ||
88 | - (id) wb$yieldToSelector:(SEL)selector withObject:(id)object { | |
89 | /*return [self performSelector:selector withObject:object];*/ | |
90 | ||
91 | volatile bool stopped(false); | |
92 | ||
93 | NSMutableArray *context([NSMutableArray arrayWithObjects: | |
94 | [NSValue valueWithPointer:selector], | |
95 | [NSValue valueWithNonretainedObject:object], | |
96 | [NSValue valueWithPointer:const_cast<bool *>(&stopped)], | |
97 | nil]); | |
98 | ||
99 | NSThread *thread([[[NSThread alloc] | |
100 | initWithTarget:self | |
101 | selector:@selector(wb$_yieldToContext:) | |
102 | object:context | |
103 | ] autorelease]); | |
104 | ||
105 | [thread start]; | |
106 | ||
107 | NSRunLoop *loop([NSRunLoop currentRunLoop]); | |
108 | NSDate *future([NSDate distantFuture]); | |
109 | ||
110 | while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); | |
111 | ||
112 | return [context count] == 0 ? nil : [context objectAtIndex:0]; | |
113 | } | |
114 | ||
115 | - (id) wb$yieldToSelector:(SEL)selector { | |
116 | return [self wb$yieldToSelector:selector withObject:nil]; | |
117 | } | |
118 | ||
119 | @end | |
120 | /* }}} */ | |
121 | ||
224d48e3 JF |
122 | /* Theme Settings Controller {{{ */ |
123 | @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> { | |
124 | UITableView *_tableView; | |
125 | NSMutableArray *_themes; | |
126 | } | |
127 | ||
128 | @property (nonatomic, retain) NSMutableArray *themes; | |
129 | ||
224d48e3 JF |
130 | - (id) initForContentSize:(CGSize)size; |
131 | - (id) view; | |
132 | - (id) navigationTitle; | |
133 | - (void) themesChanged; | |
134 | ||
135 | - (int) numberOfSectionsInTableView:(UITableView *)tableView; | |
136 | - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section; | |
137 | - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section; | |
138 | - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; | |
139 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; | |
140 | - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath; | |
141 | - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath; | |
142 | - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath; | |
143 | - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath; | |
7c88a3f1 | 144 | |
224d48e3 JF |
145 | @end |
146 | ||
147 | @implementation WBSThemesController | |
148 | ||
149 | @synthesize themes = _themes; | |
150 | ||
06839c7d | 151 | + (void) initialize { |
224d48e3 JF |
152 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); |
153 | checkImage = [_UIImageWithName(@"UIPreferencesBlueCheck.png") retain]; | |
154 | uncheckedImage = [[UIImage imageWithContentsOfFile:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle/SearchResultsCheckmarkClear.png"] retain]; | |
155 | [pool release]; | |
156 | } | |
157 | ||
158 | - (id) initForContentSize:(CGSize)size { | |
159 | if ((self = [super initForContentSize:size]) != nil) { | |
160 | self.themes = [_settings objectForKey:@"Themes"]; | |
161 | if (!_themes) { | |
162 | if (NSString *theme = [_settings objectForKey:@"Theme"]) { | |
163 | self.themes = [NSMutableArray arrayWithObject: | |
164 | [NSMutableDictionary dictionaryWithObjectsAndKeys: | |
165 | theme, @"Name", | |
166 | [NSNumber numberWithBool:YES], @"Active", nil]]; | |
167 | [_settings removeObjectForKey:@"Theme"]; | |
168 | } | |
169 | if (!_themes) | |
170 | self.themes = [NSMutableArray array]; | |
171 | [_settings setObject:_themes forKey:@"Themes"]; | |
172 | } | |
173 | ||
174 | NSMutableArray *themesOnDisk([NSMutableArray array]); | |
175 | ||
176 | [themesOnDisk | |
177 | addObjectsFromArray:[[NSFileManager defaultManager] | |
178 | contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL] | |
179 | ]; | |
180 | ||
181 | [themesOnDisk addObjectsFromArray:[[NSFileManager defaultManager] | |
182 | contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] | |
183 | error:NULL | |
184 | ]]; | |
185 | ||
186 | for (int i = 0, count = [themesOnDisk count]; i < count; i++) { | |
187 | NSString *theme = [themesOnDisk objectAtIndex:i]; | |
188 | if ([theme hasSuffix:@".theme"]) | |
189 | [themesOnDisk replaceObjectAtIndex:i withObject:[theme stringByDeletingPathExtension]]; | |
190 | } | |
191 | ||
192 | NSMutableSet *themesSet([NSMutableSet set]); | |
193 | ||
194 | for (int i = 0, count = [_themes count]; i < count; i++) { | |
195 | NSDictionary *theme([_themes objectAtIndex:i]); | |
196 | NSString *name([theme objectForKey:@"Name"]); | |
197 | ||
198 | if (!name || ![themesOnDisk containsObject:name]) { | |
199 | [_themes removeObjectAtIndex:i]; | |
200 | i--; | |
201 | count--; | |
202 | } else { | |
203 | [themesSet addObject:name]; | |
204 | } | |
205 | } | |
206 | ||
207 | for (NSString *theme in themesOnDisk) { | |
208 | if ([themesSet containsObject:theme]) | |
209 | continue; | |
210 | [themesSet addObject:theme]; | |
211 | ||
212 | [_themes insertObject:[NSMutableDictionary dictionaryWithObjectsAndKeys: | |
213 | theme, @"Name", | |
214 | [NSNumber numberWithBool:NO], @"Active", | |
215 | nil] atIndex:0]; | |
216 | } | |
217 | ||
218 | _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStyleGrouped]; | |
219 | [_tableView setDataSource:self]; | |
220 | [_tableView setDelegate:self]; | |
221 | [_tableView setEditing:YES]; | |
222 | [_tableView setAllowsSelectionDuringEditing:YES]; | |
b39b993d DH |
223 | if ([self respondsToSelector:@selector(setView:)]) |
224 | [self setView:_tableView]; | |
224d48e3 JF |
225 | } |
226 | return self; | |
227 | } | |
228 | ||
229 | - (void) dealloc { | |
230 | [_tableView release]; | |
231 | [_themes release]; | |
232 | [super dealloc]; | |
233 | } | |
234 | ||
235 | - (id) navigationTitle { | |
236 | return @"Themes"; | |
237 | } | |
238 | ||
239 | - (id) view { | |
240 | return _tableView; | |
241 | } | |
242 | ||
243 | - (void) themesChanged { | |
244 | settingsChanged = YES; | |
245 | } | |
246 | ||
247 | /* UITableViewDelegate / UITableViewDataSource Methods {{{ */ | |
248 | - (int) numberOfSectionsInTableView:(UITableView *)tableView { | |
249 | return 1; | |
250 | } | |
251 | ||
252 | - (id) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section { | |
253 | return nil; | |
254 | } | |
255 | ||
256 | - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section { | |
257 | return _themes.count; | |
258 | } | |
259 | ||
260 | - (id) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
261 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThemeCell"]; | |
262 | if (!cell) { | |
263 | cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100) reuseIdentifier:@"ThemeCell"] autorelease]; | |
264 | //[cell setTableViewStyle:UITableViewCellStyleDefault]; | |
265 | } | |
266 | ||
267 | NSDictionary *theme([_themes objectAtIndex:indexPath.row]); | |
268 | cell.text = [theme objectForKey:@"Name"]; | |
269 | cell.hidesAccessoryWhenEditing = NO; | |
270 | NSNumber *active([theme objectForKey:@"Active"]); | |
271 | BOOL inactive(active == nil || ![active boolValue]); | |
272 | [cell setImage:(inactive ? uncheckedImage : checkImage)]; | |
273 | return cell; | |
274 | } | |
275 | ||
276 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
277 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
278 | NSMutableDictionary *theme = [_themes objectAtIndex:indexPath.row]; | |
279 | NSNumber *active = [theme objectForKey:@"Active"]; | |
280 | BOOL inactive = active == nil || ![active boolValue]; | |
281 | [theme setObject:[NSNumber numberWithBool:inactive] forKey:@"Active"]; | |
282 | [cell setImage:(!inactive ? uncheckedImage : checkImage)]; | |
283 | [tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:YES]; | |
284 | [self themesChanged]; | |
285 | } | |
286 | ||
287 | - (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { | |
288 | NSUInteger fromIndex = [fromIndexPath row]; | |
289 | NSUInteger toIndex = [toIndexPath row]; | |
290 | if (fromIndex == toIndex) | |
291 | return; | |
292 | NSMutableDictionary *theme = [[[_themes objectAtIndex:fromIndex] retain] autorelease]; | |
293 | [_themes removeObjectAtIndex:fromIndex]; | |
294 | [_themes insertObject:theme atIndex:toIndex]; | |
295 | [self themesChanged]; | |
296 | } | |
297 | ||
298 | - (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { | |
299 | return UITableViewCellEditingStyleNone; | |
300 | } | |
301 | ||
302 | - (BOOL) tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { | |
303 | return NO; | |
304 | } | |
305 | ||
306 | - (BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { | |
307 | return YES; | |
308 | } | |
309 | /* }}} */ | |
310 | @end | |
311 | /* }}} */ | |
312 | ||
024f98ea | 313 | @interface WBAdvancedController: PSListController { |
224d48e3 JF |
314 | } |
315 | ||
224d48e3 JF |
316 | - (id) specifiers; |
317 | - (void) settingsChanged; | |
224d48e3 JF |
318 | |
319 | @end | |
320 | ||
024f98ea | 321 | @implementation WBAdvancedController |
224d48e3 | 322 | |
024f98ea JF |
323 | - (id) specifiers { |
324 | if (!_specifiers) | |
325 | _specifiers = [[self loadSpecifiersFromPlistName:@"Advanced" target:self] retain]; | |
326 | return _specifiers; | |
7c88a3f1 JF |
327 | } |
328 | ||
024f98ea JF |
329 | - (void) settingsChanged { |
330 | settingsChanged = YES; | |
331 | } | |
7c88a3f1 | 332 | |
024f98ea JF |
333 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec { |
334 | NSString *key([spec propertyForKey:@"key"]); | |
335 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
336 | value = [NSNumber numberWithBool:(![value boolValue])]; | |
337 | [_settings setValue:value forKey:key]; | |
338 | [self settingsChanged]; | |
224d48e3 JF |
339 | } |
340 | ||
024f98ea JF |
341 | - (id) readPreferenceValue:(PSSpecifier *)spec { |
342 | NSString *key([spec propertyForKey:@"key"]); | |
343 | id defaultValue([spec propertyForKey:@"default"]); | |
344 | id plistValue([_settings objectForKey:key]); | |
345 | if (!plistValue) | |
346 | return defaultValue; | |
347 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
348 | plistValue = [NSNumber numberWithBool:(![plistValue boolValue])]; | |
349 | return plistValue; | |
224d48e3 JF |
350 | } |
351 | ||
43fd3a0b | 352 | - (void) __optimizeThemes { |
265e19b2 JF |
353 | system("/usr/libexec/winterboard/Optimize"); |
354 | } | |
355 | ||
356 | - (void) optimizeThemes { | |
54a4cf27 | 357 | UIAlertView *alert([[[UIAlertView alloc] |
43fd3a0b | 358 | initWithTitle:@"Optimize Themes" |
54a4cf27 | 359 | message:@"Please note that this setting /replaces/ the PNG files that came with the theme. PNG files that have been iPhone-optimized cannot be viewed on a normal computer unless they are first deoptimized. You can use Cydia to reinstall themes that have been optimized in order to revert to the original PNG files." |
43fd3a0b | 360 | delegate:self |
54a4cf27 JF |
361 | cancelButtonTitle:@"Cancel" |
362 | otherButtonTitles:@"Optimize", nil | |
43fd3a0b JF |
363 | ] autorelease]); |
364 | ||
54a4cf27 JF |
365 | [alert setContext:@"optimize"]; |
366 | [alert setNumberOfRows:1]; | |
367 | [alert show]; | |
43fd3a0b JF |
368 | } |
369 | ||
370 | - (void) _optimizeThemes { | |
265e19b2 JF |
371 | UIView *view([self view]); |
372 | UIWindow *window([view window]); | |
373 | ||
374 | UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window] autorelease]); | |
375 | [hud setText:@"Reticulating Splines\nPlease Wait (Minutes)"]; | |
376 | ||
377 | [window setUserInteractionEnabled:NO]; | |
378 | ||
379 | [window addSubview:hud]; | |
380 | [hud show:YES]; | |
43fd3a0b | 381 | [self wb$yieldToSelector:@selector(__optimizeThemes)]; |
265e19b2 JF |
382 | [hud removeFromSuperview]; |
383 | ||
384 | [window setUserInteractionEnabled:YES]; | |
385 | ||
386 | [self settingsChanged]; | |
387 | } | |
388 | ||
54a4cf27 JF |
389 | - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { |
390 | NSString *context([alert context]); | |
43fd3a0b JF |
391 | |
392 | if ([context isEqualToString:@"optimize"]) { | |
54a4cf27 JF |
393 | if (button == [alert firstOtherButtonIndex]) { |
394 | [self performSelector:@selector(_optimizeThemes) withObject:nil afterDelay:0]; | |
43fd3a0b JF |
395 | } |
396 | ||
54a4cf27 JF |
397 | [alert dismissWithClickedButtonIndex:-1 animated:YES]; |
398 | } | |
399 | /*else if ([super respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) | |
400 | [super alertView:alert clickedButtonAtIndex:button];*/ | |
43fd3a0b JF |
401 | } |
402 | ||
024f98ea JF |
403 | @end |
404 | ||
405 | @interface WBSettingsController: PSListController { | |
406 | } | |
407 | ||
408 | - (id) initForContentSize:(CGSize)size; | |
409 | - (void) dealloc; | |
410 | - (void) suspend; | |
411 | - (void) navigationBarButtonClicked:(int)buttonIndex; | |
412 | - (void) viewWillRedisplay; | |
413 | - (void) pushController:(id)controller; | |
414 | - (id) specifiers; | |
415 | - (void) settingsChanged; | |
416 | - (NSString *) title; | |
417 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec; | |
418 | - (id) readPreferenceValue:(PSSpecifier *)spec; | |
419 | ||
420 | @end | |
421 | ||
422 | @implementation WBSettingsController | |
423 | ||
424 | + (void) load { | |
e0c66475 | 425 | libhide = dlopen("/usr/lib/hide.dylib", RTLD_LAZY); |
024f98ea JF |
426 | IsIconHiddenDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "IsIconHiddenDisplayId")); |
427 | HideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "HideIconViaDisplayId")); | |
428 | UnHideIconViaDisplayId = reinterpret_cast<BOOL (*)(NSString *)>(dlsym(libhide, "UnHideIconViaDisplayId")); | |
429 | } | |
430 | ||
34b51da8 JF |
431 | - (void) _wb$loadSettings { |
432 | _plist = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()] retain]; | |
433 | _settings = [NSMutableDictionary dictionaryWithContentsOfFile:_plist]; | |
434 | ||
435 | bool set; | |
436 | if (_settings != nil) | |
437 | set = true; | |
438 | else { | |
439 | set = false; | |
440 | _settings = [NSMutableDictionary dictionary]; | |
441 | } | |
d236b808 | 442 | |
34b51da8 | 443 | _settings = [_settings retain]; |
d236b808 | 444 | |
34b51da8 JF |
445 | if ([_settings objectForKey:@"SummerBoard"] == nil) |
446 | [_settings setObject:[NSNumber numberWithBool:set] forKey:@"SummerBoard"]; | |
024f98ea | 447 | |
e0c66475 JF |
448 | if (libhide != NULL) |
449 | [_settings setObject:[NSNumber numberWithBool:IsIconHiddenDisplayId(WinterBoardDisplayID)] forKey:@"IconHidden"]; | |
34b51da8 JF |
450 | } |
451 | ||
452 | - (id) initForContentSize:(CGSize)size { | |
453 | if ((self = [super initForContentSize:size]) != nil) { | |
454 | [self _wb$loadSettings]; | |
024f98ea JF |
455 | } return self; |
456 | } | |
457 | ||
458 | - (void) dealloc { | |
459 | [_settings release]; | |
460 | [_plist release]; | |
461 | [super dealloc]; | |
462 | } | |
463 | ||
224d48e3 JF |
464 | - (void) suspend { |
465 | if (!settingsChanged) | |
466 | return; | |
467 | ||
468 | NSData *data([NSPropertyListSerialization dataFromPropertyList:_settings format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL]); | |
469 | if (!data) | |
470 | return; | |
471 | if (![data writeToFile:_plist options:NSAtomicWrite error:NULL]) | |
472 | return; | |
473 | ||
e0c66475 JF |
474 | if (libhide != NULL) |
475 | ([[_settings objectForKey:@"IconHidden"] boolValue] ? HideIconViaDisplayId : UnHideIconViaDisplayId)(WinterBoardDisplayID); | |
7c88a3f1 | 476 | |
224d48e3 JF |
477 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons"); |
478 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-icons.plist"); | |
479 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons"); | |
480 | unlink("/User/Library/Caches/com.apple.springboard-imagecache-smallicons.plist"); | |
bbea033b | 481 | |
546a205b JF |
482 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen"); |
483 | unlink("/User/Library/Caches/com.apple.SpringBoard.notificationCenterLinen"); | |
bbea033b | 484 | |
546a205b JF |
485 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0"); |
486 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1"); | |
487 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2"); | |
488 | unlink("/User/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3"); | |
7c88a3f1 JF |
489 | |
490 | system("rm -rf /User/Library/Caches/SpringBoardIconCache"); | |
491 | system("rm -rf /User/Library/Caches/SpringBoardIconCache-small"); | |
f64efe8d | 492 | system("rm -rf /User/Library/Caches/com.apple.IconsCache"); |
546a205b | 493 | system("rm -rf /User/Library/Caches/com.apple.newsstand"); |
bbea033b | 494 | system("rm -rf /User/Library/Caches/com.apple.springboard.sharedimagecache"); |
7c88a3f1 | 495 | |
26bd2bf2 | 496 | system("killall -9 lsd"); |
c532a1cf JF |
497 | |
498 | if (kCFCoreFoundationVersionNumber > 700) // XXX: iOS 6.x | |
499 | system("killall backboardd"); | |
500 | else | |
501 | system("killall SpringBoard"); | |
224d48e3 JF |
502 | } |
503 | ||
b39b993d DH |
504 | - (void) cancelChanges { |
505 | [_settings release]; | |
506 | [_plist release]; | |
b39b993d | 507 | |
34b51da8 JF |
508 | [self _wb$loadSettings]; |
509 | ||
b39b993d DH |
510 | [self reloadSpecifiers]; |
511 | if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) { | |
1d3b613f JF |
512 | [[self navigationItem] setLeftBarButtonItem:nil]; |
513 | [[self navigationItem] setRightBarButtonItem:nil]; | |
838dbf4c DH |
514 | } else { |
515 | [self showLeftButton:nil withStyle:0 rightButton:nil withStyle:0]; | |
b39b993d DH |
516 | } |
517 | settingsChanged = NO; | |
518 | } | |
519 | ||
224d48e3 JF |
520 | - (void) navigationBarButtonClicked:(int)buttonIndex { |
521 | if (!settingsChanged) { | |
522 | [super navigationBarButtonClicked:buttonIndex]; | |
523 | return; | |
524 | } | |
525 | ||
838dbf4c | 526 | if (buttonIndex == 0) { |
b39b993d | 527 | [self cancelChanges]; |
838dbf4c DH |
528 | return; |
529 | } | |
224d48e3 JF |
530 | |
531 | [self suspend]; | |
532 | [self.rootController popController]; | |
533 | } | |
534 | ||
b39b993d DH |
535 | - (void) settingsConfirmButtonClicked:(UIBarButtonItem *)button { |
536 | [self navigationBarButtonClicked:button.tag]; | |
537 | } | |
538 | ||
224d48e3 JF |
539 | - (void) viewWillRedisplay { |
540 | if (settingsChanged) | |
541 | [self settingsChanged]; | |
542 | [super viewWillRedisplay]; | |
543 | } | |
544 | ||
b39b993d DH |
545 | - (void) viewWillAppear:(BOOL)animated { |
546 | if (settingsChanged) | |
547 | [self settingsChanged]; | |
1d3b613f JF |
548 | if ([super respondsToSelector:@selector(viewWillAppear:)]) |
549 | [super viewWillAppear:animated]; | |
b39b993d DH |
550 | } |
551 | ||
224d48e3 JF |
552 | - (void) pushController:(id)controller { |
553 | [self hideNavigationBarButtons]; | |
554 | [super pushController:controller]; | |
555 | } | |
556 | ||
557 | - (id) specifiers { | |
558 | if (!_specifiers) | |
559 | _specifiers = [[self loadSpecifiersFromPlistName:@"WinterBoard" target:self] retain]; | |
560 | return _specifiers; | |
561 | } | |
562 | ||
563 | - (void) settingsChanged { | |
b39b993d DH |
564 | if (![[PSViewController class] instancesRespondToSelector:@selector(showLeftButton:withStyle:rightButton:withStyle:)]) { |
565 | UIBarButtonItem *respringButton([[UIBarButtonItem alloc] initWithTitle:@"Respring" style:UIBarButtonItemStyleDone target:self action:@selector(settingsConfirmButtonClicked:)]); | |
566 | UIBarButtonItem *cancelButton([[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(settingsConfirmButtonClicked:)]); | |
567 | cancelButton.tag = 0; | |
568 | respringButton.tag = 1; | |
1d3b613f JF |
569 | [[self navigationItem] setLeftBarButtonItem:respringButton]; |
570 | [[self navigationItem] setRightBarButtonItem:cancelButton]; | |
b39b993d DH |
571 | [respringButton release]; |
572 | [cancelButton release]; | |
573 | } else { | |
574 | [self showLeftButton:@"Respring" withStyle:2 rightButton:@"Cancel" withStyle:0]; | |
575 | } | |
224d48e3 JF |
576 | settingsChanged = YES; |
577 | } | |
578 | ||
579 | - (NSString *) title { | |
580 | return @"WinterBoard"; | |
581 | } | |
582 | ||
583 | - (void) setPreferenceValue:(id)value specifier:(PSSpecifier *)spec { | |
7c88a3f1 | 584 | NSString *key([spec propertyForKey:@"key"]); |
224d48e3 JF |
585 | if ([[spec propertyForKey:@"negate"] boolValue]) |
586 | value = [NSNumber numberWithBool:(![value boolValue])]; | |
7c88a3f1 | 587 | [_settings setValue:value forKey:key]; |
224d48e3 JF |
588 | [self settingsChanged]; |
589 | } | |
590 | ||
591 | - (id) readPreferenceValue:(PSSpecifier *)spec { | |
592 | NSString *key([spec propertyForKey:@"key"]); | |
593 | id defaultValue([spec propertyForKey:@"default"]); | |
594 | id plistValue([_settings objectForKey:key]); | |
595 | if (!plistValue) | |
596 | return defaultValue; | |
597 | if ([[spec propertyForKey:@"negate"] boolValue]) | |
598 | plistValue = [NSNumber numberWithBool:(![plistValue boolValue])]; | |
599 | return plistValue; | |
600 | } | |
601 | ||
602 | @end | |
b39b993d DH |
603 | |
604 | #define WBSAddMethod(_class, _sel, _imp, _type) \ | |
605 | if (![[_class class] instancesRespondToSelector:@selector(_sel)]) \ | |
606 | class_addMethod([_class class], @selector(_sel), (IMP)_imp, _type) | |
607 | void $PSRootController$popController(PSRootController *self, SEL _cmd) { | |
608 | [self popViewControllerAnimated:YES]; | |
609 | } | |
610 | ||
611 | void $PSViewController$hideNavigationBarButtons(PSRootController *self, SEL _cmd) { | |
612 | } | |
613 | ||
614 | id $PSViewController$initForContentSize$(PSRootController *self, SEL _cmd, CGRect contentSize) { | |
615 | return [self init]; | |
616 | } | |
617 | ||
618 | static __attribute__((constructor)) void __wbsInit() { | |
619 | WBSAddMethod(PSRootController, popController, $PSRootController$popController, "v@:"); | |
620 | WBSAddMethod(PSViewController, hideNavigationBarButtons, $PSViewController$hideNavigationBarButtons, "v@:"); | |
621 | WBSAddMethod(PSViewController, initForContentSize:, $PSViewController$initForContentSize$, "@@:{ff}"); | |
622 | } |