Skip to content

Commit 5396740

Browse files
committed
1.0
1 parent 9f85735 commit 5396740

File tree

10 files changed

+335
-149
lines changed

10 files changed

+335
-149
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,3 @@ packages/
7070
.DS_Store
7171

7272
.theos/
73-
74-
Makefile

Bop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
-(void)buttonPressed_LG:(char) button;
1010
-(void)respring_LG:(BOOL)safeMode;
1111
-(void)pauseMusic;
12-
-(void)repeatMusic;
12+
//-(void)repeatMusic;
1313
-(void)skipTrack;
1414
-(void)f15Music;
15+
-(void)prevTrack;
1516
-(void)b15Music;
1617
-(void)loadPrefs;
1718
@end

Bop.xm

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#import "Bop.h"
2+
static NSString *pauseMusicSequence = @"V";
3+
static NSString *skipTrackSequence = @"VUD";
4+
static NSString *f15Sequence = @"";
5+
static NSString *b15Sequence = @"";
6+
static NSString *prevTrackSequence = @"VDU";
7+
static NSTimer *BopTimer;
8+
static id sharedInstance;
9+
10+
@implementation Bop
11+
NSMutableString *sequence = [@"" mutableCopy];
12+
NSTimeInterval lastPress;
13+
14+
+ (id)sharedInstance{
15+
NSLog(@"[Bop] get sharedInstance");
16+
return sharedInstance;
17+
}
18+
19+
-(id)init {
20+
NSLog(@"[Bop] init");
21+
lastPress = 0.0;
22+
sharedInstance = self;
23+
return self;
24+
}
25+
26+
27+
28+
-(void)buttonPressed_LG:(char)button {
29+
NSLog(@"[Bop] Button pressed");
30+
NSTimeInterval now = [[NSDate date] timeIntervalSince1970] * 1000;
31+
if (now - lastPress > 650.0){
32+
[sequence setString:@""];
33+
} else {
34+
if(BopTimer)
35+
NSLog(@"[Bop] Bop Timer");
36+
[BopTimer invalidate];
37+
}
38+
if (now - lastPress < 100.0)
39+
[sequence deleteCharactersInRange:NSMakeRange([sequence length]-1, 1)];
40+
lastPress = now;
41+
42+
[sequence appendFormat:@"%c", button];
43+
NSLog(@"[Bop] Start Timer");
44+
BopTimer = [NSTimer scheduledTimerWithTimeInterval:0.65
45+
target:self
46+
selector:@selector(interpSeq)
47+
userInfo:nil
48+
repeats:NO];
49+
}
50+
-(void)interpSeq {
51+
NSLog(@"[Bop] interpSeq");
52+
[self loadPrefs];
53+
if([[sequence copy] isEqualToString: pauseMusicSequence]) {[self pauseMusic];}
54+
if([[sequence copy] isEqualToString: skipTrackSequence]) {[self skipTrack];}
55+
//if([[sequence copy] isEqualToString: toggleRepeatSequence]) {[self repeatMusic];}
56+
if([[sequence copy] isEqualToString: f15Sequence]) {[self f15Music];}
57+
if([[sequence copy] isEqualToString: b15Sequence]) {[self b15Music];}
58+
if([[sequence copy] isEqualToString: prevTrackSequence]) {[self prevTrack];}
59+
}
60+
61+
-(void)respring_LG:(BOOL)safeMode {
62+
[sequence setString:@""];
63+
pid_t pid;
64+
if (safeMode) {
65+
const char* args[] = {"killall", "-SEGV", "SpringBoard", NULL};
66+
posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
67+
} else {
68+
const char* args[] = {"killall", "backboardd", NULL};
69+
posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
70+
}
71+
}
72+
-(void)pauseMusic{
73+
NSLog(@"[Bop] %d TogglePause", (int)MRMediaRemoteSendCommand(kMRTogglePlayPause, 0));
74+
75+
}
76+
-(void)prevTrack{
77+
MRMediaRemoteSendCommand(kMRPreviousTrack, 0);
78+
}
79+
-(void)skipTrack{
80+
MRMediaRemoteSendCommand(kMRNextTrack, 0);
81+
82+
NSLog(@"[Bop] skipTrack");
83+
}
84+
-(void)f15Music{
85+
MRMediaRemoteSendCommand(kMRSkipFifteenSeconds, 0);
86+
87+
NSLog(@"[Bop] Hit f15");
88+
}
89+
-(void)b15Music{
90+
91+
NSLog(@"[Bop] %d Hit b15", (int)MRMediaRemoteSendCommand(kMRGoBackFifteenSeconds, 0));
92+
}
93+
94+
-(void)loadPrefs{
95+
NSLog(@"[Bop] loadPrefs");
96+
NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.squidkingdom.boppreferences.defaults"];
97+
98+
pauseMusicSequence = [[prefs objectForKey:@"pauseMusicSequence"] uppercaseString];
99+
skipTrackSequence = [[prefs objectForKey:@"skipTrackSequence"] uppercaseString];
100+
f15Sequence = [[prefs objectForKey:@"f15Sequence"] uppercaseString];
101+
b15Sequence = [[prefs objectForKey:@"b15Sequence"] uppercaseString];
102+
prevTrackSequence = [[prefs objectForKey:@"prevTrackSequence"] uppercaseString];
103+
NSLog(@"[Bop] Pause: %@\nSkip: %@\n Forward: %@\n Back: %@\n", [pauseMusicSequence copy], skipTrackSequence, f15Sequence, b15Sequence);
104+
}
105+
@end

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
#THEOS_DEVICE_IP = 192.168.1.131
2-
THEOS_DEVICE_IP = 172.20.10.1
1+
THEOS_DEVICE_IP = 192.168.1.215
2+
FINAL_BUILD = 1
3+
FOR_RELEASE= 0
34
export ARCHS = arm64 arm64e
45
export TARGET = iphone:clang:13.0:10.0
56

