/
Tweak.xm
60 lines (51 loc) · 1.83 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
//
// Created by Josh Straitiff
// Copyright 2009 Josh Straitiff
//
#include <SpringBoard/SBRoundedCornerView.h>
#define kSettingsChangeNotification "com.straitiff.windowplaner.settingschange"
static UIWindow *roundWin;
static SBRoundedCornerView *roundView;
static void UpdateWindowAndView();
%class SBRoundedCornerView
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)app {
%orig;
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (void (*)(CFNotificationCenterRef, void *, CFStringRef, const void *, CFDictionaryRef))UpdateWindowAndView, CFSTR(kSettingsChangeNotification), NULL, CFNotificationSuspensionBehaviorHold);
UpdateWindowAndView();
}
- (void)dealloc {
[roundView removeFromSuperview];
[roundView release];
roundView = nil;
[roundWin setHidden:YES];
[roundWin release];
roundWin = nil;
%orig;
}
%end
static void UpdateWindowAndView()
{
[roundView removeFromSuperview];
[roundView release];
roundView = nil;
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.straitiff.windowplaner.plist"];
id toggleActiveSetting = [dict objectForKey:@"active"];
if (toggleActiveSetting ? [toggleActiveSetting boolValue] : YES) {
id sizeSetting = [dict objectForKey:@"size"];
CGFloat sliderValue = sizeSetting ? floorf([sizeSetting floatValue]) : 12.0f;
if (!roundWin) {
roundWin = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
roundWin.windowLevel = 99999;
roundWin.userInteractionEnabled = NO;
roundWin.hidden = NO;
}
roundView = [[$SBRoundedCornerView alloc] initWithCornerRadius:sliderValue size:sliderValue inset:0.0f imageSuperview:nil];
roundView.frame = [[UIScreen mainScreen] bounds];
[roundWin addSubview:roundView];
} else {
[roundWin setHidden:YES];
[roundWin release];
roundWin = nil;
}
}