Skip to content

Commit

Permalink
Kill app after 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Jan 23, 2024
1 parent 1d91dfe commit 1bf814f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET := iphone:clang:latest:11.0
INSTALL_TARGET_PROCESSES = TrollLEDs
ARCHS = arm64
PACKAGE_VERSION = 1.4.0
PACKAGE_VERSION = 1.5.0

include $(THEOS)/makefiles/common.mk

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Supported Devices

- iOS 12 or higher (Tested on iOS 12, 14, 15, 16, 17), lower versions are not supported/tested
- iOS 12 or higher, lower versions are not supported/tested
- iPhone or iPad with multiple of different flashlight LEDs (e.g. amber and regular white)
- Devices with single-color flashlight LED(s) are not supported, such as iPhone 4s and iPhone 5
- **iPhone 14 series and higher are not supported**, as [Apple has completely redesigned the flashlight LEDs](https://appleinsider.com/articles/22/09/20/how-iphone-14-pro-adaptive-true-tone-flash-creates-perfect-light-for-your-photos)
Expand Down Expand Up @@ -39,22 +39,22 @@ Unlike [Amber tweak](https://github.com/PoomSmart/Amber), this app cannot force

## Limitation

### Exclusive Control

TrollLEDs utilizes the `mediaserverd`-exclusive `BWFigCaptureDeviceVendor` class to control the flashlight LEDs.
This creates an instance of `BWFigCaptureDevice` (or `OpaqueFigCaptureDeviceRef`). There can only be one instance at a time, so if there is another app that creates it (i.e., `mediaserverd`), TrollLEDs will not be able to control the flashlight LEDs.
This is why there is a switch at the top of the app to lock the flashlight LEDs to TrollLEDs only. If you want to use the LEDs (or use the Camera app) from somewhere else, you can either turn off the switch (and wait few seconds) or kill the app.

## Building
### Battery Concern

As `.tipa`:
As long as TrollLEDs app is running, the flashlight device connection will be kept alive. This may cause battery drain, as reported by some users. To mitigate this issue, the app will automatically kill itself after 5 minutes of inactivity.

```sh
make package FINALPACKAGE=1 PACKAGE_FORMAT=ipa
```
## Building

AS `.deb`:
Build `.tipa` (sandboxed and unsandboxed) and `.deb` (rootful and rootless) with:

```sh
make package FINALPACKAGE=1
./build.sh
```

## Future Plans
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<string>iPhoneOS</string>
</array>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>1.5.0</string>
<key>CFBundleVersion</key>
<string>1.4.0</string>
<string>1.5.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
Expand Down
41 changes: 24 additions & 17 deletions TLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,41 @@
@implementation TLAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13.0, *)) {
return YES;
}
_window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
_myViewController = [[TLRootViewController alloc] init];
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey])
_myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
_rootViewController.navigationBarHidden = YES;
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
return YES;
if (@available(iOS 13.0, *)) {
return YES;
}
_window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
_myViewController = [[TLRootViewController alloc] init];
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey])
_myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
_rootViewController.navigationBarHidden = YES;
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
return YES;
}

- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
[_myViewController handleShortcutAction:shortcutItem.type];
[_myViewController handleShortcutAction:shortcutItem.type];
}

- (void)applicationWillResignActive:(UIApplication *)application {
[_myViewController releaseStream];
- (void)appWillEnterForeground:(UIApplication *)application {
[application endBackgroundTask:UIBackgroundTaskInvalid];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
[_myViewController setupStream];
- (void)appDidEnterBackground:(UIApplication *)application {
__block UIBackgroundTaskIdentifier task;
task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask:task];
task = UIBackgroundTaskInvalid;
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
exit(0);
});
}

@end
2 changes: 2 additions & 0 deletions TLRootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
- (void)setupStream;
- (void)releaseStream;
@end

#define KILL_TIMEOUT 300
2 changes: 1 addition & 1 deletion TLRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (NSString *)switchLabel {
}

- (void)viewDidLoad {
[super viewDidLoad];
[super viewDidLoad];

NSString *currentError = _deviceManager.currentError;
if (currentError) {
Expand Down
34 changes: 14 additions & 20 deletions TLSceneDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@ - (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(U
completionHandler(YES);
}

// - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
// [[UIApplication sharedApplication] endBackgroundTask:UIBackgroundTaskInvalid];
// }

// - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
// __block UIBackgroundTaskIdentifier task;
// UIApplication *application = [UIApplication sharedApplication];
// task = [application beginBackgroundTaskWithExpirationHandler:^ {
// [application endBackgroundTask:task];
// task = UIBackgroundTaskInvalid;
// }];
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// [_myViewController releaseStream];
// [application endBackgroundTask:task];
// task = UIBackgroundTaskInvalid;
// });
// }
- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
[[UIApplication sharedApplication] endBackgroundTask:UIBackgroundTaskInvalid];
}

// - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
// [_myViewController setupStream];
// }
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
__block UIBackgroundTaskIdentifier task;
UIApplication *application = [UIApplication sharedApplication];
task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask:task];
task = UIBackgroundTaskInvalid;
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
exit(0);
});
}

@end
2 changes: 1 addition & 1 deletion main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "TLAppDelegate.h"

int main(int argc, char *argv[]) {
NSString * appDelegateClassName;
NSString *appDelegateClassName;
@autoreleasepool {
appDelegateClassName = NSStringFromClass([TLAppDelegate class]);
}
Expand Down

0 comments on commit 1bf814f

Please sign in to comment.