diff --git a/app/AboutViewController.m b/app/AboutViewController.m index aa109848..e8851b90 100644 --- a/app/AboutViewController.m +++ b/app/AboutViewController.m @@ -5,10 +5,12 @@ // Created by Theodore Dubois on 9/23/18. // -#import "UIApplication+OpenURL.h" #import "AboutViewController.h" -#import "UserPreferences.h" +#import "AppDelegate.h" +#import "CurrentRoot.h" #import "AppGroup.h" +#import "UserPreferences.h" +#import "UIApplication+OpenURL.h" #import "NSObject+SaneKVO.h" @interface AboutViewController () @@ -23,6 +25,9 @@ @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; @@ -33,7 +38,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - [self _updatePreferenceUI]; + [self _updateUI]; if (self.recoveryMode) { self.includeDebugPanel = YES; self.navigationItem.title = @"Recovery Mode"; @@ -49,8 +54,14 @@ [UserPreferences.shared observe:@[@"capsLockMapping", @"fontSize", @"launchCommand", @"bootCommand"] options:0 owner:self usingBlock:^(typeof(self) self) { - [self _updatePreferenceUI]; + [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 { @@ -62,12 +73,17 @@ exit(0); } -- (void)_updatePreferenceUI { +- (void)_updateUI { 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 { @@ -92,6 +108,19 @@ [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) diff --git a/app/AppDelegate.h b/app/AppDelegate.h index d644a340..1b69624b 100644 --- a/app/AppDelegate.h +++ b/app/AppDelegate.h @@ -25,3 +25,4 @@ extern NSString *const ProcessExitedNotification; #else extern NSString *const KernelPanicNotification; #endif + diff --git a/app/AppDelegate.m b/app/AppDelegate.m index e2a78bdc..688cd6bb 100644 --- a/app/AppDelegate.m +++ b/app/AppDelegate.m @@ -12,6 +12,7 @@ #import "AboutViewController.h" #import "AppDelegate.h" #import "AppGroup.h" +#import "CurrentRoot.h" #import "iOSFS.h" #import "SceneDelegate.h" #import "PasteboardDevice.h" @@ -70,7 +71,6 @@ void ReportPanic(const char *message, void (^completion)(void)) { #endif static int bootError; -static int fs_ish_version; static NSString *const kSkipStartupMessage = @"Skip Startup Message"; @implementation AppDelegate @@ -91,44 +91,7 @@ static NSString *const kSkipStartupMessage = @"Skip Startup Message"; if (err < 0) return err; - // /ish/version is the last ish version that opened this root. Used to migrate the filesystem. - struct fd *ish_version_fd = generic_open("/ish/version", O_RDONLY_, 0); - if (!IS_ERR(ish_version_fd)) { - char buf[100]; - ssize_t n = ish_version_fd->ops->read(ish_version_fd, buf, sizeof(buf)); - if (n < 0) - return (int) n; - NSString *version = [[NSString alloc] initWithBytesNoCopy:buf length:n encoding:NSUTF8StringEncoding freeWhenDone:NO]; - version = [version stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]; - fs_ish_version = version.intValue; - fd_close(ish_version_fd); - - NSURL *repositories = [NSBundle.mainBundle URLForResource:@"repositories" withExtension:@"txt"]; - if (repositories != nil) { - NSMutableData *repositoriesData = [@"# This file contains pinned repositories managed by iSH. If the /ish directory\n" - @"# exists, iSH uses the metadata stored in it to keep this file up to date (by\n" - @"# overwriting the contents on boot.)\n" dataUsingEncoding:NSUTF8StringEncoding].mutableCopy; - [repositoriesData appendData:[NSData dataWithContentsOfURL:repositories]]; - struct fd *repositories_fd = generic_open("/etc/apk/repositories", O_WRONLY_|O_TRUNC_, 0); - if (!IS_ERR(repositories_fd)) { - repositories_fd->ops->write(repositories_fd, repositoriesData.bytes, repositoriesData.length); - fd_close(repositories_fd); - } - } - generic_rmdirat(AT_PWD, "/ish/apk"); - - NSString *currentVersion = NSBundle.mainBundle.infoDictionary[(__bridge NSString *) kCFBundleVersionKey]; - if (currentVersion.intValue > fs_ish_version) { - fs_ish_version = currentVersion.intValue; - ish_version_fd = generic_open("/ish/version", O_WRONLY_|O_TRUNC_, 0644); - if (!IS_ERR(ish_version_fd)) { - NSString *file = [NSString stringWithFormat:@"%@\n", currentVersion]; - ish_version_fd->ops->write(ish_version_fd, file.UTF8String, [file lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); - fd_close(ish_version_fd); - } - } - - } + FsInitialize(); // create some device nodes // this will do nothing if they already exist @@ -257,7 +220,7 @@ static NSString *const kSkipStartupMessage = @"Skip Startup Message"; + (void)maybePresentStartupMessageOnViewController:(UIViewController *)vc { if ([NSUserDefaults.standardUserDefaults integerForKey:kSkipStartupMessage] >= 1) return; - if (fs_ish_version == 0) { + if (!FsIsManaged()) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Install iSH’s built-in APK?" message:@"iSH now includes the APK package manager, but it must be manually activated." preferredStyle:UIAlertControllerStyleAlert]; diff --git a/app/Base.lproj/About.storyboard b/app/Base.lproj/About.storyboard index cd79b72e..500877bd 100644 --- a/app/Base.lproj/About.storyboard +++ b/app/Base.lproj/About.storyboard @@ -1,9 +1,9 @@ - + - + @@ -19,7 +19,7 @@