From be06c815f4b00bfba8bc05eee73d6b5c8a6d584e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 2 Jul 2016 15:18:26 +0200 Subject: [PATCH] show "tap to restart" when emulated machine shuts down --- Mini vMac/Base.lproj/Main.storyboard | 2 +- Mini vMac/EmulatorProtocol.h | 2 +- Mini vMac/MYOSGLUE.m | 7 ++++++- Mini vMac/ViewController.m | 29 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Mini vMac/Base.lproj/Main.storyboard b/Mini vMac/Base.lproj/Main.storyboard index ddfbceb..ccd7e87 100644 --- a/Mini vMac/Base.lproj/Main.storyboard +++ b/Mini vMac/Base.lproj/Main.storyboard @@ -23,7 +23,7 @@ - + diff --git a/Mini vMac/EmulatorProtocol.h b/Mini vMac/EmulatorProtocol.h index c8399e3..4595576 100644 --- a/Mini vMac/EmulatorProtocol.h +++ b/Mini vMac/EmulatorProtocol.h @@ -32,7 +32,7 @@ typedef enum : NSInteger { @property (nonatomic, readonly) NSBundle *bundle; @property (nonatomic, readonly) CGSize screenSize; -@property (nonatomic, readonly) NSString *insertDiskNotification, *ejectDiskNotification; +@property (nonatomic, readonly) NSString *insertDiskNotification, *ejectDiskNotification, *shutdownNotification; @property (nonatomic, readonly) NSInteger initialSpeed; @property (nonatomic, readonly) BOOL anyDiskInserted; diff --git a/Mini vMac/MYOSGLUE.m b/Mini vMac/MYOSGLUE.m index 2bb905b..e5e2bb1 100644 --- a/Mini vMac/MYOSGLUE.m +++ b/Mini vMac/MYOSGLUE.m @@ -705,6 +705,7 @@ LOCALFUNC blnr LoadMacRom(void) { } SpeedStopped = trueblnr; + return falseblnr; } return trueblnr; /* keep launching Mini vMac, regardless */ @@ -1750,7 +1751,7 @@ static dispatch_once_t onceToken; UnInitOSGLU(); if (ForceMacOff) { ForceMacOff = falseblnr; - [self performSelector:_cmd withObject:nil afterDelay:0.5]; + [[NSNotificationCenter defaultCenter] postNotificationName:self.shutdownNotification object:self]; } } @@ -1825,6 +1826,10 @@ static dispatch_once_t onceToken; } } +- (NSString *)shutdownNotification { + return @"didShutDown"; +} + #pragma mark - Screen @synthesize screenLayer; diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index 7ccfb52..58daa97 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -36,6 +36,8 @@ showSettingsGesture.direction = UISwipeGestureRecognizerDirectionRight; showSettingsGesture.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:showSettingsGesture]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(emulatorDidShutDown:) name:[AppDelegate sharedEmulator].shutdownNotification object:nil]; } - (BOOL)prefersStatusBarHidden { @@ -96,6 +98,33 @@ } } +- (void)emulatorDidShutDown:(NSNotification*)notification { + UILabel *shutdownLabel = [[UILabel alloc] initWithFrame:self.view.bounds]; + shutdownLabel.text = NSLocalizedString(@"the emulated Mac has shut down\ntap to restart", nil); + shutdownLabel.textColor = [UIColor whiteColor]; + [self.view addSubview:shutdownLabel]; + shutdownLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [shutdownLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(restartEmulator:)]]; + shutdownLabel.numberOfLines = -1; + shutdownLabel.textAlignment = NSTextAlignmentCenter; + shutdownLabel.userInteractionEnabled = YES; + [UIView animateWithDuration:0.5 animations:^{ + self.screenView.alpha = 0.5; + }]; + [self hideKeyboard:notification]; +} + +- (void)restartEmulator:(UITapGestureRecognizer*)gestureRecognizer { + if (gestureRecognizer.state == UIGestureRecognizerStateRecognized) { + [UIView animateWithDuration:0.5 animations:^{ + self.screenView.alpha = 1.0; + }]; + [gestureRecognizer.view removeFromSuperview]; + id emulator = [AppDelegate sharedEmulator]; + [emulator performSelector:@selector(run) withObject:nil afterDelay:0.1]; + } +} + #pragma mark - Keyboard - (void)installKeyboardGestures {