Skip to content

Commit

Permalink
Add a one-time message if you update from a version without /ish/apk
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Nov 29, 2020
1 parent b162e68 commit 983caeb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

+ (int)bootError;

+ (void)maybePresentStartupMessageOnViewController:(UIViewController *)vc;

@end

extern NSString *const ProcessExitedNotification;
32 changes: 28 additions & 4 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "AboutViewController.h"
#import "AppDelegate.h"
#import "AppGroup.h"
#import "APKFilesystem.h"
#import "iOSFS.h"
#import "SceneDelegate.h"
#import "PasteboardDevice.h"
Expand All @@ -20,7 +21,7 @@
#import "Roots.h"
#import "TerminalViewController.h"
#import "UserPreferences.h"
#import "APKFilesystem.h"
#import "UIApplication+OpenURL.h"
#include "kernel/init.h"
#include "kernel/calls.h"
#include "fs/dyndev.h"
Expand Down Expand Up @@ -58,6 +59,10 @@ static void ios_handle_die(const char *msg) {
pthread_setname_np(newName.UTF8String);
}

static int bootError;
static BOOL has_ish_version;
static NSString *const kSkipStartupMessage = @"Skip Startup Message";

@implementation AppDelegate

- (int)boot {
Expand All @@ -76,7 +81,7 @@ - (int)boot {
return err;

// /ish/version is the last ish version that opened this root. Not used for anything yet, but could be used to know whether to change the root if needed in a future update.
BOOL has_ish_version = NO;
has_ish_version = NO;
struct fd *ish_version = generic_open("/ish/version", O_WRONLY_|O_CREAT_|O_TRUNC_, 0644);
if (!IS_ERR(ish_version)) {
has_ish_version = YES;
Expand All @@ -91,6 +96,7 @@ - (int)boot {
do_mount(&apkfs, "apk", "/ish/apk", "", 0);
}


// create some device nodes
// this will do nothing if they already exist
generic_mknodat(AT_PWD, "/dev/tty1", S_IFCHR|0666, dev_make(TTY_CONSOLE_MAJOR, 1));
Expand Down Expand Up @@ -196,12 +202,30 @@ - (void)configureDns {
}
}

static int bootError;

+ (int)bootError {
return bootError;
}

+ (void)maybePresentStartupMessageOnViewController:(UIViewController *)vc {
if ([NSUserDefaults.standardUserDefaults integerForKey:kSkipStartupMessage] >= 1)
return;
if (!has_ish_version) {
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];
[alert addAction:[UIAlertAction actionWithTitle:@"Show me how"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
[UIApplication openURL:@"https://go.ish.app/get-apk"];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Don't show again"
style:UIAlertActionStyleDefault
handler:nil]];
[vc presentViewController:alert animated:YES completion:nil];
}
[NSUserDefaults.standardUserDefaults setInteger:1 forKey:kSkipStartupMessage];
}

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions {
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
if ([defaults boolForKey:@"hail mary"]) {
Expand Down
5 changes: 5 additions & 0 deletions app/TerminalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ - (void)awakeFromNib {
object:nil];
}

- (void)viewDidAppear:(BOOL)animated {
[AppDelegate maybePresentStartupMessageOnViewController:self];
[super viewDidAppear:animated];
}

- (void)startNewSession {
int err = [self startSession];
if (err < 0) {
Expand Down

0 comments on commit 983caeb

Please sign in to comment.