mirror of
https://github.com/ish-app/ish.git
synced 2026-01-25 14:06:40 +00:00
Most of the code assumed it was called on the main thread, but we need to make this explicit now because preference updates will be driven off the UI as well.
151 lines
6.4 KiB
Objective-C
151 lines
6.4 KiB
Objective-C
//
|
|
// AboutViewController.m
|
|
// iSH
|
|
//
|
|
// Created by Theodore Dubois on 9/23/18.
|
|
//
|
|
|
|
#import "AboutViewController.h"
|
|
#import "AppDelegate.h"
|
|
#import "CurrentRoot.h"
|
|
#import "AppGroup.h"
|
|
#import "UserPreferences.h"
|
|
#import "UIApplication+OpenURL.h"
|
|
#import "NSObject+SaneKVO.h"
|
|
|
|
@interface AboutViewController ()
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *capsLockMappingCell;
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *themeCell;
|
|
@property (weak, nonatomic) IBOutlet UISwitch *disableDimmingSwitch;
|
|
@property (weak, nonatomic) IBOutlet UITextField *launchCommandField;
|
|
@property (weak, nonatomic) IBOutlet UITextField *bootCommandField;
|
|
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *sendFeedback;
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *openGithub;
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *openTwitter;
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *openDiscord;
|
|
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *upgradeApkCell;
|
|
@property (weak, nonatomic) IBOutlet UILabel *upgradeApkLabel;
|
|
@property (weak, nonatomic) IBOutlet UIView *upgradeApkBadge;
|
|
@property (weak, nonatomic) IBOutlet UITableViewCell *exportContainerCell;
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel *versionLabel;
|
|
|
|
@end
|
|
|
|
@implementation AboutViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self _updateUI];
|
|
if (self.recoveryMode) {
|
|
self.includeDebugPanel = YES;
|
|
self.navigationItem.title = @"Recovery Mode";
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Exit"
|
|
style:UIBarButtonItemStyleDone
|
|
target:self
|
|
action:@selector(exitRecovery:)];
|
|
self.navigationItem.leftBarButtonItem = nil;
|
|
}
|
|
_versionLabel.text = [NSString stringWithFormat:@"iSH %@ (Build %@)",
|
|
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
|
|
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
|
|
|
[UserPreferences.shared observe:@[@"capsLockMapping", @"fontSize", @"launchCommand", @"bootCommand"]
|
|
options:0 owner:self usingBlock:^(typeof(self) self) {
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self _updateUI];
|
|
});
|
|
}];
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_updateUI) name:FsUpdatedNotification object:nil];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
[self _updateUI];
|
|
}
|
|
|
|
- (IBAction)dismiss:(id)sender {
|
|
[self dismissViewControllerAnimated:self completion:nil];
|
|
}
|
|
|
|
- (void)exitRecovery:(id)sender {
|
|
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"recovery"];
|
|
exit(0);
|
|
}
|
|
|
|
- (void)_updateUI {
|
|
NSAssert(NSThread.isMainThread, @"This method needs to be called on the main thread");
|
|
UserPreferences *prefs = UserPreferences.shared;
|
|
self.themeCell.detailTextLabel.text = prefs.theme.presetName;
|
|
self.disableDimmingSwitch.on = UserPreferences.shared.shouldDisableDimming;
|
|
self.launchCommandField.text = [UserPreferences.shared.launchCommand componentsJoinedByString:@" "];
|
|
self.bootCommandField.text = [UserPreferences.shared.bootCommand componentsJoinedByString:@" "];
|
|
|
|
self.upgradeApkCell.userInteractionEnabled = FsNeedsRepositoryUpdate();
|
|
self.upgradeApkLabel.enabled = FsNeedsRepositoryUpdate();
|
|
self.upgradeApkBadge.hidden = !FsNeedsRepositoryUpdate();
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
|
|
if (cell == self.sendFeedback) {
|
|
[UIApplication openURL:@"mailto:tblodt@icloud.com?subject=Feedback%20for%20iSH"];
|
|
} else if (cell == self.openGithub) {
|
|
[UIApplication openURL:@"https://github.com/ish-app/ish"];
|
|
} else if (cell == self.openTwitter) {
|
|
[UIApplication openURL:@"https://twitter.com/tblodt"];
|
|
} else if (cell == self.openDiscord) {
|
|
[UIApplication openURL:@"https://discord.gg/HFAXj44"];
|
|
} else if (cell == self.exportContainerCell) {
|
|
// copy the files to the app container so they can be extracted from iTunes file sharing
|
|
NSURL *container = ContainerURL();
|
|
NSURL *documents = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
|
|
[NSFileManager.defaultManager removeItemAtURL:[documents URLByAppendingPathComponent:@"roots copy"] error:nil];
|
|
[NSFileManager.defaultManager copyItemAtURL:[container URLByAppendingPathComponent:@"roots"]
|
|
toURL:[documents URLByAppendingPathComponent:@"roots copy"]
|
|
error:nil];
|
|
}
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
}
|
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
|
|
if (section == 1) { // filesystems / upgrade
|
|
if (!FsIsManaged()) {
|
|
return @"The current filesystem is not managed by iSH.";
|
|
} else if (!FsNeedsRepositoryUpdate()) {
|
|
return [NSString stringWithFormat:@"The current filesystem is using %s, which is the latest version.", NEWEST_APK_VERSION];
|
|
} else {
|
|
return [NSString stringWithFormat:@"An upgrade to %s is available.", NEWEST_APK_VERSION];
|
|
}
|
|
}
|
|
return [super tableView:tableView titleForFooterInSection:section];
|
|
}
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
NSInteger sections = [super numberOfSectionsInTableView:tableView];
|
|
if (!self.includeDebugPanel)
|
|
sections--;
|
|
return sections;
|
|
}
|
|
|
|
- (IBAction)disableDimmingChanged:(id)sender {
|
|
UserPreferences.shared.shouldDisableDimming = self.disableDimmingSwitch.on;
|
|
}
|
|
|
|
- (IBAction)textBoxSubmit:(id)sender {
|
|
[sender resignFirstResponder];
|
|
}
|
|
|
|
- (IBAction)launchCommandChanged:(id)sender {
|
|
UserPreferences.shared.launchCommand = [self.launchCommandField.text componentsSeparatedByString:@" "];
|
|
}
|
|
|
|
- (IBAction)bootCommandChanged:(id)sender {
|
|
UserPreferences.shared.bootCommand = [self.bootCommandField.text componentsSeparatedByString:@" "];
|
|
}
|
|
|
|
@end
|