VMDisplayViewController.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Copyright © 2020 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMDisplayViewController.h"
  17. #import "UTM-Swift.h"
  18. @implementation VMDisplayViewController
  19. #pragma mark - Properties
  20. @synthesize prefersStatusBarHidden = _prefersStatusBarHidden;
  21. @synthesize vmConfiguration;
  22. @synthesize vmMessage;
  23. @synthesize keyboardVisible = _keyboardVisible;
  24. @synthesize toolbarVisible = _toolbarVisible;
  25. - (UTMQemuConfiguration *)vmQemuConfig {
  26. return (UTMQemuConfiguration *)vmConfiguration;
  27. }
  28. - (BOOL)prefersHomeIndicatorAutoHidden {
  29. return YES; // always hide home indicator
  30. }
  31. - (UIStatusBarStyle)preferredStatusBarStyle {
  32. return UIStatusBarStyleLightContent;
  33. }
  34. - (void)setPrefersStatusBarHidden:(BOOL)prefersStatusBarHidden {
  35. _prefersStatusBarHidden = prefersStatusBarHidden;
  36. [self setNeedsStatusBarAppearanceUpdate];
  37. }
  38. - (void)setToolbarVisible:(BOOL)toolbarVisible {
  39. if (toolbarVisible) {
  40. [self.toolbar show];
  41. } else {
  42. [self.toolbar hide];
  43. }
  44. _toolbarVisible = toolbarVisible;
  45. }
  46. #pragma mark - View handling
  47. - (BOOL)inputViewIsFirstResponder {
  48. return NO;
  49. }
  50. - (void)updateKeyboardAccessoryFrame {
  51. }
  52. - (void)virtualMachine:(UTMVirtualMachine *)vm transitionToState:(UTMVMState)state {
  53. static BOOL hasStartedOnce = NO;
  54. if (hasStartedOnce && state == kVMStopped) {
  55. [self terminateApplication];
  56. }
  57. switch (state) {
  58. case kVMError: {
  59. [self.placeholderIndicator stopAnimating];
  60. self.resumeBigButton.hidden = YES;
  61. NSString *msg = self.vmMessage ? self.vmMessage : NSLocalizedString(@"An internal error has occured. UTM will terminate.", @"VMDisplayViewController");
  62. [self showAlert:msg actions:nil completion:^(UIAlertAction *action){
  63. [self terminateApplication];
  64. }];
  65. break;
  66. }
  67. case kVMStopped:
  68. case kVMPaused:
  69. case kVMSuspended: {
  70. [self enterSuspendedWithIsBusy:NO];
  71. break;
  72. }
  73. case kVMPausing:
  74. case kVMStopping:
  75. case kVMStarting:
  76. case kVMResuming: {
  77. [self enterSuspendedWithIsBusy:YES];
  78. break;
  79. }
  80. case kVMStarted: {
  81. hasStartedOnce = YES; // auto-quit after VM ends
  82. [self enterLive];
  83. break;
  84. }
  85. }
  86. }
  87. @end