-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTweak.x
57 lines (43 loc) · 1.19 KB
/
Tweak.x
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
// iOS 9 - 11
@interface BCBatteryDevice : NSObject <NSCopying, NSCoding>
- (NSString *)matchIdentifier;
- (long long)percentCharge;
@end
// iOS 9 - 11
@interface BCBatteryDeviceController : NSObject
+ (instancetype)sharedInstance;
- (NSArray<BCBatteryDevice *> *)connectedDevices;
@end
// iOS 5 - 11
@interface BluetoothDevice : NSObject
- (NSString *)address;
- (int)batteryLevel;
@end
// iOS 3 - 11
@interface SBBluetoothController : NSObject
+ (instancetype)sharedInstance;
- (void)updateBattery;
@end
%hook BluetoothDevice
- (int)batteryLevel {
NSString *thisAddress = self.address;
for (BCBatteryDevice *targ in BCBatteryDeviceController.sharedInstance.connectedDevices) {
if ([targ.matchIdentifier isEqualToString:thisAddress]) {
return targ.percentCharge;
}
}
return %orig;
}
- (BOOL)supportsBatteryLevel {
return (self.batteryLevel != -1);
}
%end
%hook BCBatteryDevice
- (void)setPercentCharge:(long long)charge {
%orig;
dispatch_async(dispatch_get_main_queue(), ^{
SBBluetoothController *bluetoothController = [objc_getClass("SBBluetoothController") sharedInstance];
[bluetoothController updateBattery];
});
}
%end