/
Tweak.xm
108 lines (85 loc) · 3.46 KB
/
Tweak.xm
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
//
// Tweak.xm
// Springshot
//
// Created by Adam Bell on 2013-12-31.
// Copyright (c) 2014 Adam Bell. All rights reserved.
//
%config(generator=MobileSubstrate);
#import "springshot.h"
#define PREFERENCES_PATH @"/User/Library/Preferences/ca.adambell.springshot.plist"
#define PREFERENCES_CHANGED_NOTIFICATION "ca.adambell.springshot.preferences-changed"
#define PREFERENCES_ENABLED_KEY @"springshotEnabled"
static BOOL _switcherVisible = NO;
static BOOL _springshotEnabled = NO;
%hook SBAppSliderController
- (void)switcherWillBeDismissed:(BOOL)arg1 {
_switcherVisible = NO;
%orig;
}
- (void)switcherWasPresented:(BOOL)arg1 {
_switcherVisible = YES;
%orig;
}
%end
%hook SBAppSliderScrollingViewController
static NSMutableArray *itemsToRemove;
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(CGPoint *)targetContentOffset {
%orig;
if (_switcherVisible && _springshotEnabled) {
NSUInteger itemIndex = [[self valueForKey:@"_items"] indexOfObject:scrollView];
BOOL isRemovable = [self.delegate sliderScroller:scrollView isIndexRemovable:itemIndex];
if (scrollView.contentOffset.y < -40.0 && isRemovable) {
[itemsToRemove addObject:scrollView];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (_springshotEnabled && _switcherVisible) {
if ([itemsToRemove containsObject:scrollView]) {
__weak SBAppSliderController *scrollerDelegate = self.delegate;
__weak SBAppSliderScrollingViewController *weakSelf = self;
__weak UIScrollView *weakScrollView = scrollView;
NSUInteger itemIndex = [[self valueForKey:@"_items"] indexOfObject:scrollView];
[UIView animateWithDuration:0.4
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^(){
weakScrollView.contentOffset = CGPointMake(0.0, scrollView.contentSize.height / 2.0);
}
completion:^(BOOL finished){
[itemsToRemove removeObject:scrollView];
[scrollerDelegate sliderScroller:weakSelf itemWantsToBeRemoved:itemIndex];
}];
DebugLog(@"SpringBoard: WEEEEEEEEEEEEEEEEEEEEEEE!!!!!!");
}
else {
%orig;
}
}
else {
%orig;
}
}
- (void)switcherWasDismissed:(id)switcher {
[itemsToRemove removeAllObjects];
%orig;
}
%end
static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSDictionary *preferences = [[NSDictionary alloc] initWithContentsOfFile:PREFERENCES_PATH];
_springshotEnabled = [preferences[PREFERENCES_ENABLED_KEY] boolValue];
}
%ctor {
itemsToRemove = [[NSMutableArray alloc] init];
NSDictionary *preferences = [[NSDictionary alloc] initWithContentsOfFile:PREFERENCES_PATH];
if (preferences == nil) {
preferences = @{ PREFERENCES_ENABLED_KEY : @(YES) };
[preferences writeToFile:PREFERENCES_PATH atomically:YES];
_springshotEnabled = YES;
}
else {
_springshotEnabled = [preferences[PREFERENCES_ENABLED_KEY] boolValue];
}
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, PreferencesChangedCallback, CFSTR(PREFERENCES_CHANGED_NOTIFICATION), NULL, CFNotificationSuspensionBehaviorCoalesce);
}