Skip to content

Commit

Permalink
Allow prompting to unlock the device when dispatching an alternate ac…
Browse files Browse the repository at this point in the history
…tion on iOS 7
  • Loading branch information
rpetrich committed Jan 26, 2014
1 parent 120115e commit 73ac30b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
4 changes: 4 additions & 0 deletions FSLaunchURL.h
@@ -0,0 +1,4 @@
#import <Foundation/Foundation.h>

__attribute__((visibility("hidden")))
void FSLaunchURL(NSURL *url);
71 changes: 71 additions & 0 deletions FSLaunchURL.x
@@ -0,0 +1,71 @@
#import "FSLaunchURL.h"

#import <UIKit/UIKit.h>

@interface UIApplication (Private)
- (void)applicationOpenURL:(NSURL *)url;
- (void)applicationOpenURL:(NSURL *)url publicURLsOnly:(BOOL)publicURLsOnly;
@end

@interface SBLockScreenManager : NSObject
+ (SBLockScreenManager *)sharedInstance;
@property (nonatomic, readonly) BOOL isUILocked;
- (void)applicationRequestedDeviceUnlock;
- (void)cancelApplicationRequestedDeviceLockEntry;
@end

@interface SBDeviceLockController : NSObject
+ (SBDeviceLockController *)sharedController;
- (BOOL)isPasscodeLocked;
@end

static NSURL *pendingURL;

static void FSLaunchURLDirect(NSURL *url)
{
UIApplication *app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(applicationOpenURL:publicURLsOnly:)])
[app applicationOpenURL:url publicURLsOnly:NO];
else
[app applicationOpenURL:url];
}

%hook SBLockScreenManager

- (void)_sendUILockStateChangedNotification
{
%orig();
NSURL *url = pendingURL;
if (url) {
pendingURL = nil;
if (!self.isUILocked)
FSLaunchURLDirect(url);
[url release];
}
}

- (void)cancelApplicationRequestedDeviceLockEntry
{
[pendingURL release];
pendingURL = nil;
%orig();
}

%end

void FSLaunchURL(NSURL *url)
{
if (!url)
return;
if ([%c(SBDeviceLockController) sharedController].isPasscodeLocked) {
SBLockScreenManager *manager = (SBLockScreenManager *)[%c(SBLockScreenManager) sharedInstance];
if (manager.isUILocked) {
url = [url retain];
[pendingURL release];
pendingURL = url;
[manager applicationRequestedDeviceUnlock];
return;
}
}
FSLaunchURLDirect(url);
}
12 changes: 2 additions & 10 deletions FSSwitchMainPanel.m
Expand Up @@ -5,6 +5,7 @@
#import "FSPreferenceSwitchDataSource.h"
#import "FSLazySwitch.h"
#import "FSCapability.h"
#import "FSLaunchURL.h"

#define ROCKETBOOTSTRAP_LOAD_DYNAMIC
#import "LightMessaging/LightMessaging.h"
Expand All @@ -16,11 +17,6 @@

#define kSwitchesPath @"/Library/Switches/"

@interface UIApplication (Private)
- (void)applicationOpenURL:(NSURL *)url;
- (void)applicationOpenURL:(NSURL *)url publicURLsOnly:(BOOL)publicURLsOnly;
@end

static volatile int32_t stateChangeCount;

@implementation FSSwitchMainPanel
Expand Down Expand Up @@ -204,11 +200,7 @@ - (void)openURLAsAlternateAction:(NSURL *)url
}
NSDictionary *userInfo = url ? [NSDictionary dictionaryWithObject:[url absoluteString] forKey:@"url"] : nil;
[self postNotificationName:FSSwitchPanelSwitchWillOpenURLNotification userInfo:userInfo];
UIApplication *app = [UIApplication sharedApplication];
if ([app respondsToSelector:@selector(applicationOpenURL:publicURLsOnly:)])
[app applicationOpenURL:url publicURLsOnly:NO];
else
[app applicationOpenURL:url];
FSLaunchURL(url);
}

- (BOOL)switchWithIdentifierIsEnabled:(NSString *)switchIdentifier
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -4,7 +4,7 @@ libflipswitch_FILES = FSSwitchPanel.m NSBundle+Flipswitch.m FSSwitchButton.m FSS
libflipswitch_FRAMEWORKS = UIKit CoreGraphics
libflipswitch_ARCHS = armv6 armv7 armv7s arm64

libFlipswitchSpringBoard_FILES = FSSwitchMainPanel.m FSSwitchDataSource.m FSSwitchMainPanel.m FSPreferenceSwitchDataSource.m FSLazySwitch.m FSCapability.m
libFlipswitchSpringBoard_FILES = FSSwitchMainPanel.m FSSwitchDataSource.m FSSwitchMainPanel.m FSPreferenceSwitchDataSource.m FSLazySwitch.m FSCapability.m FSLaunchURL.x
libFlipswitchSpringBoard_LIBRARIES = flipswitch
libFlipswitchSpringBoard_FRAMEWORKS = UIKit
libFlipswitchSpringBoard_PRIVATE_FRAMEWORKS = GraphicsServices
Expand Down

0 comments on commit 73ac30b

Please sign in to comment.