This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
HBBVListener.x
49 lines (39 loc) · 1.55 KB
/
HBBVListener.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
#import "HBBVListener.h"
#import <BackBoardServices/BKSDisplayBrightness.h>
#import <SpringBoard/SBBrightnessController.h>
#import <SpringBoard/SBHUDController.h>
#import <SpringBoard/SBHUDView.h>
#import <SpringBoard/VolumeControl.h>
@implementation HBBVListener {
NSTimer *_timer;
}
- (void)setBrightness:(BOOL)direction volumeControl:(VolumeControl *)volumeControl {
[[%c(SBBrightnessController) sharedBrightnessController] adjustBacklightLevel:direction];
#ifndef BRIGHTVOL_LEGACY
BKSDisplayBrightnessTransactionRef transaction = BKSDisplayBrightnessTransactionCreate(kCFAllocatorDefault);
BKSDisplayBrightnessSet(BKSDisplayBrightnessGetCurrent(), 1);
CFRelease(transaction);
#endif
// if a timer already exists, cancel it
if (_timer) {
[_timer invalidate];
}
// set a new timer
_timer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(timeoutFired) userInfo:nil repeats:NO];
}
- (void)timeoutFired {
// the timer has expired, so we need to reset the mode back to default
_brightnessMode = NO;
_timer = nil;
}
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event {
// tell activator we’re handling this event
event.handled = YES;
// flip the mode
_brightnessMode = !_brightnessMode;
// show a HUD with the current mode icon so the user knows what mode they’re in now
SBHUDView *hud = [[%c(SBHUDView) alloc] initWithHUDViewLevel:0];
hud.image = [UIImage imageNamed:_brightnessMode ? @"brightness" : @"speaker"];
[[%c(SBHUDController) sharedHUDController] presentHUDView:hud autoDismissWithDelay:1];
}
@end