-
Notifications
You must be signed in to change notification settings - Fork 5
/
SingleMute.x
174 lines (132 loc) · 4.54 KB
/
SingleMute.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
170
171
172
173
174
@import UIKit;
#import <HBLog.h>
@interface SBRingerControl : NSObject
- (BOOL)isRingerMuted;
@end
@interface _UIStatusBarDataQuietModeEntry : NSObject
@property(nonatomic, copy) NSString *focusName;
@end
@interface _UIStatusBarData : NSObject
@property(nonatomic, copy) _UIStatusBarDataQuietModeEntry *quietModeEntry;
@end
@interface _UIStatusBarItemUpdate : NSObject
@property(nonatomic, strong) _UIStatusBarData *data;
@end
@interface UIStatusBarServer : NSObject
+ (const unsigned char *)getStatusBarData;
@end
@interface UIStatusBar_Base : UIView
@property(nonatomic, strong) UIStatusBarServer *statusBarServer;
- (void)reloadSingleMute;
- (void)forceUpdateData:(BOOL)arg1;
- (void)statusBarServer:(id)arg1 didReceiveStatusBarData:(const unsigned char *)arg2 withActions:(int)arg3;
@end
@interface UIStatusBar_Modern : UIStatusBar_Base
@end
@interface SMWeakContainer : NSObject
@property(nonatomic, weak) id object;
@end
@implementation SMWeakContainer
@end
static BOOL kIsEnabled = YES;
static BOOL kUseLowPriorityLocation = NO;
static void ReloadPrefs() {
static NSUserDefaults *prefs = nil;
if (!prefs) {
prefs = [[NSUserDefaults alloc] initWithSuiteName:@"com.82flex.singlemuteprefs"];
}
NSDictionary *settings = [prefs dictionaryRepresentation];
kIsEnabled = settings[@"IsEnabled"] ? [settings[@"IsEnabled"] boolValue] : YES;
kUseLowPriorityLocation = settings[@"LowerPriorityForLocationIcon"] ? [settings[@"LowerPriorityForLocationIcon"] boolValue] : NO;
}
static SBRingerControl *_ringerControl = nil;
static NSMutableSet<SMWeakContainer *> *_weakContainers = nil;
// this is enough for the status bar legacy data
static unsigned char _sharedData[5000] = {0};
%group SingleMuteQuietMode
%hook _UIStatusBarIndicatorQuietModeItem
- (id)systemImageNameForUpdate:(_UIStatusBarItemUpdate *)update {
BOOL isRingerMuted = [_ringerControl isRingerMuted];
BOOL isQuietModeEnabled = ![update.data.quietModeEntry.focusName isEqualToString:@"!Mute"];
if (isRingerMuted && !isQuietModeEnabled) {
return @"bell.slash.fill";
}
return %orig;
}
%end
%hook _UIStatusBarDataQuietModeEntry
- (id)initFromData:(unsigned char *)data type:(int)arg2 focusName:(const char *)arg3 maxFocusLength:(int)arg4 imageName:(const char*)arg5 maxImageLength:(int)arg6 boolValue:(BOOL)arg7 {
BOOL isQuietMode = data[2];
if (!isQuietMode) {
_sharedData[2] = [_ringerControl isRingerMuted];
return %orig(_sharedData, arg2, "!Mute", arg4, arg5, arg6, arg7);
}
return %orig;
}
%end
%hook SBRingerControl
// iOS 15
- (id)initWithHUDController:(id)arg1 soundController:(id)arg2 {
_ringerControl = %orig;
return _ringerControl;
}
// iOS 16+
- (id)initWithBannerManager:(id)arg1 soundController:(id)arg2 {
_ringerControl = %orig;
return _ringerControl;
}
- (void)setRingerMuted:(BOOL)arg1 {
%orig;
for (SMWeakContainer *container in _weakContainers) {
UIStatusBar_Base *statusBar = (UIStatusBar_Base *)container.object;
[statusBar reloadSingleMute];
}
}
// iOS 17
- (void)setRingerMuted:(BOOL)arg1 withFeedback:(BOOL)arg2 reason:(id)arg3 clientType:(unsigned)arg4 {
%orig;
for (SMWeakContainer *container in _weakContainers) {
UIStatusBar_Base *statusBar = (UIStatusBar_Base *)container.object;
[statusBar reloadSingleMute];
}
}
%end
%hook UIStatusBar_Base
- (instancetype)_initWithFrame:(CGRect)frame showForegroundView:(BOOL)showForegroundView wantsServer:(BOOL)wantsServer inProcessStateProvider:(id)inProcessStateProvider {
SMWeakContainer *container = [SMWeakContainer new];
container.object = self;
[_weakContainers addObject:container];
return %orig;
}
%new
- (void)reloadSingleMute {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
const unsigned char *data = [UIStatusBarServer getStatusBarData];
[self statusBarServer:self.statusBarServer didReceiveStatusBarData:data withActions:0];
});
}
%end
%end // SingleMuteQuietMode
%group SingleMuteLocation
%hook _UIStatusBarDataLocationEntry
- (id)initFromData:(unsigned char *)arg1 type:(int)arg2 {
BOOL isRingerMuted = [_ringerControl isRingerMuted];
if (isRingerMuted) {
_sharedData[21] = 0;
return %orig(_sharedData, arg2);
}
return %orig;
}
%end
%end // SingleMuteLocation
%ctor {
ReloadPrefs();
if (!kIsEnabled) {
return;
}
_weakContainers = [NSMutableSet set];
%init(SingleMuteQuietMode);
if (kUseLowPriorityLocation) {
%init(SingleMuteLocation);
}
}