forked from lablabla/MuteIcon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.xm
103 lines (91 loc) · 2.38 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
#import "SpringBoard/SBMediaController.h"
#import "LibStatusBar/LSStatusBarItem.h"
#import "Settings.h"
#define BELL_ICON @"ON_Mute_Bell"
#define SPEAKER_ICON @"ON_Mute_Speaker"
#define BELL_ICON_7 @"ON_Mute_7_Bell"
#define SPEAKER_ICON_7 @"ON_Mute_7_Speaker"
#ifndef kCFCoreFoundationVersionNumber_iOS_7_0
#define kCFCoreFoundationVersionNumber_iOS_7_0 847.2
#endif
LSStatusBarItem *icon;
BOOL enabled, bell;
Settings *settings;
void changeIcon()
{
if (%c(SBMediaController) && [%c(SBMediaController) instancesRespondToSelector:@selector(isRingerMuted)])
{
bool isMute = [[%c(SBMediaController) sharedInstance] isRingerMuted];
if (!isMute)
{
if (icon) {
icon.visible = NO;
[icon release];
icon = nil;
}
}
else
{
if (!icon) {
icon = [[%c(LSStatusBarItem) alloc] initWithIdentifier:[NSString stringWithFormat:@"com.lablabla.muteicon"] alignment:StatusBarAlignmentRight];
}
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
[icon setImageName:bell ? BELL_ICON_7 : SPEAKER_ICON_7];
}
else
{
[icon setImageName:bell ? BELL_ICON : SPEAKER_ICON];
}
icon.visible = YES;
}
}
}
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application
{
%orig;
settings = [[Settings alloc] init];
[settings reloadPreferences];
enabled = [[settings.preferences valueForKey:@"muteEnabled"] boolValue];
bell = [[settings.preferences valueForKey:@"iconType"] boolValue];
if (enabled)
{
changeIcon();
}
}
%end
%hook SBMediaController
-(void)setRingerMuted:(BOOL)muted
{
%orig;
if (enabled)
{
changeIcon();
}
}
%end
static void reloadPrefsNotification(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
[settings reloadPreferences];
enabled = [[settings.preferences valueForKey:@"muteEnabled"] boolValue];
if (icon && (!enabled || bell != [[settings.preferences valueForKey:@"iconType"] boolValue])) {
icon.visible = NO;
[icon release];
icon = nil;
}
bell = [[settings.preferences valueForKey:@"iconType"] boolValue];
if (enabled)
{
changeIcon();
}
}
%ctor
{
//Register for the preferences-did-change notification
CFNotificationCenterRef r = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(r, NULL, &reloadPrefsNotification, CFSTR("com.lablabla.muteicon/reloadPrefs"), NULL, 0);
}