diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index 95b3c4b..1884bf0 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -25,7 +25,7 @@ extern NSString *DocumentsChangedNotification; + (instancetype)sharedInstance; + (id)sharedEmulator; -- (void)reloadEmulator; +- (void)loadAndStartEmulator; - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message; - (IBAction)showInsertDisk:(id)sender; diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 08334c2..e03ad17 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -33,12 +33,9 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { sharedAppDelegate = self; - if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) { - [self loadEmulator:@"MacPlus4M"]; - } [self initDefaults]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL]; - [sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1]; + [self loadAndStartEmulator]; if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) { [application btcMouseSetRawMode:YES]; @@ -69,7 +66,6 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults registerDefaults:defaultValues]; - [defaults setValue:@(sharedEmulator.initialSpeed) forKey:@"speedValue"]; [defaults addObserver:self forKeyPath:@"speedValue" options:0 context:NULL]; } @@ -108,17 +104,26 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; return sharedEmulator != nil; } -- (void)reloadEmulator { - NSBundle *bundle = sharedEmulator.bundle; +- (void)loadAndStartEmulator { [self willChangeValueForKey:@"sharedEmulator"]; - id oldEmulator = sharedEmulator; - sharedEmulator = nil; - [oldEmulator shutdown]; - [bundle unload]; + if (sharedEmulator) { + NSBundle *bundle = sharedEmulator.bundle; + id oldEmulator = sharedEmulator; + sharedEmulator = nil; + [oldEmulator shutdown]; + [bundle unload]; + } if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) { [self loadEmulator:@"MacPlus4M"]; } [self didChangeValueForKey:@"sharedEmulator"]; + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + if ([defaults integerForKey:@"speedValue"] > sharedEmulator.initialSpeed) { + [defaults setValue:@(sharedEmulator.initialSpeed) forKey:@"speedValue"]; + } else { + sharedEmulator.speed = [defaults integerForKey:@"speedValue"]; + } [sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1]; } diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index 3e00ffb..facc4ac 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -109,7 +109,7 @@ typedef enum : NSInteger { [super viewWillDisappear:animated]; [AppDelegate sharedEmulator].running = YES; if (![selectedEmulatorBundle isEqual:[AppDelegate sharedEmulator].bundle] && ![AppDelegate sharedEmulator].anyDiskInserted) { - [[AppDelegate sharedInstance] reloadEmulator]; + [[AppDelegate sharedInstance] loadAndStartEmulator]; } }