67
include $(THEOS)/makefiles/common.mk
78

89
TWEAK_NAME = Bop
9-
Bop_FILES = Tweak.xm
10-
Bop_EXTRA_FRAMEWORKS += Cephei
10+
Bop_FILES = Tweak.xm Bop.xm
11+
Bop_EXTRA_FRAMEWORKS += Cephei
1112
Bop_PRIVATE_FRAMEWORKS = MediaRemote
1213

1314
include $(THEOS_MAKE_PATH)/tweak.mk
1415

15-
#after-install::
16-
#install.exec "killall -9 SpringBoard"
16+
after-install::
17+
install.exec "killall -9 SpringBoard"
1718
SUBPROJECTS += boppreferences
1819
include $(THEOS_MAKE_PATH)/aggregate.mk

Tweak.xm

Lines changed: 22 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,20 @@
33
#define VDOWN_BUTTON 103
44
#define POWER_BUTTON 104
55
#define HOME_BUTTON 101
6+
bool inited = false;
67

7-
static NSString *pauseMusicSequence = @"";
8-
static NSString *skipTrackSequence = @"";
9-
static NSString *toggleRepeatSequence = @"";
10-
static NSString *f15Sequence = @"";
11-
static NSString *b15Sequence = @"";
12-
static NSTimer *bopTimer;
13-
14-
15-
static void loadPrefs();
16-
17-
8+
%group tweakStuff
189
id sharedInstance;
19-
static BOOL tweakEnabled = YES;
20-
static BOOL isRunning = NO;
21-
10+
bool isRunning = NO;
2211
static void triggerButton(char button) {
23-
if (tweakEnabled && !isRunning) {
24-
isRunning = YES;
25-
if (!sharedInstance) sharedInstance = [[Bop alloc] init];
12+
NSLog(@"[Bop] triggerButton");
13+
if(!isRunning){
14+
isRunning = YES;
2615
[sharedInstance buttonPressed_LG:button];
27-
isRunning = NO;
28-
}
16+
isRunning = NO;
17+
18+
}
19+
2920
}
3021

3122

