FLEXManager.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // FLEXManager.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 4/4/14.
  6. // Copyright (c) 2020 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXManager.h"
  9. #import "FLEXUtility.h"
  10. #import "FLEXExplorerViewController.h"
  11. #import "FLEXWindow.h"
  12. #import "FLEXObjectExplorerViewController.h"
  13. #import "FLEXFileBrowserController.h"
  14. @interface FLEXManager () <FLEXWindowEventDelegate, FLEXExplorerViewControllerDelegate>
  15. @property (nonatomic, readonly, getter=isHidden) BOOL hidden;
  16. @property (nonatomic) FLEXWindow *explorerWindow;
  17. @property (nonatomic) FLEXExplorerViewController *explorerViewController;
  18. @property (nonatomic, readonly) NSMutableArray<FLEXGlobalsEntry *> *userGlobalEntries;
  19. @property (nonatomic, readonly) NSMutableDictionary<NSString *, FLEXCustomContentViewerFuture> *customContentTypeViewers;
  20. @end
  21. @implementation FLEXManager
  22. + (instancetype)sharedManager {
  23. static FLEXManager *sharedManager = nil;
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. sharedManager = [self new];
  27. });
  28. return sharedManager;
  29. }
  30. - (instancetype)init {
  31. self = [super init];
  32. if (self) {
  33. _userGlobalEntries = [NSMutableArray new];
  34. _customContentTypeViewers = [NSMutableDictionary new];
  35. }
  36. return self;
  37. }
  38. - (FLEXWindow *)explorerWindow {
  39. NSAssert(NSThread.isMainThread, @"You must use %@ from the main thread only.", NSStringFromClass([self class]));
  40. if (!_explorerWindow) {
  41. _explorerWindow = [[FLEXWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
  42. _explorerWindow.eventDelegate = self;
  43. _explorerWindow.rootViewController = self.explorerViewController;
  44. }
  45. return _explorerWindow;
  46. }
  47. - (FLEXExplorerViewController *)explorerViewController {
  48. if (!_explorerViewController) {
  49. _explorerViewController = [FLEXExplorerViewController new];
  50. _explorerViewController.delegate = self;
  51. }
  52. return _explorerViewController;
  53. }
  54. - (void)showExplorer {
  55. UIWindow *flex = self.explorerWindow;
  56. flex.hidden = NO;
  57. #if FLEX_AT_LEAST_IOS13_SDK
  58. if (@available(iOS 13.0, *)) {
  59. // Only look for a new scene if we don't have one
  60. if (!flex.windowScene) {
  61. flex.windowScene = FLEXUtility.activeScene;
  62. }
  63. }
  64. #endif
  65. }
  66. - (void)hideExplorer {
  67. self.explorerWindow.hidden = YES;
  68. }
  69. - (void)toggleExplorer {
  70. if (self.explorerWindow.isHidden) {
  71. [self showExplorer];
  72. } else {
  73. [self hideExplorer];
  74. }
  75. }
  76. - (void)showExplorerFromScene:(UIWindowScene *)scene {
  77. #if FLEX_AT_LEAST_IOS13_SDK
  78. if (@available(iOS 13.0, *)) {
  79. self.explorerWindow.windowScene = scene;
  80. }
  81. #endif
  82. self.explorerWindow.hidden = NO;
  83. }
  84. - (BOOL)isHidden {
  85. return self.explorerWindow.isHidden;
  86. }
  87. - (FLEXExplorerToolbar *)toolbar {
  88. return self.explorerViewController.explorerToolbar;
  89. }
  90. #pragma mark - FLEXWindowEventDelegate
  91. - (BOOL)shouldHandleTouchAtPoint:(CGPoint)pointInWindow {
  92. // Ask the explorer view controller
  93. return [self.explorerViewController shouldReceiveTouchAtWindowPoint:pointInWindow];
  94. }
  95. - (BOOL)canBecomeKeyWindow {
  96. // Only when the explorer view controller wants it because
  97. // it needs to accept key input & affect the status bar.
  98. return self.explorerViewController.wantsWindowToBecomeKey;
  99. }
  100. #pragma mark - FLEXExplorerViewControllerDelegate
  101. - (void)explorerViewControllerDidFinish:(FLEXExplorerViewController *)explorerViewController {
  102. [self hideExplorer];
  103. }
  104. @end