From 39ac903fa325e1563a9df4595d8b627f9bc4fbfc Mon Sep 17 00:00:00 2001 From: Lieven Dekeyser Date: Fri, 15 Mar 2024 19:41:46 +0100 Subject: [PATCH] Display a browser view when swiping down with 2 fingers + wrap downloaded files into an HFS disk image to allow opening them in the emulator --- Mini vMac/AppDelegate.h | 2 ++ Mini vMac/AppDelegate.m | 51 ++++++++++++++++++++++++++++++++++++-- Mini vMac/ViewController.m | 6 ++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index 1884bf0..34e12db 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -32,5 +32,7 @@ extern NSString *DocumentsChangedNotification; - (IBAction)showSettings:(id)sender; - (IBAction)showGestureHelp:(id)sender; +- (void)showBrowser; + @end diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index c2ac758..e2e1f64 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -7,16 +7,18 @@ // @import AVFoundation; +@import SafariServices; #import "AppDelegate.h" #import "SettingsViewController.h" #import "InsertDiskViewController.h" +#import "HFSDiskImage.h" static AppDelegate *sharedAppDelegate = nil; static NSObject *sharedEmulator = nil; NSString *DocumentsChangedNotification = @"documentsChanged"; -@interface AppDelegate () - +@interface AppDelegate () +@property (nonatomic, strong) SFSafariViewController * browser; @end @implementation AppDelegate @@ -281,7 +283,23 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { + [self.window.rootViewController dismissViewControllerAnimated:NO completion:nil]; + if (url.fileURL) { + + // FIXME: detect file type of imported file + // if archive first unarchive + // - if the resulting file(s) contain ROM files, copy to Documents + // - if the resulting file(s) contain disk images, copy those to Documents + // - if the resulting file(s) contain other files, embed them in an HFS Disk Image and copy that to Documents + + // FIXME: this is temporary code to test importing files into disk images + HFSDiskImage * tempDiskImage = [HFSDiskImage importFileIntoTemporaryDiskImage:url.path]; + if (tempDiskImage) { + [sharedEmulator insertDisk:tempDiskImage.path]; + return YES; + } + // opening file NSString *inboxPath = [self.documentsPath stringByAppendingPathComponent:@"Inbox"]; if ([url.path.stringByStandardizingPath hasPrefix:inboxPath]) { @@ -304,4 +322,33 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; return YES; } +- (void)showBrowser { + NSURL * url = [NSURL URLWithString:@"https://macintoshgarden.org"]; + if (url == nil) { + return; + } + + if (self.window.rootViewController.presentedViewController) { + __weak typeof(self) weakSelf = self; + [self.window.rootViewController dismissViewControllerAnimated:NO completion:^{ + [weakSelf showBrowser]; + }]; + return; + } + + SFSafariViewController * vc = self.browser; + if (vc == nil) { + vc = [[SFSafariViewController alloc] initWithURL:url]; + vc.modalPresentationStyle = UIModalPresentationPageSheet; + vc.delegate = self; + self.browser = vc; + } + + [self.window.rootViewController presentViewController:vc animated:YES completion:nil]; +} + +- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller { + [self.window.rootViewController dismissViewControllerAnimated:YES completion:nil]; +} + @end diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index f4a1384..1dabc63 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -281,7 +281,11 @@ API_AVAILABLE(ios(13.4)) } - (void)hideKeyboard:(id)sender { - [self setKeyboardVisible:NO animated:YES]; + if (self.keyboardVisible) { + [self setKeyboardVisible:NO animated:YES]; + } else { + [[AppDelegate sharedInstance] showBrowser]; + } } - (void)setKeyboardVisible:(BOOL)visible animated:(BOOL)animated {