@@ -72,6 +63,7 @@ static void triggerButton(char button) {
7263
if (force == 1 && force2 == 1){
7364
// NSLog(@"[BOP] Volume");
7465
triggerButton('V');
66+
7567
}
7668
}
7769
if (type+type2 == 207 && force+force2 == 2){
@@ -82,8 +74,10 @@ static void triggerButton(char button) {
8274
// NSLog(@"[BOP] Single button %i", type);
8375
if (type == VDOWN_BUTTON)
8476
triggerButton('D');
85-
else if (type == VUP_BUTTON)
86-
triggerButton('U');
77+
else if (type == VUP_BUTTON){
78+
NSLog(@"[Bop] %i", force);
79+
triggerButton('U');
80+
}
8781
else if (type == POWER_BUTTON)
8882
triggerButton('L');
8983
else if (type == HOME_BUTTON)
@@ -96,92 +90,16 @@ static void triggerButton(char button) {
9690
%end
9791

9892

99-
@implementation Bop
100-
NSMutableString *sequence = [@"" mutableCopy];
101-
NSTimeInterval lastPress;
102-
103-
+ (id)sharedInstance{
104-
return sharedInstance;
105-
}
106-
107-
-(id)init {
108-
lastPress = 0.0;
109-
return self;
110-
}
111-
112-
113-
114-
-(void)buttonPressed_LG:(char)button {
115-
116-
NSTimeInterval now = [[NSDate date] timeIntervalSince1970] * 1000;
117-
if (now - lastPress > 650.0){
118-
[sequence setString:@""];
119-
} else {
120-
if(bopTimer)
121-
[bopTimer invalidate];
122-
}
123-
if (now - lastPress < 100.0)
124-
[sequence deleteCharactersInRange:NSMakeRange([sequence length]-1, 1)];
125-
lastPress = now;
126-
127-
[sequence appendFormat:@"%c", button];
128-
NSLog(@"[BOP] Sequence:%@ Added:%c", sequence, button);
129-
bopTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
130-
target:self
131-
selector:@selector(interpSeq)
132-
userInfo:nil
133-
repeats:NO];
134-
}
135-
-(void)interpSeq {
136-
137-
if([[sequence copy] isEqualToString: pauseMusicSequence]) {[self pauseMusic];}
138-
if([[sequence copy] isEqualToString: skipTrackSequence]) {[self skipTrack];}
139-
if([[sequence copy] isEqualToString: toggleRepeatSequence]) {[self repeatMusic];}
140-
if([[sequence copy] isEqualToString: f15Sequence]) {[self f15Music];}
141-
if([[sequence copy] isEqualToString: b15Sequence]) {[self b15Music];}
142-
}
143-
144-
-(void)respring_LG:(BOOL)safeMode {
145-
[sequence setString:@""];
146-
pid_t pid;
147-
if (safeMode) {
148-
const char* args[] = {"killall", "-SEGV", "SpringBoard", NULL};
149-
posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
150-
} else {
151-
const char* args[] = {"killall", "backboardd", NULL};
152-
posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
153-
}
154-
}
155-
-(void)pauseMusic{
156-
MRMediaRemoteSendCommand(kMRTogglePlayPause, 0);
157-
}
158-
-(void)repeatMusic{
159-
MRMediaRemoteSendCommand(kMRToggleRepeat, 0);
160-
}
161-
-(void)skipTrack{
162-
MRMediaRemoteSendCommand(kMRNextTrack, 0);
163-
}
164-
-(void)f15Music{
165-
MRMediaRemoteSendCommand(kMRSkipFifteenSeconds, 0);
166-
}
167-
-(void)b15Music{
168-
MRMediaRemoteSendCommand(kMRGoBackFifteenSeconds, 0);
169-
}
170-
-(void)loadPrefs{
171-
loadPrefs();
172-
}
173-
174-
175-
@end
17693

94+
%end
17795

17896

179-
static void loadPrefs() {
180-
NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.squidkingdom.boppreferences.defaults"];
181-
pauseMusicSequence = [[prefs objectForKey:@"pauseMusicSequence"] uppercaseString];
182-
skipTrackSequence = [[prefs objectForKey:@"skipTrackSequence"] uppercaseString];
183-
}
18497

18598
%ctor {
186-
loadPrefs();
99+
NSLog(@"[Bop] Ctor");
100+
if(!inited)
101+
%init(tweakStuff);
102+
inited = true;
103+
sharedInstance = [[Bop alloc] init];
104+
[sharedInstance loadPrefs];
187105
}

boppreferences/BOPRootListController.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@
135135
@interface BOPRootListController : HBRootListController
136136
@end
137137

138-
@interface Bop : NSObject
139138

140-
-(void)loadPrefs;
141-
+(id)sharedInstance;
142-
@end
143139

144140
@interface LifeguardBigTextCell : PSTableCell{
145141
UILabel* _label;

boppreferences/BOPRootListController.m

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BOPRootListController.h"
2+
#include "../Bop.h"
23

34
@implementation BOPRootListController
45

@@ -10,10 +11,10 @@ - (void) viewDidLoad {
1011
self.navigationController.navigationBar.prefersLargeTitles = false;
1112
self.navigationController.navigationItem.largeTitleDisplayMode =
1213
UINavigationItemLargeTitleDisplayModeNever;
13-
[[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Apply"
14-
style:UIBarButtonItemStylePlain
15-
target:self
16-
action:@selector(respring)]];
14+
// [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Apply"
15+
// style:UIBarButtonItemStylePlain
16+
// target:self
17+
// action:@selector(respring)]];
1718
}
1819
}
1920

@@ -25,10 +26,10 @@ - (void) viewDidAppear:(BOOL)animated {
2526
self.navigationController.navigationItem.largeTitleDisplayMode =
2627
UINavigationItemLargeTitleDisplayModeNever;
2728

28-
[[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Apply"
29-
style:UIBarButtonItemStylePlain
30-
target:self
31-
action:@selector(respring)]];
29+
// [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Apply"
30+
// style:UIBarButtonItemStylePlain
31+
// target:self
32+
// action:@selector(respring)]];
3233
}
3334
}
3435

@@ -71,16 +72,16 @@ - (NSArray *) specifiers {
7172

7273
return _specifiers;
7374
}
74-
- (void) respring {
75-
76-
[[Bop sharedInstance] loadPrefs];
77-
// pid_t pid;
78-
// const char* args[] = {"killall", "-9", "SpringBoard", NULL};
79-
// [HBRespringController respringAndReturnTo:[NSURL URLWithString:@"prefs:root=Bop"]];
80-
//
81-
// posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
82-
83-
}
75+
// - (void) respring {
76+
// NSLog(@"[Bop] respring called");
77+
// [[Bop sharedInstance] loadPrefs];
78+
// // pid_t pid;
79+
// // const char* args[] = {"killall", "-9", "SpringBoard", NULL};
80+
// // [HBRespringController respringAndReturnTo:[NSURL URLWithString:@"prefs:root=Bop"]];
81+
// //
82+
// // posix_spawn(&pid, "/usr/bin/killall", NULL, NULL, (char* const*)args, NULL);
83+
//
84+
// }
8485

8586

8687

0 commit comments

Comments
 (0)