Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
renewed the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra authored and Alexandra committed Sep 17, 2022
0 parents commit 48fe5d2
Show file tree
Hide file tree
Showing 20 changed files with 951 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: traurige
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Bug report
about: Report a bug to help improve BatteryBuddy
title: ''
labels: bug
assignees: Traurige

---

**Describe the bug:**

**Steps to reproduce the behavior:**

**System information:**
- iOS version:
- Jailbreak:
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Feature request
about: Suggest a feature that can help make BatteryBuddy even better
title: ''
labels: enhancement
assignees: Traurige

---

**Describe the requested feature:**

**System information:**
- iOS version:
- Jailbreak:
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.theos
packages/
.vscode
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export ARCHS = arm64 arm64e
export TARGET = iphone:clang:14.4:13.0
export SYSROOT = $(THEOS)/sdks/iPhoneOS14.4.sdk
#export PREFIX = $(THEOS)/toolchain/Xcode.xctoolchain/usr/bin/

INSTALL_TARGET_PROCESSES = SpringBoard
SUBPROJECTS = Tweak

include $(THEOS)/makefiles/common.mk
include $(THEOS_MAKE_PATH)/aggregate.mk
Binary file added Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Battery Buddy ⚡️
Battery Indicator, but cute

## Preview
<img src="Preview.png" alt="BatteryBuddy preview" />

