-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.mm
150 lines (122 loc) · 4.43 KB
/
Tweak.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// Tweak.mm
// Contains all hooks into Apple's code which handles showing the Apple internal settings.
//
// Created by Joshua Seltzer on 12/15/14.
//
//
#import "AppleInterfaces.h"
#import <UIKit/UIKit.h>
// macros to determine which system software this device is running
#define SYSTEM_VERSION_IOS9 [[[%c(UIDevice) currentDevice] systemVersion] floatValue] >= 9.0
// define the path to the preferences plist
#define SETTINGS_PATH [NSHomeDirectory() stringByAppendingPathComponent:kJSSettingsPath]
// define the constant for the application bundle ID that we need to check for
static NSString *const kJSAppBundleId = @"com.apple.Preferences";
// constant that defines the string that points to our preference plist
static NSString *const kJSSettingsPath = @"/Library/Preferences/com.joshuaseltzer.advancedsettings8prefs.plist";
// flag that determines if we have presented the advanced settings
static BOOL sJSPresentedSettings = NO;
// check the preferences file to see if the tweak itself is enabled or disabled
BOOL isEnabled()
{
// attempt to get the preferences from the plist
NSDictionary *prefs = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_PATH];
// See if it we have preferences and if it is enabled. By default it is enabled
BOOL isEnabled = YES;
if (prefs) {
isEnabled = [[prefs objectForKey:@"enabled"] boolValue];
}
return isEnabled;
}
// the iOS8 specific hooks
%group iOS8
// hook to see when we long press on an icon
%hook SBIconView
// invoked when the long press timer on a Springboard icon is fired
- (void)longPressTimerFired
{
// Check to see if the application bundle ID is equal to the settings app. Disallow the settings
// to display if we are already in edit mode
if (!self.isEditing && isEnabled() && [[self.icon applicationBundleID] isEqualToString:kJSAppBundleId]) {
// set our presentation flag to YES
sJSPresentedSettings = YES;
// show the advanced settings
[[%c(SBPrototypeController) sharedInstance] _showSettings];
} else {
// perform the original implementation for any other app icon
%orig;
}
}
%end
// hook to see when we tap on an icon
%hook SBApplicationIcon
// launches an application
- (void)launchFromLocation:(int)location
{
// check to see if the application bundle ID is equal to the settings app
if (isEnabled() && [[self applicationBundleID] isEqualToString:kJSAppBundleId]) {
if (sJSPresentedSettings) {
// if we have presented the advanced settings, then reset the flag
sJSPresentedSettings = NO;
} else {
// otherwise, launch the settings app
%orig;
}
} else {
// perform the original implementation for any other app icon
%orig;
}
}
%end
%end
// the iOS9 specific hooks
%group iOS9
// hook to see when we long press on an icon
%hook SBIconView
// fired when the first half long press is invoked
- (void)_handleSecondHalfLongPressTimer:(id)arg1
{
// Check to see if the application bundle ID is equal to the settings app. Disallow the settings
// to display if we are already in edit mode
if (!self.isEditing && isEnabled() && [[self.icon applicationBundleID] isEqualToString:kJSAppBundleId]) {
// set our presentation flag to YES
sJSPresentedSettings = YES;
// show the advanced settings
[[%c(SBPrototypeController) sharedInstance] _showSettings];
} else {
// perform the original implementation for any other app icon
%orig;
}
}
%end
// hook to see when we tap on an icon
%hook SBApplicationIcon
// launches an application
- (void)launchFromLocation:(int)arg1 context:(id)arg2
{
// check to see if the application bundle ID is equal to the settings app
if (isEnabled() && [[self applicationBundleID] isEqualToString:kJSAppBundleId]) {
if (sJSPresentedSettings) {
// if we have presented the advanced settings, then reset the flag
sJSPresentedSettings = NO;
} else {
// otherwise, launch the settings app
%orig;
}
} else {
// perform the original implementation for any other app icon
%orig;
}
}
%end
%end
// constructor which will decide which hooks to include depending which system software the device
// is running
%ctor {
if (SYSTEM_VERSION_IOS9) {
%init(iOS9);
} else {
%init(iOS8);
}
}