2016-04-27 20:52:28 +00:00
|
|
|
//
|
|
|
|
// AppDelegate.m
|
|
|
|
// Mini vMac
|
|
|
|
//
|
|
|
|
// Created by Jesús A. Álvarez on 27/04/2016.
|
2018-04-28 10:12:43 +00:00
|
|
|
// Copyright © 2016-2018 namedfork. All rights reserved.
|
2016-04-27 20:52:28 +00:00
|
|
|
//
|
|
|
|
|
2016-06-06 14:09:23 +00:00
|
|
|
@import AVFoundation;
|
2016-04-27 20:52:28 +00:00
|
|
|
#import "AppDelegate.h"
|
2016-05-11 21:04:49 +00:00
|
|
|
#import "SettingsViewController.h"
|
|
|
|
#import "InsertDiskViewController.h"
|
2024-02-10 11:15:01 +00:00
|
|
|
#import "ViewController.h"
|
2016-05-01 17:05:36 +00:00
|
|
|
|
|
|
|
static AppDelegate *sharedAppDelegate = nil;
|
2016-05-28 11:01:13 +00:00
|
|
|
static NSObject<Emulator> *sharedEmulator = nil;
|
2016-06-06 17:42:10 +00:00
|
|
|
NSString *DocumentsChangedNotification = @"documentsChanged";
|
2016-04-27 20:52:28 +00:00
|
|
|
|
2020-06-22 19:07:01 +00:00
|
|
|
@interface AppDelegate () <BTCMouseDelegate>
|
2016-04-27 20:52:28 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AppDelegate
|
2016-05-14 13:15:37 +00:00
|
|
|
{
|
|
|
|
}
|
2016-04-27 20:52:28 +00:00
|
|
|
|
2016-05-01 17:05:36 +00:00
|
|
|
+ (instancetype)sharedInstance {
|
|
|
|
return sharedAppDelegate;
|
|
|
|
}
|
2016-04-27 20:52:28 +00:00
|
|
|
|
2016-05-28 11:01:13 +00:00
|
|
|
+ (id<Emulator>)sharedEmulator {
|
|
|
|
return sharedEmulator;
|
|
|
|
}
|
|
|
|
|
2016-04-27 20:52:28 +00:00
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2016-05-01 21:44:47 +00:00
|
|
|
sharedAppDelegate = self;
|
2016-05-28 22:43:03 +00:00
|
|
|
[self initDefaults];
|
2016-11-21 22:10:46 +00:00
|
|
|
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
|
2020-09-25 20:13:52 +00:00
|
|
|
[self loadAndStartEmulator];
|
2016-12-04 19:05:24 +00:00
|
|
|
|
|
|
|
if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) {
|
|
|
|
[application btcMouseSetRawMode:YES];
|
|
|
|
[application btcMouseSetDelegate:self];
|
|
|
|
}
|
2018-04-28 09:49:05 +00:00
|
|
|
|
|
|
|
// populate documents directory so it shows up in Files
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:self.userKeyboardLayoutsPath withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
|
|
2016-05-14 12:04:18 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initDefaults {
|
2016-05-14 11:01:02 +00:00
|
|
|
// default settings
|
2016-05-14 13:36:50 +00:00
|
|
|
NSDictionary *layoutForLanguage = @{@"en": @"British.nfkeyboardlayout",
|
|
|
|
@"es": @"Spanish.nfkeyboardlayout",
|
|
|
|
@"en-US": @"US.nfkeyboardlayout"};
|
|
|
|
NSString *firstLanguage = [NSBundle preferredLocalizationsFromArray:layoutForLanguage.allKeys].firstObject;
|
2016-05-14 12:04:18 +00:00
|
|
|
NSDictionary *defaultValues = @{@"trackpad": @([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad),
|
2016-05-28 11:01:13 +00:00
|
|
|
@"keyboardLayout": layoutForLanguage[firstLanguage],
|
2016-06-06 14:09:23 +00:00
|
|
|
@"machine": @"MacPlus4M",
|
|
|
|
@"speedValue": @(sharedEmulator.initialSpeed),
|
|
|
|
@"runInBackground": @NO,
|
2017-11-30 19:09:08 +00:00
|
|
|
@"autoSlow": @(sharedEmulator.initialAutoSlow),
|
2020-06-23 17:19:28 +00:00
|
|
|
@"screenFilter": kCAFilterLinear,
|
2022-05-26 17:11:38 +00:00
|
|
|
@"autoShowGestureHelp": @YES,
|
|
|
|
@"recentDisks": @[]
|
2016-05-14 12:04:18 +00:00
|
|
|
};
|
2016-05-14 13:36:50 +00:00
|
|
|
|
2016-05-14 12:04:18 +00:00
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
[defaults registerDefaults:defaultValues];
|
|
|
|
[defaults addObserver:self forKeyPath:@"speedValue" options:0 context:NULL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
|
|
|
|
if (object == [NSUserDefaults standardUserDefaults]) {
|
2016-06-06 14:09:23 +00:00
|
|
|
NSUserDefaults *defaults = object;
|
2016-05-14 12:04:18 +00:00
|
|
|
if ([keyPath isEqualToString:@"speedValue"]) {
|
2016-06-06 14:09:23 +00:00
|
|
|
sharedEmulator.speed = [defaults integerForKey:@"speedValue"];
|
|
|
|
} else if ([keyPath isEqualToString:@"autoSlow"]) {
|
|
|
|
sharedEmulator.autoSlow = [defaults integerForKey:@"autoSlow"];
|
2016-05-14 12:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-27 20:52:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:34:08 +00:00
|
|
|
- (NSString*)emulatorBundlesPath {
|
|
|
|
return [NSBundle mainBundle].privateFrameworksPath;
|
|
|
|
}
|
|
|
|
|
2016-05-28 20:20:55 +00:00
|
|
|
- (NSArray<NSBundle*>*)emulatorBundles {
|
2020-06-22 12:34:08 +00:00
|
|
|
NSArray<NSString*> *names = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.emulatorBundlesPath error:NULL];
|
2016-05-28 11:01:13 +00:00
|
|
|
NSMutableArray *emulatorBundles = [NSMutableArray arrayWithCapacity:names.count];
|
|
|
|
for (NSString *name in [names pathsMatchingExtensions:@[@"mnvm"]]) {
|
2020-06-22 12:34:08 +00:00
|
|
|
NSBundle *bundle = [NSBundle bundleWithPath:[self.emulatorBundlesPath stringByAppendingPathComponent:name]];
|
2016-05-28 11:01:13 +00:00
|
|
|
[emulatorBundles addObject:bundle];
|
|
|
|
}
|
|
|
|
return emulatorBundles;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)loadEmulator:(NSString*)name {
|
|
|
|
NSString *emulatorBundleName = [name stringByAppendingPathExtension:@"mnvm"];
|
2020-06-22 12:34:08 +00:00
|
|
|
NSString *emulatorBundlePath = [self.emulatorBundlesPath stringByAppendingPathComponent:emulatorBundleName];
|
2016-05-28 11:01:13 +00:00
|
|
|
NSBundle *emulatorBundle = [NSBundle bundleWithPath:emulatorBundlePath];
|
|
|
|
[emulatorBundle load];
|
|
|
|
sharedEmulator = [[emulatorBundle principalClass] new];
|
2024-02-09 15:06:37 +00:00
|
|
|
sharedEmulator.rootViewController = self.window.rootViewController;
|
|
|
|
sharedEmulator.showAlert = ^(NSString *title, NSString *message) {
|
|
|
|
[self showAlertWithTitle:title message:message];
|
|
|
|
};
|
2016-05-28 11:01:13 +00:00
|
|
|
sharedEmulator.dataPath = self.documentsPath;
|
2024-02-10 11:15:01 +00:00
|
|
|
#if defined(TARGET_OS_VISION) && TARGET_OS_VISION == 1
|
|
|
|
[ViewController adjustToScreenSize];
|
|
|
|
#endif
|
2016-05-28 11:01:13 +00:00
|
|
|
return sharedEmulator != nil;
|
|
|
|
}
|
|
|
|
|
2020-09-25 20:13:52 +00:00
|
|
|
- (void)loadAndStartEmulator {
|
2020-09-24 22:29:30 +00:00
|
|
|
[self willChangeValueForKey:@"sharedEmulator"];
|
2020-09-25 20:13:52 +00:00
|
|
|
if (sharedEmulator) {
|
|
|
|
NSBundle *bundle = sharedEmulator.bundle;
|
|
|
|
id<Emulator> oldEmulator = sharedEmulator;
|
|
|
|
sharedEmulator = nil;
|
|
|
|
[oldEmulator shutdown];
|
|
|
|
[bundle unload];
|
|
|
|
}
|
2020-09-24 22:29:30 +00:00
|
|
|
if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) {
|
|
|
|
[self loadEmulator:@"MacPlus4M"];
|
|
|
|
}
|
|
|
|
[self didChangeValueForKey:@"sharedEmulator"];
|
2020-09-25 20:13:52 +00:00
|
|
|
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([defaults integerForKey:@"speedValue"] > sharedEmulator.initialSpeed) {
|
|
|
|
[defaults setValue:@(sharedEmulator.initialSpeed) forKey:@"speedValue"];
|
|
|
|
} else {
|
|
|
|
sharedEmulator.speed = [defaults integerForKey:@"speedValue"];
|
|
|
|
}
|
2020-09-24 22:29:30 +00:00
|
|
|
[sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id<Emulator>)sharedEmulator {
|
|
|
|
return sharedEmulator;
|
|
|
|
}
|
|
|
|
|
2016-04-27 20:52:28 +00:00
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
2016-06-06 14:09:23 +00:00
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
[defaults synchronize];
|
|
|
|
if ([defaults boolForKey:@"runInBackground"]) {
|
|
|
|
// slow down to 1x when in background
|
|
|
|
sharedEmulator.speed = EmulatorSpeed1x;
|
|
|
|
} else {
|
|
|
|
sharedEmulator.running = NO;
|
|
|
|
}
|
2016-05-28 11:01:13 +00:00
|
|
|
if (sharedEmulator.anyDiskInserted == NO) {
|
2016-05-27 18:33:09 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2016-04-27 20:52:28 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 19:05:24 +00:00
|
|
|
- (void)handleEventWithMove:(CGPoint)move andWheel:(float)wheel andPan:(float)pan andButtons:(int)buttons {
|
|
|
|
[sharedEmulator moveMouseX:move.x/2.0 Y:move.y/2.0];
|
|
|
|
[sharedEmulator setMouseButton:buttons == 1];
|
|
|
|
}
|
|
|
|
|
2016-04-27 20:52:28 +00:00
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
2016-06-06 14:09:23 +00:00
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
if (sharedEmulator.running) {
|
|
|
|
sharedEmulator.speed = [defaults integerForKey:@"speedValue"];
|
|
|
|
} else {
|
|
|
|
sharedEmulator.running = YES;
|
|
|
|
}
|
2016-05-07 18:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
|
|
|
|
if (![NSThread isMainThread]) {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self showAlertWithTitle:title message:message];
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2024-02-09 15:06:37 +00:00
|
|
|
BOOL wasRunning = sharedEmulator.isRunning;
|
2020-09-30 20:40:32 +00:00
|
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
2024-02-09 15:06:37 +00:00
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
[sharedEmulator setRunning:wasRunning];
|
|
|
|
}]];
|
2020-09-30 20:40:32 +00:00
|
|
|
UIViewController *controller = self.window.rootViewController;
|
|
|
|
while (controller.presentedViewController) {
|
|
|
|
controller = controller.presentedViewController;
|
2016-05-26 21:23:49 +00:00
|
|
|
}
|
2020-09-30 20:40:32 +00:00
|
|
|
[controller presentViewController:alert animated:YES completion:nil];
|
2016-05-07 18:48:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 17:11:38 +00:00
|
|
|
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
|
|
|
|
BOOL success = NO;
|
2024-03-04 20:12:40 +00:00
|
|
|
if ([shortcutItem.type isEqualToString:@"disk"]) {
|
2022-05-26 17:11:38 +00:00
|
|
|
NSString *fileName = (NSString*)shortcutItem.userInfo[@"disk"];
|
|
|
|
NSString *filePath = [self.documentsPath stringByAppendingPathComponent:fileName];
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] && ![sharedEmulator isDiskInserted:filePath]) {
|
|
|
|
success = YES;
|
|
|
|
[sharedEmulator performSelector:@selector(insertDisk:) withObject:filePath afterDelay:1.0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
completionHandler(success);
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:32:07 +00:00
|
|
|
#pragma mark - Settings / Insert Disk / Help
|
2016-05-14 13:15:37 +00:00
|
|
|
|
2016-05-11 21:04:49 +00:00
|
|
|
- (void)showSettings:(id)sender {
|
2020-06-22 19:07:01 +00:00
|
|
|
[self.window.rootViewController performSelector:@selector(showSettings:) withObject:sender];
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showInsertDisk:(id)sender {
|
2020-06-22 19:07:01 +00:00
|
|
|
[self.window.rootViewController performSelector:@selector(showInsertDisk:) withObject:sender];
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 16:32:07 +00:00
|
|
|
- (void)showGestureHelp:(id)sender {
|
|
|
|
[self.window.rootViewController performSelector:@selector(showGestureHelp:) withObject:sender];
|
|
|
|
}
|
|
|
|
|
2016-05-07 18:48:53 +00:00
|
|
|
#pragma mark - Files
|
|
|
|
|
2016-05-27 18:21:32 +00:00
|
|
|
- (BOOL)isSandboxed {
|
2016-11-21 22:07:10 +00:00
|
|
|
#if TARGET_IPHONE_SIMULATOR
|
|
|
|
return YES;
|
|
|
|
#else
|
2016-05-27 18:21:32 +00:00
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
static BOOL sandboxed;
|
|
|
|
dispatch_once(&onceToken, ^{
|
2016-11-21 22:07:10 +00:00
|
|
|
// not sandboxed if parent of documents directory is "mobile"
|
|
|
|
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject.stringByStandardizingPath;
|
|
|
|
sandboxed = ![documentsPath.stringByDeletingLastPathComponent.lastPathComponent isEqualToString:@"mobile"];
|
2016-05-27 18:21:32 +00:00
|
|
|
});
|
|
|
|
return sandboxed;
|
2016-11-21 22:07:10 +00:00
|
|
|
#endif
|
2016-05-27 18:21:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:04:49 +00:00
|
|
|
- (NSArray<NSString *> *)diskImageExtensions {
|
2016-06-04 19:42:31 +00:00
|
|
|
return @[@"dsk", @"img", @"dc42", @"diskcopy42", @"image"];
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-07 18:48:53 +00:00
|
|
|
- (NSString *)documentsPath {
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
static NSString *documentsPath;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject.stringByStandardizingPath;
|
2016-05-27 18:21:32 +00:00
|
|
|
if (!self.sandboxed) {
|
|
|
|
documentsPath = [documentsPath stringByAppendingPathComponent:@"Mini vMac"].stringByStandardizingPath;
|
|
|
|
}
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:NULL];
|
2016-05-07 18:48:53 +00:00
|
|
|
});
|
|
|
|
return documentsPath;
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:49:05 +00:00
|
|
|
- (NSString *)userKeyboardLayoutsPath {
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
static NSString *userKeyboardLayoutsPath;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
userKeyboardLayoutsPath = [self.documentsPath stringByAppendingPathComponent:@"Keyboard Layouts"];
|
|
|
|
});
|
|
|
|
return userKeyboardLayoutsPath;
|
|
|
|
}
|
|
|
|
|
2024-02-10 13:09:02 +00:00
|
|
|
- (NSArray<NSString *> *)keyboardLayoutPaths {
|
|
|
|
NSArray *keyboardLayouts = [[NSBundle mainBundle] pathsForResourcesOfType:@"nfkeyboardlayout" inDirectory:@"Keyboard Layouts"];
|
|
|
|
NSString *userKeyboardLayoutsPath = [AppDelegate sharedInstance].userKeyboardLayoutsPath;
|
|
|
|
NSArray *userKeyboardLayouts = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:userKeyboardLayoutsPath error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension.lowercaseString = %@", @"nfkeyboardlayout"]];
|
|
|
|
if (userKeyboardLayouts.count > 0) {
|
|
|
|
keyboardLayouts = [keyboardLayouts arrayByAddingObjectsFromArray:userKeyboardLayouts];
|
|
|
|
}
|
|
|
|
return keyboardLayouts;
|
|
|
|
}
|
|
|
|
|
2018-04-28 11:05:20 +00:00
|
|
|
- (BOOL)importFileToDocuments:(NSURL *)url copy:(BOOL)copy {
|
2016-05-07 18:48:53 +00:00
|
|
|
if (url.fileURL) {
|
|
|
|
// opening file
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSString *fileName = url.path.lastPathComponent;
|
|
|
|
NSString *destinationPath = [self.documentsPath stringByAppendingPathComponent:fileName];
|
|
|
|
NSError *error = NULL;
|
|
|
|
NSInteger tries = 1;
|
|
|
|
while ([fileManager fileExistsAtPath:destinationPath]) {
|
|
|
|
NSString *newFileName;
|
|
|
|
if (fileName.pathExtension.length > 0) {
|
|
|
|
newFileName = [NSString stringWithFormat:@"%@ %d.%@", fileName.stringByDeletingPathExtension, (int)tries, fileName.pathExtension];
|
|
|
|
} else {
|
|
|
|
newFileName = [NSString stringWithFormat:@"%@ %d", fileName, (int)tries];
|
|
|
|
}
|
|
|
|
destinationPath = [self.documentsPath stringByAppendingPathComponent:newFileName];
|
|
|
|
tries++;
|
|
|
|
}
|
2018-04-28 11:05:20 +00:00
|
|
|
if (copy) {
|
|
|
|
[fileManager copyItemAtPath:url.path toPath:destinationPath error:&error];
|
|
|
|
} else {
|
|
|
|
[fileManager moveItemAtPath:url.path toPath:destinationPath error:&error];
|
|
|
|
}
|
2016-05-07 18:48:53 +00:00
|
|
|
if (error) {
|
|
|
|
[self showAlertWithTitle:fileName message:error.localizedFailureReason];
|
|
|
|
} else {
|
2016-06-06 17:42:10 +00:00
|
|
|
NSDictionary *userInfo = @{@"path": destinationPath};
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:DocumentsChangedNotification object:self userInfo:userInfo];
|
2016-05-07 18:48:53 +00:00
|
|
|
[self showAlertWithTitle:@"File Import" message:[NSString stringWithFormat:@"%@ imported to Documents", destinationPath.lastPathComponent]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
2016-04-27 20:52:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 09:50:22 +00:00
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
|
|
|
if (url.fileURL) {
|
|
|
|
// opening file
|
2018-04-28 11:05:20 +00:00
|
|
|
NSString *inboxPath = [self.documentsPath stringByAppendingPathComponent:@"Inbox"];
|
|
|
|
if ([url.path.stringByStandardizingPath hasPrefix:inboxPath]) {
|
|
|
|
// pre-iOS 11 import through inbox
|
|
|
|
[url startAccessingSecurityScopedResource];
|
|
|
|
[self importFileToDocuments:url copy:NO];
|
|
|
|
[url stopAccessingSecurityScopedResource];
|
|
|
|
} else if ([url.path.stringByStandardizingPath hasPrefix:self.documentsPath]) {
|
2018-04-28 09:50:22 +00:00
|
|
|
// already in documents - mount
|
|
|
|
[sharedEmulator insertDisk:url.path];
|
|
|
|
} else if ([options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue]) {
|
|
|
|
// not in documents - copy
|
|
|
|
[url startAccessingSecurityScopedResource];
|
2018-04-28 11:05:20 +00:00
|
|
|
[self importFileToDocuments:url copy:YES];
|
2018-04-28 09:50:22 +00:00
|
|
|
[url stopAccessingSecurityScopedResource];
|
|
|
|
} else {
|
2018-04-28 11:05:20 +00:00
|
|
|
return [self importFileToDocuments:url copy:NO];
|
2018-04-28 09:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:15:01 +00:00
|
|
|
#pragma mark - Making a Scene
|
|
|
|
|
|
|
|
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
|
|
|
|
for (NSUserActivity *activity in options.userActivities) {
|
|
|
|
if ([activity.activityType isEqualToString:@"net.namedfork.keyboard"]) {
|
|
|
|
return [UISceneConfiguration configurationWithName:@"Keyboard" sessionRole:UIWindowSceneSessionRoleApplication];
|
|
|
|
}
|
|
|
|
}
|
2024-02-17 13:41:22 +00:00
|
|
|
if ([self sceneWithName:@"Default"] == nil) {
|
2024-02-17 13:52:50 +00:00
|
|
|
[[AppDelegate sharedEmulator] setRunning:YES];
|
2024-02-10 11:15:01 +00:00
|
|
|
return [UISceneConfiguration configurationWithName:@"Default" sessionRole:UIWindowSceneSessionRoleApplication];
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
|
2024-02-17 13:41:36 +00:00
|
|
|
if ([self sceneWithName:@"Default"] == nil) {
|
2024-02-17 13:52:50 +00:00
|
|
|
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"runInBackground"] == NO) {
|
|
|
|
[[AppDelegate sharedEmulator] setRunning:NO];
|
|
|
|
}
|
2024-02-17 13:41:36 +00:00
|
|
|
UIScene *keyboardScene = [self sceneWithName:@"Keyboard"];
|
|
|
|
if (keyboardScene != nil) {
|
2024-02-17 13:52:50 +00:00
|
|
|
// if only keyboard is left, close it too
|
2024-02-17 13:41:36 +00:00
|
|
|
[application requestSceneSessionDestruction:keyboardScene.session options:nil errorHandler:nil];
|
|
|
|
}
|
2024-02-10 11:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 13:41:22 +00:00
|
|
|
- (UIScene*)sceneWithName:(NSString*)name {
|
2024-02-10 11:15:01 +00:00
|
|
|
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
|
2024-02-17 13:41:22 +00:00
|
|
|
if ([scene.session.configuration.name isEqualToString:name]) {
|
|
|
|
return scene;
|
2024-02-10 11:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-17 13:41:22 +00:00
|
|
|
return nil;
|
2024-02-10 11:15:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 20:52:28 +00:00
|
|
|
@end
|