mirror of
https://github.com/ish-app/ish.git
synced 2025-12-08 17:36:02 +00:00
166 lines
6.8 KiB
Objective-C
166 lines
6.8 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 "iOSFS.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 *openFediverse;
|
|
@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 UITableViewCell *resetMountsCell;
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel *versionLabel;
|
|
|
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *saddamHussein;
|
|
|
|
@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];
|
|
}
|
|
|
|
- (void)updateViewConstraints {
|
|
self.saddamHussein.constant = UIEdgeInsetsInsetRect(self.tableView.frame, self.tableView.adjustedContentInset).size.height;
|
|
[super updateViewConstraints];
|
|
}
|
|
|
|
- (IBAction)dismiss:(id)sender {
|
|
[self dismissViewControllerAnimated:self completion:nil];
|
|
}
|
|
|
|
- (void)exitRecovery:(id)sender {
|
|
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"recovery"];
|
|
exit(0);
|
|
}
|
|
|
|
- (void)_updateUI:(NSNotification *)notification {
|
|
[self _updateUI];
|
|
}
|
|
|
|
- (void)_updateUI {
|
|
NSAssert(NSThread.isMainThread, @"This method needs to be called on the main thread");
|
|
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.openFediverse) {
|
|
[UIApplication openURL:@"https://publ.ish.app/ish"];
|
|
} 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];
|
|
} else if (cell == self.resetMountsCell) {
|
|
#if !ISH_LINUX
|
|
iosfs_clear_all_bookmarks();
|
|
#endif
|
|
}
|
|
[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.", CURRENT_APK_VERSION_STRING];
|
|
} else {
|
|
return [NSString stringWithFormat:@"An upgrade to %s is available.", CURRENT_APK_VERSION_STRING];
|
|
}
|
|
}
|
|
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
|