diff --git a/.gitignore b/.gitignore index 882fb2f..0681d84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ # .theos *.deb +Packages/ +layout/ # Xcode # @@ -21,3 +23,7 @@ DerivedData *.hmap *.ipa *.xcuserstate + +CarPlayActivator/carplaylauncher/theos + +CarPlayActivator/carplaylauncher/libflipswitch.dylib diff --git a/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.h b/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.h new file mode 100755 index 0000000..ab73bd2 --- /dev/null +++ b/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.h @@ -0,0 +1,19 @@ +// +// CarPlayLauncherSwitch.h +// CarPlayLauncher +// +// Created by Pigi Galdi on 08.12.2014. +// Copyright (c) 2014 Pigi Galdi. All rights reserved. +// + +#import +#import + +#import "FSSwitchDataSource.h" +#import "FSSwitchPanel.h" + +#import "../PrivateHeaders.h" + +@interface CarPlayLauncherSwitch : NSObject + +@end \ No newline at end of file diff --git a/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.x b/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.x new file mode 100755 index 0000000..e19d860 --- /dev/null +++ b/CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.x @@ -0,0 +1,63 @@ +// +// CarPlayLauncherSwitch.x +// CarPlayLauncher +// +// Created by Pigi Galdi on 08.12.2014. +// Copyright (c) 2014 Pigi Galdi. All rights reserved. +// + +#import "CarPlayLauncherSwitch.h" + +static BOOL _isCarPlayActive (void) { + // Check if file exist at path. + NSFileManager *fileManager = [NSFileManager defaultManager]; + if ([fileManager fileExistsAtPath:CARPLAY_ACTIVE_FILE_PATH]) + return YES; + else + return NO; +} + +static void _removeFile (void) { + // Disable CarPlay removing file. + NSFileManager *fileManager = [NSFileManager defaultManager]; + [fileManager removeItemAtPath:CARPLAY_ACTIVE_FILE_PATH error:nil]; +} + +static void _createFile (void) { + // Enable CarPlay creating file. + NSFileManager *fileManager = [NSFileManager defaultManager]; + [fileManager createFileAtPath:CARPLAY_ACTIVE_FILE_PATH contents:[@"canhaz?" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil]; +} + +static void _killallBackboardd (void) { + // Kill backboardd to get changes. + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3.f * NSEC_PER_SEC), dispatch_get_main_queue(),^{ + system("killall -9 backboardd"); + }); +} + +@implementation CarPlayLauncherSwitch + +- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier { + return _isCarPlayActive() ? FSSwitchStateOn : FSSwitchStateOff; +} + +- (void)applyState:(FSSwitchState)newState forSwitchIdentifier:(NSString *)switchIdentifier +{ + switch (newState) { + case FSSwitchStateIndeterminate: + return; + case FSSwitchStateOn: + // Remove file. + _createFile(); + _killallBackboardd(); + break; + case FSSwitchStateOff: + // Create file. + _removeFile(); + _killallBackboardd(); + break; + } +} + +@end \ No newline at end of file diff --git a/CarPlayActivator/carplaylauncher/FSSwitchDataSource.h b/CarPlayActivator/carplaylauncher/FSSwitchDataSource.h new file mode 100755 index 0000000..775d45d --- /dev/null +++ b/CarPlayActivator/carplaylauncher/FSSwitchDataSource.h @@ -0,0 +1,91 @@ +#import +#import + +#import "FSSwitchState.h" + +@protocol FSSwitchDataSource + +@optional + +/** + Gets the current state of the switch. + Must override if building a settings-like switch. + Return FSSwitchStateIndeterminate if switch is loading. + By default returns FSSwitchStateIndeterminate. + */ +- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Sets the new state of the switch. + Must override if building a settings-like switch. + By default calls through to applyActionForSwitchIdentifier: If newState is different from the current state. + */ +- (void)applyState:(FSSwitchState)newState forSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Runs the default action for the switch. + Must override if building an action-like switch. + By default calls through to applyState:forSwitchIdentifier: if state is not indeterminate. + */ +- (void)applyActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Returns the localized title for the switch. + By default reads the CFBundleDisplayName out of the switch's bundle. + */ +- (NSString *)titleForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Returns wether the switch should be shown. + By default returns YES or the value from GraphicsServices for the capability specified in the "required-capability-key" of the switch's bundle. + E.g. You would detect if the device has the required capability (3G, flash etc). + */ +- (BOOL)shouldShowSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Provide an image descriptor that best displays at the requested size and scale. + By default looks through the bundle to find a glyph image. + */ +- (id)glyphImageDescriptorOfState:(FSSwitchState)switchState size:(CGFloat)size scale:(CGFloat)scale forSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Provides a bundle to look for localizations/images in. + By default returns the bundle for the current class. + */ + +- (NSBundle *)bundleForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Called when switch is first registered. + */ +- (void)switchWasRegisteredForIdentifier:(NSString *)switchIdentifier; + + +/** + Called when switch is unregistered. + */ +- (void)switchWasUnregisteredForIdentifier:(NSString *)switchIdentifier; + + +/** + Gets whether the switch supports an alternate or "hold" action. + By default queries if switch responds to applyAlternateActionForSwitchIdentifier: or if it has a "alternate-action-url" key set. + */ +- (BOOL)hasAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Applies the alternate or "hold" action. + By default launches the URL stored in the "alternate-action-url" key of the switch's bundle. + */ +- (void)applyAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +@end \ No newline at end of file diff --git a/CarPlayActivator/carplaylauncher/FSSwitchPanel.h b/CarPlayActivator/carplaylauncher/FSSwitchPanel.h new file mode 100755 index 0000000..2fabb8a --- /dev/null +++ b/CarPlayActivator/carplaylauncher/FSSwitchPanel.h @@ -0,0 +1,106 @@ +#import +#import + +#import "FSSwitchState.h" + +@interface FSSwitchPanel : NSObject + ++ (FSSwitchPanel *)sharedPanel; + +/** + Returns a list of identifying all switches installed on the device. + */ +@property (nonatomic, readonly, copy) NSArray *switchIdentifiers; + + +/** + Returns the localized title for a specific switch. + */ +- (NSString *)titleForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Returns a UIButton for a specific switch. + The button automatically updates its style based on the user interaction and switch state changes, applies the standard action when pressed, and applies the alternate action when held. + */ +- (UIButton *)buttonForSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle; + +- (UIImage *)imageOfSwitchState:(FSSwitchState)state controlState:(UIControlState)controlState forSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle; + + +/** + Returns an image representing how a specific switch would look in a particular state when styled with the provided template. + */ +- (UIImage *)imageOfSwitchState:(FSSwitchState)state controlState:(UIControlState)controlState scale:(CGFloat)scale forSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle; + + +/** + Returns the raw glyph identifier as retrieved from the backing FSSwitch instance. + */ +- (id)glyphImageDescriptorOfState:(FSSwitchState)switchState size:(CGFloat)size scale:(CGFloat)scale forSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Returns the current state of a particualr switch. + */ +- (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Updates the state of a particular switch. If the switch accepts the change it will send a state change. + */ +- (void)setState:(FSSwitchState)state forSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Applies the default action of a particular switch. + */ +- (void)applyActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Queries whether a switch supports an alternate action. This is often triggered by a hold gesture. + */ +- (BOOL)hasAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Apply the alternate action of a particular switch. + */ +- (void)applyAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier; + + +/** + Helper method to open a particular URL as if it were launched from an alternate action. + */ +- (void)openURLAsAlternateAction:(NSURL *)url; + +@end + +@protocol FSSwitchDataSource; + +@interface FSSwitchPanel (SpringBoard) + +/** + Registers a switch implementation for a specific identifier. Bundlee in /Library/Switches will have their principal class automatically loaded. + */ +- (void)registerDataSource:(id)dataSource forSwitchIdentifier:(NSString *)switchIdentifier; + +/** + Unregisters a switch. + */ +- (void)unregisterSwitchIdentifier:(NSString *)switchIdentifier; + +/** + Informs the system when a switch changes its state. This will trigger any switch buttons to update their style. + */ +- (void)stateDidChangeForSwitchIdentifier:(NSString *)switchIdentifier; + +@end + +FOUNDATION_EXTERN NSString * const FSSwitchPanelSwitchesChangedNotification; + +FOUNDATION_EXTERN NSString * const FSSwitchPanelSwitchStateChangedNotification; +FOUNDATION_EXTERN NSString * const FSSwitchPanelSwitchIdentifierKey; + +FOUNDATION_EXTERN NSString * const FSSwitchPanelSwitchWillOpenURLNotification; diff --git a/CarPlayActivator/carplaylauncher/FSSwitchState.h b/CarPlayActivator/carplaylauncher/FSSwitchState.h new file mode 100755 index 0000000..a994ea7 --- /dev/null +++ b/CarPlayActivator/carplaylauncher/FSSwitchState.h @@ -0,0 +1,11 @@ +#import + +typedef enum { + FSSwitchStateOff = 0, + FSSwitchStateOn = 1, + FSSwitchStateIndeterminate = -1 +} FSSwitchState; + +FOUNDATION_EXTERN NSString *NSStringFromFSSwitchState(FSSwitchState state); + +FOUNDATION_EXTERN FSSwitchState FSSwitchStateFromNSString(NSString *stateString); diff --git a/CarPlayActivator/carplaylauncher/Makefile b/CarPlayActivator/carplaylauncher/Makefile new file mode 100755 index 0000000..b74b966 --- /dev/null +++ b/CarPlayActivator/carplaylauncher/Makefile @@ -0,0 +1,23 @@ +THEOS_DEVICE_IP = 192.168.0.14 +THEOS_DEVICE_PORT = 22 +GO_EASY_ON_ME = 1 + +ARCHS = armv7 armv7s arm64 + +TARGET = iphone:clang:latest:8.1 + +THEOS_BUILD_DIR = Packages + +include theos/makefiles/common.mk + +BUNDLE_NAME = CarPlayLauncher +CarPlayLauncher_CFLAGS = -fobjc-arc +CarPlayLauncher_FILES = CarPlayLauncherSwitch.x +CarPlayLauncher_FRAMEWORKS = Foundation UIKit +CarPlayLauncher_LDFLAGS = -weak_library libflipswitch.dylib +CarPlayLauncher_INSTALL_PATH = /Library/Switches + +include $(THEOS_MAKE_PATH)/bundle.mk + +after-install:: + install.exec "rm -rf /tmp/FlipswitchCache; killall -9 backboardd" diff --git a/CarPlayActivator/carplaylauncher/Resources/Info.plist b/CarPlayActivator/carplaylauncher/Resources/Info.plist new file mode 100755 index 0000000..e50f0b7 --- /dev/null +++ b/CarPlayActivator/carplaylauncher/Resources/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + CarPlayLauncher + CFBundleIdentifier + com.pigigaldi.carplaylauncher + CFBundleDisplayName + CarPlayLauncher + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + DTPlatformName + iphoneos + MinimumOSVersion + 8.1 + NSPrincipalClass + CarPlayLauncherSwitch + alternate-action-url + prefs: + + diff --git a/CarPlayActivator/carplaylauncher/Resources/glyph-off.pdf b/CarPlayActivator/carplaylauncher/Resources/glyph-off.pdf new file mode 100755 index 0000000..68ef544 Binary files /dev/null and b/CarPlayActivator/carplaylauncher/Resources/glyph-off.pdf differ diff --git a/CarPlayActivator/carplaylauncher/Resources/glyph.pdf b/CarPlayActivator/carplaylauncher/Resources/glyph.pdf new file mode 100755 index 0000000..99c1f8c Binary files /dev/null and b/CarPlayActivator/carplaylauncher/Resources/glyph.pdf differ diff --git a/CarPlayActivator/carplaylauncher/control b/CarPlayActivator/carplaylauncher/control new file mode 100755 index 0000000..ad4ffcc --- /dev/null +++ b/CarPlayActivator/carplaylauncher/control @@ -0,0 +1,8 @@ +Package: com.pigigaldi.carplaylauncher +Name: CarPlayLauncher +Depends: mobilesubstrate, com.a3tweaks.flipswitch, firmware (>= 8.1) +Version: 0.0.1 +Architecture: iphoneos-arm +Description: (FlipSwitch) Enable/Disable CarPlay Activator (by Adam Bell). +Author: Pigi Galdi +Section: Addons (Flipswitch) \ No newline at end of file