-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTweak.xm
129 lines (98 loc) · 3.49 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "SWWidgetContainerView.h"
#import <Preferences/PSListController.h>
#import <Preferences/PSSpecifier.h>
#import "CoreTelephonyClient.h"
@interface CTDeviceDataUsage : NSObject
- (id)totalDataUsageForPeriod:(unsigned long long)arg1;
- (id)totalDataUsedForPeriod:(unsigned long long)arg1;
@end
extern "C"
int __isOSVersionAtLeast(int major, int minor, int patch) {
NSOperatingSystemVersion version;
version.majorVersion = major;
version.minorVersion = minor;
version.patchVersion = patch;
return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version];
}
#define MIN_WIDGET_HEIGHT 100
@interface UITraitCollection (iOS13)
+(UITraitCollection *)currentTraitCollection;
@end
static BOOL boolForKey(NSDictionary *dict, NSString *key, BOOL fallBack) {
id result = [dict objectForKey:key];
if (!result) {
return fallBack;
}
return [result boolValue];
}
static SWWidgetType widgetTypeForKey(NSDictionary *dict, NSString *key, SWWidgetType fallBack) {
id result = [dict objectForKey:key];
if (!result) {
return fallBack;
}
return (SWWidgetType)[result integerValue];
}
static int intForKey(NSDictionary *dict, NSString *key, long long fallBack) {
id result = [dict objectForKey:key];
if (!result) {
return fallBack;
}
return [result intValue];
}
static BOOL enabled;
static BOOL transparentMode;
static BOOL widget2Enabled;
static int widgetCornerRadius;
static int widgetHeight;
static int widgetInset;
static SWWidgetType widgetType1;
static SWWidgetType widgetType2;
static void loadPrefs() {
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.shepgoba.swprefs"];
NSDictionary *settings = defaults.dictionaryRepresentation;
enabled = boolForKey(settings, @"enabled", YES);
transparentMode = boolForKey(settings, @"transparentMode", NO);
widgetType1 = widgetTypeForKey(settings, @"widgetType1", SWWidgetTypeBattery);
widgetType2 = widgetTypeForKey(settings, @"widgetType2", SWWidgetTypeStorage);
widgetHeight = intForKey(settings, @"widgetHeight", 120);
widgetInset = intForKey(settings, @"widgetInset", 15);
widget2Enabled = boolForKey(settings, @"widget2Enabled", YES);
widgetCornerRadius = intForKey(settings, @"widgetCornerRadius", 16);
}
@interface PSUIPrefsListController : PSListController
@property (nonatomic, retain) SWWidgetContainerView *widgetContainerView;
- (id)specifierForID;
@end
%group Tweak
%hook PSUIPrefsListController
%property (nonatomic, retain) SWWidgetContainerView *widgetContainerView;
-(void)viewWillAppear:(BOOL)arg1 {
%orig;
UITableView *tblView = self.table;
self.widgetContainerView.frame = CGRectMake(0, 0, tblView.frame.size.width, widgetHeight < MIN_WIDGET_HEIGHT ? MIN_WIDGET_HEIGHT : widgetHeight);
}
-(void)viewDidLoad {
%orig;
UITableView *tblView = self.table;
self.widgetContainerView = [[SWWidgetContainerView alloc] init];
self.widgetContainerView.backgroundColor = UIColor.clearColor;
tblView.tableHeaderView = self.widgetContainerView;
if (!widget2Enabled)
widgetType2 = SWWidgetTypeNone;
[self.widgetContainerView setupWidgetsWithType1:widgetType1 type2:widgetType2 transparentBackground:transparentMode widgetInset:widgetInset cornerRadius:widgetCornerRadius];
[self.widgetContainerView setWidgetBackgrounds];
}
-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
%orig;
[self.widgetContainerView setWidgetBackgrounds];
}
%end
%end
%ctor {
NSLog(@"SettingsWidgets loaded");
loadPrefs();
if (enabled)
%init(Tweak);
}