## Installation
1. Download the latest `deb` from the [releases](https://github.com/Traurige/BatteryBuddy/releases)
2. Install BatteryBuddy

## Compatibility
iPhone, iPad and iPod running iOS/iPadOS 13 or later

## Compiling
- [Theos](https://theos.dev/) is required to compile the project
- You may want to edit the root `Makefile` to use your Theos SDK and toolchain

## License
[GPLv3](https://github.com/Traurige/BatteryBuddy/blob/main/COPYING)

## Credits
- Original Creator For macOS
- [neilsardesai](https://twitter.com/neilsardesai)
- Icon And Banner
- [74k1_](https://twitter.com/74k1_)
25 changes: 25 additions & 0 deletions Tweak/BatteryBuddy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// BatteryBuddy.h
// BatteryBuddy
//
// Created by Alexandra (@Traurige)
//

#import "substrate.h"
#import <UIKit/UIKit.h>

UIImageView* statusBarBatteryIconView;
UIImageView* statusBarBatteryChargerView;
UIImageView* lockscreenBatteryIconView;
UIImageView* lockscreenBatteryChargerView;
BOOL isCharging = NO;

@interface _UIBatteryView : UIView
- (CGFloat)chargePercent;
- (long long)chargingState;
- (void)refreshIcon;
- (void)updateIconColor;
@end

@interface CSBatteryFillView : UIView
@end
145 changes: 145 additions & 0 deletions Tweak/BatteryBuddy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//
// BatteryBuddy.m
// BatteryBuddy
//
// Created by Alexandra (@Traurige)
//

#import "BatteryBuddy.h"

BOOL (* orig__UIBatteryView__shouldShowBolt)(_UIBatteryView* self, SEL _cmd);
UIColor* (* orig__UIBatteryView_fillColor)(_UIBatteryView* self, SEL _cmd);
CGFloat (* orig__UIBatteryView_chargePercent)(_UIBatteryView* self, SEL _cmd);
long long (* orig__UIBatteryView_chargingState)(_UIBatteryView* self, SEL _cmd);
void (* orig__UIBatteryView__updateFillLayer)(_UIBatteryView* self, SEL _cmd);
void (* orig_CSBatteryFillView_didMoveToWindow)(CSBatteryFillView* self, SEL _cmd);

BOOL override__UIBatteryView__shouldShowBolt(_UIBatteryView* self, SEL _cmd) {
return NO;
}

UIColor* override__UIBatteryView_fillColor(_UIBatteryView* self, SEL _cmd) {
return [orig__UIBatteryView_fillColor(self, _cmd) colorWithAlphaComponent:0.25];
}

CGFloat override__UIBatteryView_chargePercent(_UIBatteryView* self, SEL _cmd) {
CGFloat orig = orig__UIBatteryView_chargePercent(self, _cmd);
int actualPercentage = orig * 100;

if (actualPercentage <= 20 && !isCharging) {
[statusBarBatteryIconView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/StatusBarSad.png"]];
} else if (actualPercentage <= 49 && !isCharging) {
[statusBarBatteryIconView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/StatusBarNeutral.png"]];
} else if (actualPercentage > 49 && !isCharging) {
[statusBarBatteryIconView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/StatusBarHappy.png"]];
} else if (isCharging) {
[statusBarBatteryIconView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/StatusBarHappy.png"]];
}

[self updateIconColor];

return orig;
}

long long override__UIBatteryView_chargingState(_UIBatteryView* self, SEL _cmd) {
long long orig = orig__UIBatteryView_chargingState(self, _cmd);

if (orig == 1) {
isCharging = YES;
} else {
isCharging = NO;
}

[self refreshIcon];

return orig;
}

void override__UIBatteryView__updateFillLayer(_UIBatteryView* self, SEL _cmd) {
orig__UIBatteryView__updateFillLayer(self, _cmd);
[self chargingState];
}

void _UIBatteryView_refreshIcon(_UIBatteryView* self, SEL _cmd) {
// remove existing images
statusBarBatteryIconView = nil;
statusBarBatteryChargerView = nil;
for (UIImageView* imageView in [self subviews]) {
[imageView removeFromSuperview];
}

if (!statusBarBatteryIconView) {
statusBarBatteryIconView = [[UIImageView alloc] initWithFrame:[self bounds]];
[statusBarBatteryIconView setContentMode:UIViewContentModeScaleAspectFill];
[statusBarBatteryIconView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
if (![statusBarBatteryIconView isDescendantOfView:self]) {
[self addSubview:statusBarBatteryIconView];
}
}

if (!statusBarBatteryChargerView && isCharging) {
statusBarBatteryChargerView = [[UIImageView alloc] initWithFrame:[self bounds]];
[statusBarBatteryChargerView setContentMode:UIViewContentModeScaleAspectFill];
[statusBarBatteryChargerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[statusBarBatteryChargerView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/StatusBarCharger.png"]];
if (![statusBarBatteryChargerView isDescendantOfView:self]) {
[self addSubview:statusBarBatteryChargerView];
}
}

[self chargePercent];
}

void _UIBatteryView_updateIconColor(_UIBatteryView* self, SEL _cmd) {
[statusBarBatteryIconView setImage:[[statusBarBatteryIconView image] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[statusBarBatteryChargerView setImage:[[statusBarBatteryChargerView image] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];

if (![[NSProcessInfo processInfo] isLowPowerModeEnabled]) {
[statusBarBatteryIconView setTintColor:[UIColor labelColor]];
[statusBarBatteryChargerView setTintColor:[UIColor labelColor]];
} else {
[statusBarBatteryIconView setTintColor:[UIColor blackColor]];
[statusBarBatteryChargerView setTintColor:[UIColor blackColor]];
}
}

void override_CSBatteryFillView_didMoveToWindow(CSBatteryFillView* self, SEL _cmd) {
orig_CSBatteryFillView_didMoveToWindow(self, _cmd);

[[self superview] setClipsToBounds:NO];

if (!lockscreenBatteryIconView) {
lockscreenBatteryIconView = [[UIImageView alloc] initWithFrame:[self bounds]];
[lockscreenBatteryIconView setContentMode:UIViewContentModeScaleAspectFill];
[lockscreenBatteryIconView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[lockscreenBatteryIconView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/LockscreenHappy.png"]];
}
[lockscreenBatteryIconView setImage:[[lockscreenBatteryIconView image] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[lockscreenBatteryIconView setTintColor:[UIColor whiteColor]];
if (![lockscreenBatteryIconView isDescendantOfView:[self superview]]) {
[[self superview] addSubview:lockscreenBatteryIconView];
}

if (!lockscreenBatteryChargerView) {
lockscreenBatteryChargerView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.origin.x - 25, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height)];
[lockscreenBatteryChargerView setContentMode:UIViewContentModeScaleAspectFill];
[lockscreenBatteryChargerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[lockscreenBatteryChargerView setImage:[UIImage imageWithContentsOfFile:@"/Library/BatteryBuddy/LockscreenCharger.png"]];
}
[lockscreenBatteryChargerView setImage:[[lockscreenBatteryChargerView image] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[lockscreenBatteryChargerView setTintColor:[UIColor whiteColor]];
if (![lockscreenBatteryChargerView isDescendantOfView:[self superview]]) {
[[self superview] addSubview:lockscreenBatteryChargerView];
}
}

__attribute__((constructor)) static void initialize() {
MSHookMessageEx(NSClassFromString(@"_UIBatteryView"), @selector(_shouldShowBolt), (IMP)&override__UIBatteryView__shouldShowBolt, (IMP *)&orig__UIBatteryView__shouldShowBolt);
MSHookMessageEx(NSClassFromString(@"_UIBatteryView"), @selector(fillColor), (IMP)&override__UIBatteryView_fillColor, (IMP *)&orig__UIBatteryView_fillColor);
MSHookMessageEx(NSClassFromString(@"_UIBatteryView"), @selector(chargePercent), (IMP)&override__UIBatteryView_chargePercent, (IMP *)&orig__UIBatteryView_chargePercent);
MSHookMessageEx(NSClassFromString(@"_UIBatteryView"), @selector(chargingState), (IMP)&override__UIBatteryView_chargingState, (IMP *)&orig__UIBatteryView_chargingState);
MSHookMessageEx(NSClassFromString(@"_UIBatteryView"), @selector(_updateFillLayer), (IMP)&override__UIBatteryView__updateFillLayer, (IMP *)&orig__UIBatteryView__updateFillLayer);
class_addMethod(NSClassFromString(@"_UIBatteryView"), @selector(refreshIcon), (IMP)&_UIBatteryView_refreshIcon, "v@:");
class_addMethod(NSClassFromString(@"_UIBatteryView"), @selector(updateIconColor), (IMP)&_UIBatteryView_updateIconColor, "v@:");
MSHookMessageEx(NSClassFromString(@"CSBatteryFillView"), @selector(didMoveToWindow), (IMP)&override_CSBatteryFillView_didMoveToWindow, (IMP *)&orig_CSBatteryFillView_didMoveToWindow);
}
1 change: 1 addition & 0 deletions Tweak/BatteryBuddy.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
7 changes: 7 additions & 0 deletions Tweak/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TWEAK_NAME = BatteryBuddy
BatteryBuddy_FILES = BatteryBuddy.m
BatteryBuddy_CFLAGS = -fobjc-arc -DTHEOS_LEAN_AND_MEAN
BatteryBuddy_FRAMEWORKS = UIKit

include $(THEOS)/makefiles/common.mk
include $(THEOS_MAKE_PATH)/tweak.mk
10 changes: 10 additions & 0 deletions control
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: dev.traurige.batterybuddy
Name: BatteryBuddy ⚡️
Depends: mobilesubstrate
Conflicts: love.litten.batterybuddy
Version: 1.0.3
Architecture: iphoneos-arm
Description: Battery indicator, but cute
Maintainer: Traurige
Author: Traurige & neilsardesai
Section: Tweaks
19 changes: 19 additions & 0 deletions layout/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

echo ""
echo " _, .--. "
echo " ( / ( '-. "
echo " .-=-. ) -. "
echo " / ( .' . \ "
echo " \ ( ' ,_) ) \_/ "
echo " (_ , /\ ,_/ "
echo " '--\ \-- "
echo " _\ _\ "
echo " \ \ "
echo " _\_\ "
echo " \\ "
echo " \\ "
echo " -.'. \.'.- "
echo ""
echo "Thank You For Installing BatteryBuddy 1.0.3 🤗"
echo ""
Binary file added layout/Library/BatteryBuddy/LockscreenCharger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/Library/BatteryBuddy/LockscreenHappy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/Library/BatteryBuddy/StatusBarCharger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/Library/BatteryBuddy/StatusBarHappy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/Library/BatteryBuddy/StatusBarNeutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added layout/Library/BatteryBuddy/StatusBarSad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48fe5d2

Please sign in to comment.