From dead799d16ce4bca0091772a2d08f44c1074b690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Fri, 25 Sep 2020 22:13:52 +0200 Subject: [PATCH] only reset speed when saved speed is faster than default this saves the preferences, but still prevents accidentally locking up the app by setting a fast speed on a low end device --- Mini vMac/AppDelegate.h | 2 +- Mini vMac/AppDelegate.m | 27 ++++++++++++++++----------- Mini vMac/SettingsViewController.m | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) 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]; } }