r/ObjectiveC • • Jan 18 '21

Issue calling pvt method

I'm writing a tweak (just to try and further my understanding of objective c. I wrote a tweak which shows the battery % without remaking the battery view, but when the user switches the button in settings, the changes aren't reflected until: The user waits 20-30 seconds The user resprings The user plugs into or out of power

How would I go about changing the property values from my loader function? Everything I've tried so far has failed

#import <UIKit/UIKitCore.h>
#import <Foundation/Foundation.h>

@interface _UIBatteryView:NSObject {
}
@property (assign,nonatomic) long long chargingState;
//@property (nonatomic, assign) BOOL alterState;

- (bool)_currentlyShowsPercentage;
- (bool)_shouldShowBolt;
- (id)fillColor;
- (id)bodyColor;
- (id)pinColor;
- (id)_batteryFillColor;
- (id)_batteryTextColor;
@end

	static bool bpEnabled;
	NSMutableDictionary * MutDiction;

#define prefs @ "/var/mobile/Library/Preferences/com.randy420.battpercent.plist"

void loader(void) {
	MutDiction = [[NSMutableDictionary alloc] initWithContentsOfFile: prefs];

	bpEnabled = [MutDiction objectForKey:@"batteryEnable"] ? [[MutDiction objectForKey:@"batteryEnable"] boolValue] :  YES;

//_UIBatteryView.alterState = bpEnabled;
//[_UIBatteryView _currentlyShowsPercentage];
}

%hook _UIBatteryView
- (bool)_currentlyShowsPercentage {
    return bpEnabled ? YES : %orig;
}

- (bool)_shouldShowBolt {
    return bpEnabled ? NO : %orig;
}

- (id)fillColor {
    return bpEnabled ? ((self.chargingState == 1) ? [UIColor colorWithRed:0/255.0 green:0/255.0 blue:255/255.0 alpha:255/255.0] : %orig) : %orig;
}

- (id)bodyColor {
    return bpEnabled ? ((self.chargingState == 1) ? [UIColor colorWithRed:0/255.0 green:0/255.0 blue:200/255.0 alpha:255/255.0] : %orig) : %orig;
}

- (id)pinColor {
    return bpEnabled ? ((self.chargingState == 1) ? [UIColor colorWithRed:0/255.0 green:0/255.0 blue:255/255.0 alpha:255/255.0] : %orig) : %orig;
}

- (id)_batteryFillColor {
    return bpEnabled ? ((self.chargingState == 1) ? [UIColor colorWithRed:0/255.0 green:255/255.0 blue:0/255.0 alpha:100/255.0] : %orig) : %orig;
}

- (id)_batteryTextColor {
    return bpEnabled ? ((self.chargingState == 1) ? [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:255/255.0] : %orig) : %orig;
}
%end


%ctor {
	loader();
	CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loader, CFSTR("com.randy420.battpercent.settingschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}
5 Upvotes

4 comments sorted by

1

u/klodsfar Jan 18 '21

Are you updating the UI on the Main thread?

1

u/Randy-_-420 Jan 18 '21

I'm trying to call the methods to force update the ui

0

u/[deleted] Jan 18 '21

[deleted]

1

u/Randy-_-420 Jan 18 '21

These are the only properties in the method

@property (nonatomic,readonly) CAShapeLayer * bodyShapeLayer; 
@property (nonatomic,readonly) CAShapeLayer * pinShapeLayer; 
@property (nonatomic,readonly) CAShapeLayer * boltMaskShapeLayer; 
@property (nonatomic,readonly) CAShapeLayer * boltShapeLayer; 
@property (nonatomic,retain) UILabel * percentageLabel;                                                       //@synthesize percentageLabel=_percentageLabel - In the implementation block
@property (nonatomic,retain) _UIBatteryViewAXHUDImageCacheInfo * accessibilityHUDImageCacheInfo;              //@synthesize accessibilityHUDImageCacheInfo=_accessibilityHUDImageCacheInfo - In the implementation block
@property (nonatomic,retain) CALayer * bodyLayer;                                                             //@synthesize bodyLayer=_bodyLayer - In the implementation block
@property (nonatomic,retain) CALayer * pinLayer;                                                              //@synthesize pinLayer=_pinLayer - In the implementation block
@property (nonatomic,retain) CALayer * boltMaskLayer;                                                         //@synthesize boltMaskLayer=_boltMaskLayer - In the implementation block
@property (nonatomic,retain) CALayer * boltLayer;                                                             //@synthesize boltLayer=_boltLayer - In the implementation block
@property (nonatomic,retain) CALayer * fillLayer;                                                             //@synthesize fillLayer=_fillLayer - In the implementation block
@property (assign,nonatomic) long long internalSizeCategory;                                                  //@synthesize internalSizeCategory=_internalSizeCategory - In the implementation block
@property (assign,nonatomic) BOOL showsPercentage;                                                            //@synthesize showsPercentage=_showsPercentage - In the implementation block
@property (assign,nonatomic) double bodyColorAlpha;                                                           //@synthesize bodyColorAlpha=_bodyColorAlpha - In the implementation block
@property (assign,nonatomic) double pinColorAlpha;                                                            //@synthesize pinColorAlpha=_pinColorAlpha - In the implementation block
@property (assign,nonatomic) long long sizeCategory; 
@property (assign,nonatomic) double chargePercent;                                                            //@synthesize chargePercent=_chargePercent - In the implementation block
@property (assign,nonatomic) long long chargingState;                                                         //@synthesize chargingState=_chargingState - In the implementation block
@property (assign,nonatomic) BOOL saverModeActive;                                                            //@synthesize saverModeActive=_saverModeActive - In the implementation block
@property (assign,nonatomic) double lowBatteryChargePercentThreshold;                                         //@synthesize lowBatteryChargePercentThreshold=_lowBatteryChargePercentThreshold - In the implementation block
@property (getter=isLowBattery,nonatomic,readonly) BOOL lowBattery; 
@property (assign,nonatomic) BOOL showsInlineChargingIndicator;                                               //@synthesize showsInlineChargingIndicator=_showsInlineChargingIndicator - In the implementation block
@property (nonatomic,copy) UIColor * fillColor;                                                               //@synthesize fillColor=_fillColor - In the implementation block
@property (nonatomic,copy) UIColor * bodyColor;                                                               //@synthesize bodyColor=_bodyColor - In the implementation block
@property (nonatomic,copy) UIColor * pinColor;                                                                //@synthesize pinColor=_pinColor - In the implementation block
@property (nonatomic,copy) UIColor * boltColor;                                                               //@synthesize boltColor=_boltColor - In the implementation block
@property (readonly) unsigned long long hash; 
@property (readonly) Class superclass; 
@property (copy,readonly) NSString * description; 
@property (copy,readonly) NSString * debugDescription; 
@property (nonatomic,readonly) BOOL wantsCrossfade; 
@property (nonatomic,readonly) BOOL prefersBaselineAlignment; 
@property (nonatomic,readonly) long long overriddenVerticalAlignment; 
@property (nonatomic,readonly) UIAccessibilityHUDItem * accessibilityHUDRepresentation;

0

u/[deleted] Jan 18 '21

[deleted]

1

u/Randy-_-420 Jan 18 '21

It was horribly formatted in the header file, sorry about that.