]>
Commit | Line | Data |
---|---|---|
62b2dbad | 1 | /* WinterBoard - Theme Manager for the iPhone |
224d48e3 | 2 | * Copyright (C) 2008-2009 Jay Freeman (saurik) |
62b2dbad JF |
3 | */ |
4 | ||
5 | /* | |
6 | * Redistribution and use in source and binary | |
7 | * forms, with or without modification, are permitted | |
8 | * provided that the following conditions are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the | |
11 | * above copyright notice, this list of conditions | |
12 | * and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the | |
14 | * above copyright notice, this list of conditions | |
15 | * and the following disclaimer in the documentation | |
16 | * and/or other materials provided with the | |
17 | * distribution. | |
18 | * 3. The name of the author may not be used to endorse | |
19 | * or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
24 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
33 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | #import <Foundation/Foundation.h> | |
39 | #import <CoreGraphics/CGGeometry.h> | |
40 | #import <UIKit/UIKit.h> | |
41 | ||
77d89d52 JF |
42 | #include <objc/objc-runtime.h> |
43 | ||
224d48e3 JF |
44 | #import <Preferences/PSRootController.h> |
45 | #import <Preferences/PSViewController.h> | |
b44f5c22 | 46 | #import <Preferences/PSListController.h> |
224d48e3 | 47 | #import <Preferences/PSSpecifier.h> |
d5fb6e01 | 48 | |
f9511b59 JF |
49 | #include <substrate.h> |
50 | #include <mach-o/dyld.h> | |
51 | ||
b44f5c22 DH |
52 | static NSBundle *wbSettingsBundle; |
53 | static Class $WBSettingsController; | |
54 | ||
224d48e3 JF |
55 | @interface UIApplication (Private) |
56 | - (void) terminateWithSuccess; | |
57 | @end | |
d5fb6e01 | 58 | |
b44f5c22 DH |
59 | @interface UIDevice (Private) |
60 | - (BOOL) isWildcat; | |
61 | @end | |
62 | ||
63 | @interface PSRootController (Compatibility) | |
64 | - (id) _popController; // < 3.2 | |
65 | - (id) contentView; // < 3.2 | |
66 | - (id) lastController; // < 3.2 | |
67 | - (id) topViewController; // >= 3.2 | |
68 | @end | |
69 | ||
70 | @interface PSListController (Compatibility) | |
71 | - (void) viewWillBecomeVisible:(void *)specifier; // < 3.2 | |
72 | - (void) viewWillAppear:(BOOL)a; // >= 3.2 | |
73 | - (void) setSpecifier:(PSSpecifier *)spec; // >= 3.2 | |
74 | @end | |
75 | ||
224d48e3 | 76 | @interface WBRootController : PSRootController { |
b44f5c22 | 77 | PSListController *_rootListController; |
d5fb6e01 JF |
78 | } |
79 | ||
b44f5c22 | 80 | @property (readonly) PSListController *rootListController; |
d5fb6e01 | 81 | |
224d48e3 | 82 | - (void) setupRootListForSize:(CGSize)size; |
b44f5c22 | 83 | - (id) topViewController; |
d5fb6e01 | 84 | @end |
62b2dbad | 85 | |
224d48e3 | 86 | @implementation WBRootController |
62b2dbad | 87 | |
b44f5c22 | 88 | @synthesize rootListController = _rootListController; |
62b2dbad | 89 | |
b44f5c22 | 90 | // < 3.2 |
224d48e3 | 91 | - (void) setupRootListForSize:(CGSize)size { |
b44f5c22 | 92 | PSSpecifier *spec([[PSSpecifier alloc] init]); |
224d48e3 JF |
93 | [spec setTarget:self]; |
94 | spec.name = @"WinterBoard"; | |
62b2dbad | 95 | |
b44f5c22 DH |
96 | _rootListController = [[$WBSettingsController alloc] initForContentSize:size]; |
97 | _rootListController.rootController = self; | |
98 | _rootListController.parentController = self; | |
99 | [_rootListController viewWillBecomeVisible:spec]; | |
d5fb6e01 | 100 | |
224d48e3 | 101 | [spec release]; |
62b2dbad | 102 | |
b44f5c22 | 103 | [self pushController:_rootListController]; |
d5fb6e01 JF |
104 | } |
105 | ||
b44f5c22 DH |
106 | // >= 3.2 |
107 | - (void) loadView { | |
108 | [super loadView]; | |
109 | [self pushViewController:[self rootListController] animated:NO]; | |
110 | } | |
111 | ||
112 | - (PSListController *) rootListController { | |
113 | if(!_rootListController) { | |
114 | PSSpecifier *spec([[PSSpecifier alloc] init]); | |
115 | [spec setTarget:self]; | |
116 | spec.name = @"WinterBoard"; | |
117 | _rootListController = [[$WBSettingsController alloc] initForContentSize:CGSizeZero]; | |
118 | _rootListController.rootController = self; | |
119 | _rootListController.parentController = self; | |
120 | [_rootListController setSpecifier:spec]; | |
121 | [spec release]; | |
122 | } | |
123 | return _rootListController; | |
124 | } | |
125 | ||
126 | - (id) contentView { | |
127 | if ([[PSRootController class] instancesRespondToSelector:@selector(contentView)]) { | |
128 | return [super contentView]; | |
129 | } else { | |
130 | return [super view]; | |
131 | } | |
132 | } | |
133 | ||
134 | - (id) topViewController { | |
135 | if ([[PSRootController class] instancesRespondToSelector:@selector(topViewController)]) { | |
136 | return [super topViewController]; | |
137 | } else { | |
138 | return [super lastController]; | |
139 | } | |
140 | } | |
141 | ||
1d3b613f | 142 | - (void) _popController { |
224d48e3 JF |
143 | // Pop the last controller = exit the application. |
144 | // The only time the last controller should pop is when the user taps Respring/Cancel. | |
145 | // Which only gets displayed if the user has made changes. | |
b44f5c22 | 146 | if ([self topViewController] == _rootListController) |
224d48e3 | 147 | [[UIApplication sharedApplication] terminateWithSuccess]; |
1d3b613f | 148 | [super _popController]; |
62b2dbad | 149 | } |
b44f5c22 | 150 | |
224d48e3 | 151 | @end |
62b2dbad | 152 | |
224d48e3 JF |
153 | @interface WBApplication : UIApplication { |
154 | WBRootController *_rootController; | |
d5fb6e01 | 155 | } |
62b2dbad | 156 | |
224d48e3 JF |
157 | @end |
158 | ||
159 | @implementation WBApplication | |
160 | ||
161 | - (void) dealloc { | |
162 | [_rootController release]; | |
163 | [super dealloc]; | |
d5fb6e01 | 164 | } |
62b2dbad | 165 | |
224d48e3 | 166 | - (void) applicationWillTerminate:(UIApplication *)application { |
b44f5c22 | 167 | [_rootController.rootListController suspend]; |
62b2dbad JF |
168 | } |
169 | ||
170 | - (void) applicationDidFinishLaunching:(id)unused { | |
b44f5c22 DH |
171 | wbSettingsBundle = [NSBundle bundleWithPath:@"/System/Library/PreferenceBundles/WinterBoardSettings.bundle"]; |
172 | [wbSettingsBundle load]; | |
173 | $WBSettingsController = [wbSettingsBundle principalClass]; | |
174 | ||
175 | CGRect applicationFrame(([UIDevice instancesRespondToSelector:@selector(isWildcat)] | |
77d89d52 | 176 | && [[UIDevice currentDevice] isWildcat]) || objc_getClass("UIStatusBar") != nil |
b44f5c22 DH |
177 | ? [UIScreen mainScreen].bounds |
178 | : [UIScreen mainScreen].applicationFrame); | |
179 | UIWindow *window([[UIWindow alloc] initWithFrame:applicationFrame]); | |
224d48e3 | 180 | _rootController = [[WBRootController alloc] initWithTitle:@"WinterBoard" identifier:[[NSBundle mainBundle] bundleIdentifier]]; |
b44f5c22 | 181 | [window addSubview:[_rootController contentView]]; |
224d48e3 | 182 | [window makeKeyAndVisible]; |
62b2dbad JF |
183 | } |
184 | ||
185 | @end | |
186 | ||
f9511b59 JF |
187 | MSHook(int32_t, NSVersionOfLinkTimeLibrary, const char *name) { |
188 | if (strcmp(name, "UIKit") == 0) | |
189 | return 0x6400000; | |
190 | return _NSVersionOfLinkTimeLibrary(name); | |
191 | } | |
192 | ||
62b2dbad | 193 | int main(int argc, char *argv[]) { |
b44f5c22 | 194 | NSAutoreleasePool *pool( [[NSAutoreleasePool alloc] init]); |
62b2dbad | 195 | |
f9511b59 JF |
196 | MSHookFunction(NSVersionOfLinkTimeLibrary, MSHake(NSVersionOfLinkTimeLibrary)); |
197 | ||
62b2dbad JF |
198 | int value = UIApplicationMain(argc, argv, @"WBApplication", @"WBApplication"); |
199 | ||
200 | [pool release]; | |
201 | return value; | |
202 | } |