Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
.theos
*.deb
Packages/
layout/

# Xcode
#
Expand All @@ -21,3 +23,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate

CarPlayActivator/carplaylauncher/theos

CarPlayActivator/carplaylauncher/libflipswitch.dylib
19 changes: 19 additions & 0 deletions CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CarPlayLauncherSwitch.h
// CarPlayLauncher
//
// Created by Pigi Galdi on 08.12.2014.
// Copyright (c) 2014 Pigi Galdi. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "FSSwitchDataSource.h"
#import "FSSwitchPanel.h"

#import "../PrivateHeaders.h"

@interface CarPlayLauncherSwitch : NSObject <FSSwitchDataSource>

@end
63 changes: 63 additions & 0 deletions CarPlayActivator/carplaylauncher/CarPlayLauncherSwitch.x
Original file line number Diff line number Diff line change
@@ -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
91 changes: 91 additions & 0 deletions CarPlayActivator/carplaylauncher/FSSwitchDataSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "FSSwitchState.h"

@protocol FSSwitchDataSource <NSObject>

@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
106 changes: 106 additions & 0 deletions CarPlayActivator/carplaylauncher/FSSwitchPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#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<FSSwitchDataSource>)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;
11 changes: 11 additions & 0 deletions CarPlayActivator/carplaylauncher/FSSwitchState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>

typedef enum {
FSSwitchStateOff = 0,
FSSwitchStateOn = 1,
FSSwitchStateIndeterminate = -1
} FSSwitchState;

FOUNDATION_EXTERN NSString *NSStringFromFSSwitchState(FSSwitchState state);

FOUNDATION_EXTERN FSSwitchState FSSwitchStateFromNSString(NSString *stateString);
23 changes: 23 additions & 0 deletions CarPlayActivator/carplaylauncher/Makefile
Original file line number Diff line number Diff line change
@@ -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"
32 changes: 32 additions & 0 deletions CarPlayActivator/carplaylauncher/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>CarPlayLauncher</string>
<key>CFBundleIdentifier</key>
<string>com.pigigaldi.carplaylauncher</string>
<key>CFBundleDisplayName</key>
<string>CarPlayLauncher</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>DTPlatformName</key>
<string>iphoneos</string>
<key>MinimumOSVersion</key>
<string>8.1</string>
<key>NSPrincipalClass</key>
<string>CarPlayLauncherSwitch</string>
<key>alternate-action-url</key>
<string>prefs:</string>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions CarPlayActivator/carplaylauncher/control
Original file line number Diff line number Diff line change
@@ -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)