mirror of
https://github.com/ish-app/ish.git
synced 2026-01-25 14:06:40 +00:00
102 lines
3.3 KiB
Objective-C
102 lines
3.3 KiB
Objective-C
//
|
|
// AppDelegate.m
|
|
// iSH
|
|
//
|
|
// Created by Theodore Dubois on 10/17/17.
|
|
//
|
|
|
|
#include <ndbm.h>
|
|
#import "AppDelegate.h"
|
|
#import "TerminalViewController.h"
|
|
#include "kernel/init.h"
|
|
#include "kernel/calls.h"
|
|
|
|
@interface AppDelegate ()
|
|
|
|
@end
|
|
|
|
static void ios_handle_exit(int code) {
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:ISHExitedNotification object:nil];
|
|
}
|
|
|
|
@implementation AppDelegate
|
|
|
|
- (int)startThings {
|
|
NSFileManager *manager = NSFileManager.defaultManager;
|
|
NSURL *documents = [manager URLsForDirectory:NSDocumentDirectory
|
|
inDomains:NSUserDomainMask][0];
|
|
NSURL *alpineRoot = [documents URLByAppendingPathComponent:@"alpine"];
|
|
if (![manager fileExistsAtPath:alpineRoot.path]) {
|
|
NSURL *alpineMaster = [NSBundle.mainBundle URLForResource:@"alpine" withExtension:nil];
|
|
NSError *error = nil;
|
|
[manager copyItemAtURL:alpineMaster toURL:alpineRoot error:&error];
|
|
if (error != nil) {
|
|
NSLog(@"%@", error);
|
|
exit(1);
|
|
}
|
|
}
|
|
alpineRoot = [alpineRoot URLByAppendingPathComponent:@"data"];
|
|
int err = mount_root(&fakefs, alpineRoot.fileSystemRepresentation);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
create_first_process();
|
|
char *program = "/bin/login";
|
|
char *argv[] = {program, NULL};
|
|
char *envp[] = {NULL};
|
|
err = sys_execve(program, argv, envp);
|
|
if (err < 0)
|
|
return err;
|
|
err = create_stdio(ios_tty_driver);
|
|
if (err < 0)
|
|
return err;
|
|
exit_hook = ios_handle_exit;
|
|
start_thread(current);
|
|
return 0;
|
|
}
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
int err = [self startThings];
|
|
if (err < 0) {
|
|
NSLog(@"failed with code %d", err);
|
|
}
|
|
return YES;
|
|
}
|
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
|
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
|
}
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
// sync filesystem database
|
|
struct mount *mount = mounts;
|
|
while (mount) {
|
|
if (mount->fs == &fakefs) {
|
|
dbm_close(mount->data);
|
|
mount->data = NULL;
|
|
}
|
|
mount = mount->next;
|
|
}
|
|
}
|
|
|
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
|
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
|
}
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
|
}
|
|
|
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
|
}
|
|
|
|
|
|
@end
|
|
|
|
NSString *const ISHExitedNotification = @"ISHExitedNotification";
|