1 /* Cydget - open-source IntelliScreen replacement
2 * Copyright (C) 2009 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
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
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.
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.
38 #include <substrate.h>
40 #include <Foundation/Foundation.h>
41 #include <GraphicsServices/GraphicsServices.h>
42 #include <UIKit/UIKit.h>
44 #import <SpringBoard/SBAwayController.h>
45 #import <SpringBoard/SBAwayWindow.h>
46 #import <SpringBoard/SpringBoard.h>
48 MSClassHook(SpringBoard)
49 MSClassHook(SBAwayController)
50 MSClassHook(SBAwayView)
53 NSLog(@"_trace(%s:%u)@%s %d", __FILE__, __LINE__, __FUNCTION__, active_)
55 static_cast<type>(~type())
58 static unsigned lock_;
60 static _H<NSArray> settings_;
61 static _H<NSArray> cydgets_;
62 static size_t active_;
64 @interface CydgetController : NSObject {
67 + (NSDictionary *) currentConfiguration;
71 @implementation CydgetController
73 + (NSDictionary *) currentConfiguration {
74 return [[cydgets_ objectAtIndex:active_] objectForKey:@"Configuration"];
79 @interface NSDictionary (Cydgets)
80 - (void) enableCydget:(SBAwayController *)away;
81 - (void) disableCydget:(SBAwayController *)away;
84 @implementation NSDictionary (Cydgets)
86 - (void) enableCydget:(SBAwayController *)away {
87 if (NSString *plugin = [self objectForKey:@"Plugin"])
88 [away enableLockScreenBundleWithName:plugin];
91 - (void) disableCydget:(SBAwayController *)away {
92 if (NSString *plugin = [self objectForKey:@"Plugin"])
93 [away disableLockScreenBundleWithName:plugin];
98 MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) {
101 if (!MSOldCall() && lock != 2) {
102 [[cydgets_ objectAtIndex:active_] disableCydget:self];
103 active_ = (active_ + 1) % [cydgets_ count];
104 [[cydgets_ objectAtIndex:active_] enableCydget:self];
110 MSInstanceMessageHook0(void, SBAwayController, _undimScreen) {
113 [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]];
117 MSInstanceMessageHook0(void, SBAwayController, undimScreen) {
118 lock_ = menu_ ? 1 : 0;
122 static void Deactivate_(SBAwayController *self) {
123 [[cydgets_ objectAtIndex:active_] disableCydget:self];
127 MSInstanceMessageHook0(void, SBAwayController, finishedDimmingScreen) {
132 MSInstanceMessageHook1(void, SpringBoard, menuButtonUp, GSEventRef, event) {
138 MSInstanceMessageHook1(void, SBAwayView, addGestureRecognizer, id, recognizer) {
139 // MSOldCall(recognizer);
142 #define Cydgets_ @"/System/Library/LockCydgets"
144 static void CydgetSetup() {
145 NSString *plist([NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Cydget.plist", NSHomeDirectory()]);
146 settings_ = [NSMutableDictionary dictionaryWithContentsOfFile:plist] ?: [NSMutableDictionary dictionary];
148 NSArray *cydgets([settings_ objectForKey:@"LockCydgets"] ?: [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
149 @"AwayView", @"Name", [NSNumber numberWithBool:YES], @"Active", nil
150 ], [NSDictionary dictionaryWithObjectsAndKeys:
151 @"CydgetCentral", @"Name", [NSNumber numberWithBool:YES], @"Active", nil
154 cydgets_ = [NSMutableArray arrayWithCapacity:4];
155 for (NSDictionary *cydget in cydgets)
156 if ([[cydget objectForKey:@"Active"] boolValue])
157 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.cydget/Info.plist", Cydgets_, [cydget objectForKey:@"Name"]]])
158 [cydgets_ addObject:info];
161 // XXX: this could happen while it is unlocked
162 MSInstanceMessageHook1(id, SBAwayView, initWithFrame, CGRect, frame) {
163 self = MSOldCall(frame);
165 [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]];
169 MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus, BOOL, status) {