-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIconRestore.x
169 lines (142 loc) · 4.55 KB
/
IconRestore.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#import <UIKit/UIKit.h>
#import <HBLog.h>
#import <notify.h>
@protocol SBIconModelStore
@end
@interface SBIconModelPropertyListFileStore : NSObject <SBIconModelStore>
@property (nonatomic, assign) BOOL ir_disableSave;
@end
@interface SBIconModelMemoryStore : NSObject <SBIconModelStore>
- (void)setDesiredState:(NSDictionary *)arg1;
@end
@interface SBIconModelReadOnlyMemoryStore : SBIconModelMemoryStore <SBIconModelStore>
@end
@interface SBHIconModel : NSObject
@property (nonatomic, strong) NSTimer *autosaveTimer;
@property (nonatomic, strong, readonly) id<SBIconModelStore> store;
- (void)importIconState:(NSDictionary *)arg1;
- (void)importDesiredIconState:(NSDictionary *)arg1;
- (void)markIconStateDirty;
- (void)markIconStateClean;
- (void)reloadIcons;
- (void)layout;
- (void)clearDesiredIconState;
- (void)_saveIconState;
- (BOOL)_saveIconState:(NSDictionary *)arg1 error:(NSError * __autoreleasing *)arg2;
- (void)autosaveTimerDidFire:(id)arg1;
@end
@interface SBHIconModel (IconRestore)
@property (nonatomic, assign) BOOL ir_disableSave;
@end
static NSMutableArray<SBHIconModel *> *_globalIconModels = nil;
static NSMutableArray<SBIconModelPropertyListFileStore *> *_globalFileStores = nil;
%group IconRestoreSpringBoard
%hook SBHIconModel
%property (nonatomic, assign) BOOL ir_disableSave;
- (id)initWithStore:(id)arg1 {
SBHIconModel *iconModel = %orig;
if (iconModel) {
iconModel.ir_disableSave = NO;
[_globalIconModels addObject:iconModel];
}
return iconModel;
}
// iOS 15
- (id)initWithStore:(id)arg1 applicationDataSource:(id)arg2 {
SBHIconModel *iconModel = %orig;
if (iconModel) {
iconModel.ir_disableSave = NO;
[_globalIconModels addObject:iconModel];
}
return iconModel;
}
- (void)_saveIconState {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return;
}
%orig;
}
// iOS 14.4+
- (BOOL)_saveIconStateWithError:(NSError * __autoreleasing *)arg1 {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return YES;
}
return %orig;
}
// iOS 15.2+
- (BOOL)_saveIconState:(NSDictionary *)arg1 error:(NSError * __autoreleasing *)arg2 {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return YES;
}
return %orig;
}
- (void)autosaveTimerDidFire:(id)arg1 {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return;
}
%orig;
}
%end
%hook SBIconModelPropertyListFileStore
%property (nonatomic, assign) BOOL ir_disableSave;
- (id)init {
SBIconModelPropertyListFileStore *fileStore = %orig;
if (fileStore) {
fileStore.ir_disableSave = NO;
[_globalFileStores addObject:fileStore];
}
return fileStore;
}
- (id)initWithIconStateURL:(id)arg1 desiredIconStateURL:(id)arg2 {
SBIconModelPropertyListFileStore *fileStore = %orig;
if (fileStore) {
fileStore.ir_disableSave = NO;
[_globalFileStores addObject:fileStore];
}
return fileStore;
}
- (BOOL)saveCurrentIconState:(id)arg1 error:(id*)arg2 {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return YES;
}
return %orig;
}
- (BOOL)_save:(id)arg1 url:(id)arg2 error:(id*)arg3 {
if (self.ir_disableSave) {
HBLogDebug(@"Skip saving icon layout");
return YES;
}
return %orig;
}
%end
%end
%ctor {
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
if ([bundleIdentifier isEqualToString:@"com.apple.springboard"]) {
%init(IconRestoreSpringBoard);
int triggerToken = 0;
notify_register_dispatch("com.82flex.iconrestoreprefs/save-layout", &triggerToken, dispatch_get_main_queue(), ^(int token) {
for (SBHIconModel *iconModel in _globalIconModels) {
if ([iconModel respondsToSelector:@selector(autosaveTimerDidFire:)]) {
[iconModel autosaveTimerDidFire:iconModel.autosaveTimer];
HBLogDebug(@"Force saving icon layout");
}
}
});
int forbiddenToken = 0;
notify_register_dispatch("com.82flex.iconrestoreprefs/will-respring", &forbiddenToken, dispatch_get_main_queue(), ^(int token) {
for (SBHIconModel *iconModel in _globalIconModels) {
iconModel.ir_disableSave = YES;
}
for (SBIconModelPropertyListFileStore *fileStore in _globalFileStores) {
fileStore.ir_disableSave = YES;
}
HBLogDebug(@"Disable saving icon layout");
});
}
}