Skip to content

Commit 1bf814f

Browse files
committed
Kill app after 5 minutes
1 parent 1d91dfe commit 1bf814f

File tree

8 files changed

+53
-50
lines changed

8 files changed

+53
-50
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TARGET := iphone:clang:latest:11.0
22
INSTALL_TARGET_PROCESSES = TrollLEDs
33
ARCHS = arm64
4-
PACKAGE_VERSION = 1.4.0
4+
PACKAGE_VERSION = 1.5.0
55

66
include $(THEOS)/makefiles/common.mk
77

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Supported Devices
88

9-
- iOS 12 or higher (Tested on iOS 12, 14, 15, 16, 17), lower versions are not supported/tested
9+
- iOS 12 or higher, lower versions are not supported/tested
1010
- iPhone or iPad with multiple of different flashlight LEDs (e.g. amber and regular white)
1111
- Devices with single-color flashlight LED(s) are not supported, such as iPhone 4s and iPhone 5
1212
- **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)
@@ -39,22 +39,22 @@ Unlike [Amber tweak](https://github.com/PoomSmart/Amber), this app cannot force
3939

4040
## Limitation
4141

42+
### Exclusive Control
43+
4244
TrollLEDs utilizes the `mediaserverd`-exclusive `BWFigCaptureDeviceVendor` class to control the flashlight LEDs.
4345
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.
4446
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.
4547

46-
## Building
48+
### Battery Concern
4749

48-
As `.tipa`:
50+
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.
4951

50-
```sh
51-
make package FINALPACKAGE=1 PACKAGE_FORMAT=ipa
52-
```
52+
## Building
5353

54-
AS `.deb`:
54+
Build `.tipa` (sandboxed and unsandboxed) and `.deb` (rootful and rootless) with:
5555

5656
```sh
57-
make package FINALPACKAGE=1
57+
./build.sh
5858
```
5959

6060
## Future Plans

Resources/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
<string>iPhoneOS</string>
4545
</array>
4646
<key>CFBundleShortVersionString</key>
47-
<string>1.4.0</string>
47+
<string>1.5.0</string>
4848
<key>CFBundleVersion</key>
49-
<string>1.4.0</string>
49+
<string>1.5.0</string>
5050
<key>LSRequiresIPhoneOS</key>
5151
<true/>
5252
<key>MinimumOSVersion</key>

TLAppDelegate.m

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,41 @@
44
@implementation TLAppDelegate
55

66
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
7-
if (@available(iOS 13.0, *)) {
8-
return YES;
9-
}
10-
_window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
11-
_myViewController = [[TLRootViewController alloc] init];
12-
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey])
13-
_myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
14-
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
15-
_rootViewController.navigationBarHidden = YES;
16-
_window.rootViewController = _rootViewController;
17-
[_window makeKeyAndVisible];
18-
return YES;
7+
if (@available(iOS 13.0, *)) {
8+
return YES;
9+
}
10+
_window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
11+
_myViewController = [[TLRootViewController alloc] init];
12+
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey])
13+
_myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
14+
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
15+
_rootViewController.navigationBarHidden = YES;
16+
_window.rootViewController = _rootViewController;
17+
[_window makeKeyAndVisible];
18+
return YES;
1919
}
2020

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

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

29-
- (void)applicationWillResignActive:(UIApplication *)application {
30-
[_myViewController releaseStream];
29+
- (void)appWillEnterForeground:(UIApplication *)application {
30+
[application endBackgroundTask:UIBackgroundTaskInvalid];
3131
}
3232

33-
- (void)applicationDidBecomeActive:(UIApplication *)application {
34-
[_myViewController setupStream];
33+
- (void)appDidEnterBackground:(UIApplication *)application {
34+
__block UIBackgroundTaskIdentifier task;
35+
task = [application beginBackgroundTaskWithExpirationHandler:^ {
36+
[application endBackgroundTask:task];
37+
task = UIBackgroundTaskInvalid;
38+
}];
39+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
40+
exit(0);
41+
});
3542
}
3643

3744
@end

TLRootViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- (void)setupStream;
1010
- (void)releaseStream;
1111
@end
12+
13+
#define KILL_TIMEOUT 300

TLRootViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ - (NSString *)switchLabel {
153153
}
154154

155155
- (void)viewDidLoad {
156-
[super viewDidLoad];
156+
[super viewDidLoad];
157157

158158
NSString *currentError = _deviceManager.currentError;
159159
if (currentError) {

TLSceneDelegate.m

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@ - (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(U
1919
completionHandler(YES);
2020
}
2121

22-
// - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
23-
// [[UIApplication sharedApplication] endBackgroundTask:UIBackgroundTaskInvalid];
24-
// }
25-
26-
// - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
27-
// __block UIBackgroundTaskIdentifier task;
28-
// UIApplication *application = [UIApplication sharedApplication];
29-
// task = [application beginBackgroundTaskWithExpirationHandler:^ {
30-
// [application endBackgroundTask:task];
31-
// task = UIBackgroundTaskInvalid;
32-
// }];
33-
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
34-
// [_myViewController releaseStream];
35-
// [application endBackgroundTask:task];
36-
// task = UIBackgroundTaskInvalid;
37-
// });
38-
// }
22+
- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
23+
[[UIApplication sharedApplication] endBackgroundTask:UIBackgroundTaskInvalid];
24+
}
3925

40-
// - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
41-
// [_myViewController setupStream];
42-
// }
26+
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
27+
__block UIBackgroundTaskIdentifier task;
28+
UIApplication *application = [UIApplication sharedApplication];
29+
task = [application beginBackgroundTaskWithExpirationHandler:^ {
30+
[application endBackgroundTask:task];
31+
task = UIBackgroundTaskInvalid;
32+
}];
33+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
34+
exit(0);
35+
});
36+
}
4337

4438
@end

main.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#import "TLAppDelegate.h"
33

44
int main(int argc, char *argv[]) {
5-
NSString * appDelegateClassName;
5+
NSString *appDelegateClassName;
66
@autoreleasepool {
77
appDelegateClassName = NSStringFromClass([TLAppDelegate class]);
88
}

0 commit comments

Comments
 (0)