Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Manual update timer for DataMeter on iOS 13
SBStatusBarStateAggregator hook is freezing SpringBoard
Package: com.estertion.datameter13
Name: DataMeter13
Depends: mobilesubstrate
Version: 1
Architecture: iphoneos-arm
Description: Manual DataMeter updater on iOS 13
Maintainer: esterTion
Author: esterTion
Section: Tweaks
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
include $(THEOS)/makefiles/common.mk
ARCHS = arm64
TWEAK_NAME = DataMeterz13
DataMeterz13_FILES = Tweak.xm
DataMeterz13_CFLAGS = -fobjc-arc
include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
install.exec "killall -9 SpringBoard"
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@interface FloatView : UIView
-(void)show;
-(void)hide;
-(void)setRateText:(NSString*)rateText;
@end
@interface SBStatusBarStateAggregator : NSObject {
NSDateFormatter* _timeItemDateFormatter;
}
+(SBStatusBarStateAggregator*)sharedInstance;
-(void)_updateTimeItems;
@end
static FloatView* view = NULL;
static NSString* timeFormat = NULL;
@interface DataMeterUpdater : NSObject
@end
@implementation DataMeterUpdater
+(void)doWork {
NSDictionary* infoData = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.zx.DataMeterInfoData.plist"];
uint64_t wifiRateByte = [infoData[@"wifiRateByte"] unsignedLongLongValue];
uint64_t cellularRateByte = [infoData[@"cellularRateByte"] unsignedLongLongValue];
uint64_t rate = cellularRateByte > wifiRateByte ? cellularRateByte : wifiRateByte;
NSString* rateText;
if (rate < 100 * 1024) {
rateText = [NSString stringWithFormat:@"%.2fK/s", (double)rate / 1024.0];
} else if (rate < 1024*1024) {
rateText = [NSString stringWithFormat:@"%dK/s", (signed int)rate / 1024];
} else if (rate < 99*1024*1024) {
rateText = [NSString stringWithFormat:@"%.2fM/s", (double)rate / 1024.0 / 1024.0];
} else {
rateText = [NSString stringWithFormat:@"%dM/s", (signed int)rate / 1024 / 1024];
}
if (view) {
if (rate) {
[view show];
[view setRateText:rateText];
[view setNeedsDisplay];
} else {
[view hide];
}
}
if (timeFormat) {
SBStatusBarStateAggregator *sbsba = [objc_getClass("SBStatusBarStateAggregator") sharedInstance];
[[sbsba valueForKey:@"_timeItemDateFormatter"] setDateFormat:timeFormat];
[sbsba _updateTimeItems];
}
}
@end
%hook FloatView
-(void)hide {
%orig;
if (!view) view = self;
}
%end
%ctor {
[NSTimer scheduledTimerWithTimeInterval:1.0 target:[DataMeterUpdater class] selector:@selector(doWork) userInfo:nil repeats:YES];
NSDictionary* prefs = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.zx.DataMeterConfig.plist"];
timeFormat = prefs[@"timeFormat"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.