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
This commit is contained in:
Jesús A. Álvarez 2020-09-25 22:13:52 +02:00
parent fd665a1761
commit dead799d16
3 changed files with 18 additions and 13 deletions

View File

@ -25,7 +25,7 @@ extern NSString *DocumentsChangedNotification;
+ (instancetype)sharedInstance; + (instancetype)sharedInstance;
+ (id<Emulator>)sharedEmulator; + (id<Emulator>)sharedEmulator;
- (void)reloadEmulator; - (void)loadAndStartEmulator;
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message; - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message;
- (IBAction)showInsertDisk:(id)sender; - (IBAction)showInsertDisk:(id)sender;

View File

@ -33,12 +33,9 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sharedAppDelegate = self; sharedAppDelegate = self;
if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) {
[self loadEmulator:@"MacPlus4M"];
}
[self initDefaults]; [self initDefaults];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
[sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1]; [self loadAndStartEmulator];
if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) { if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) {
[application btcMouseSetRawMode:YES]; [application btcMouseSetRawMode:YES];
@ -69,7 +66,6 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:defaultValues]; [defaults registerDefaults:defaultValues];
[defaults setValue:@(sharedEmulator.initialSpeed) forKey:@"speedValue"];
[defaults addObserver:self forKeyPath:@"speedValue" options:0 context:NULL]; [defaults addObserver:self forKeyPath:@"speedValue" options:0 context:NULL];
} }
@ -108,17 +104,26 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
return sharedEmulator != nil; return sharedEmulator != nil;
} }
- (void)reloadEmulator { - (void)loadAndStartEmulator {
NSBundle *bundle = sharedEmulator.bundle;
[self willChangeValueForKey:@"sharedEmulator"]; [self willChangeValueForKey:@"sharedEmulator"];
id<Emulator> oldEmulator = sharedEmulator; if (sharedEmulator) {
sharedEmulator = nil; NSBundle *bundle = sharedEmulator.bundle;
[oldEmulator shutdown]; id<Emulator> oldEmulator = sharedEmulator;
[bundle unload]; sharedEmulator = nil;
[oldEmulator shutdown];
[bundle unload];
}
if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) { if (![self loadEmulator:[[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]]) {
[self loadEmulator:@"MacPlus4M"]; [self loadEmulator:@"MacPlus4M"];
} }
[self didChangeValueForKey:@"sharedEmulator"]; [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]; [sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1];
} }

View File

@ -109,7 +109,7 @@ typedef enum : NSInteger {
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
[AppDelegate sharedEmulator].running = YES; [AppDelegate sharedEmulator].running = YES;
if (![selectedEmulatorBundle isEqual:[AppDelegate sharedEmulator].bundle] && ![AppDelegate sharedEmulator].anyDiskInserted) { if (![selectedEmulatorBundle isEqual:[AppDelegate sharedEmulator].bundle] && ![AppDelegate sharedEmulator].anyDiskInserted) {
[[AppDelegate sharedInstance] reloadEmulator]; [[AppDelegate sharedInstance] loadAndStartEmulator];
} }
} }