Last active
February 12, 2020 01:16
-
-
Save lwlsw/a59f0b41401d0f52db17588f0084ac58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tweak.xm | |
* VolumeLock | |
* | |
* Created by Zachary Thomas Paul <LacertosusThemes@gmail.com> on 9/16/2019. | |
* Copyright © 2019 LacertosusDeus <LacertosusThemes@gmail.com>. All rights reserved. | |
*/ | |
#define LD_DEBUG NO | |
static BOOL toggleVolumeLock = NO; | |
//Thanks Gilshahar7 | |
//https://github.com/gilshahar7/VolumeSongSkipper113/blob/master/Tweak.xm#L88 | |
%hook SpringBoard | |
-(BOOL)_handlePhysicalButtonEvent:(UIPressesEvent *)event { | |
BOOL upPressed = NO; | |
BOOL downPressed = NO; | |
for(UIPress *press in event.allPresses.allObjects) { | |
if(press.type == 102 && press.force == 1) { | |
upPressed = YES; | |
} | |
if(press.type == 103 && press.force == 1) { | |
downPressed = YES; | |
} | |
} | |
if(upPressed && downPressed) { | |
UINotificationFeedbackGenerator *feedback = [[UINotificationFeedbackGenerator alloc] init]; | |
[feedback prepare]; | |
switch ((int)toggleVolumeLock) { | |
case 0: | |
toggleVolumeLock = YES; | |
[feedback notificationOccurred:UINotificationFeedbackTypeSuccess]; | |
break; | |
case 1: | |
toggleVolumeLock = NO; | |
[feedback notificationOccurred:UINotificationFeedbackTypeError]; | |
break; | |
} | |
} | |
return %orig; | |
} | |
%end | |
%hook VolumeControl | |
-(void)increaseVolume { | |
if(toggleVolumeLock) { | |
return ; | |
} | |
%orig; | |
} | |
-(void)decreaseVolume { | |
if(toggleVolumeLock) { | |
return ; | |
} | |
%orig; | |
} | |
%end | |
%ctor { | |
if([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){13, 0, 0}]) { | |
%init(VolumeControl = NSClassFromString(@"SBVolumeControl")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment