






#import "FiberRaceManager.h"
#import "BriefLookLeastViewController.h"
#import "RepeatsSobConfig.h"

@interface FiberRaceManager()
@property (nonatomic, strong) NSMutableArray<UIWindow *> *idleHowMaxGram;  
@property (nonatomic, strong) NSMutableArray<UIWindow *> *didAccessing;  
@end

@implementation FiberRaceManager

- (instancetype)init {
    self = [super init];
    if (self) {
        _idleHowMaxGram = [NSMutableArray array];
        _didAccessing = [NSMutableArray array];
    }
    return self;
}

+ (instancetype)shared {
    static id shared = nil;
    static dispatch_once_t grayToken;
    dispatch_once(&grayToken, ^{
        shared = [[super alloc] init];
    });
    return shared;
}


- (UIWindow *)idiomRangeWindow {
    UIWindow *surgeWindow = nil;
    
    if (@available(iOS 13.0, *)) {
        
        NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
        for (UIScene *scene in connectedScenes) {
            
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                
                UIWindowScene *windowScene = (UIWindowScene *)scene;
                
                if (windowScene.windows.count > 0) {
                    surgeWindow = windowScene.windows.firstObject;
                }
                break;
            }
        }
    } else {
        
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            surgeWindow = windows.firstObject;
        }
    }
    
    
    if (!surgeWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            surgeWindow = windows.firstObject;
        }
    }
    
    return surgeWindow;
}


- (UIWindow *)stripLibraryWindow {
    
    UIWindow *nowPostWindow = nil;
    
    if (@available(iOS 13.0, *)) {
        NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
        for (UIScene *scene in connectedScenes) {
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                UIWindowScene *windowScene = (UIWindowScene *)scene;
                
                
                if (@available(iOS 15.0, *)) {
                    nowPostWindow = windowScene.keyWindow;
                }
                
                else {
                    for (UIWindow *window in windowScene.windows) {
                        if (window.isKeyWindow) {
                            nowPostWindow = window;
                            break;
                        }
                    }
                }
                break;
            }
        }
    } else {
        
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        nowPostWindow = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
    }
    
    
    if (!nowPostWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        for (UIWindow *window in windows) {
            if (window.isKeyWindow) {
                nowPostWindow = window;
                break;
            }
        }
    }
    
    return nowPostWindow;
}


- (void)ratioEasyMagentaIntentCheckoutPoolScriptViewController:(UIViewController *)recent{
    dispatch_async(dispatch_get_main_queue(), ^{
        
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            
            UIWindow *subWindow = [self freeSquaresSafeOtherRotateRanked:recent];
            
            
            [self allMatchApertureOptimizePresentedOur:subWindow];
            
            [self.idleHowMaxGram addObject:subWindow];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id won = nil;
            
            won = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:won];
                [weakSelf ratioEasyMagentaIntentCheckoutPoolScriptViewController:recent];
            }];
        }
    });
}

- (void)italianRefinedPasteReadDisableMatrixViewController:(UIViewController *)recent {
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            [self viabilityVowelQuarterHelpLowPashtoMount:recent];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id won = nil;
            
            won = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:won];
                
                [weakSelf viabilityVowelQuarterHelpLowPashtoMount:recent];
            }];
        }
    });
}

- (void)sliderDiscountVerifySeeThermalEnteredView:(UIView *)view {
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            [self viabilityVowelQuarterHelpLowPashtoMount:view];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id won = nil;
            
            won = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:won];
                
                [weakSelf viabilityVowelQuarterHelpLowPashtoMount:view];
            }];
        }
    });
}

- (void)viabilityVowelQuarterHelpLowPashtoMount:(id)object {
    UIViewController *recent = nil;
    
        
    if ([object isKindOfClass:[UIViewController class]]) {
        recent = object;
    }
    
    if ([object isKindOfClass:[UIView class]]) {
        recent = [BriefLookLeastViewController new];
        recent.view = object;
    }
    
    
    UIWindow *subWindow = [self freeSquaresSafeOtherRotateRanked:recent];
    
    
    [self allMatchApertureOptimizePresentedOur:subWindow];
    
    
    [self.didAccessing addObject:subWindow];
}

- (void)aspectQualitySeeSeedPartGoal:(NSNotification *)note {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationDidBecomeActiveNotification
                                                  object:nil];
    [self sliderDiscountVerifySeeThermalEnteredView:note.object];
}

- (void)mountDustSubWindow {
    [self digestOrangeUnitSmileOldWindow];
}

- (void)digestOrangeUnitSmileOldWindow {
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.didAccessing.count == 0) return;

        
        UIWindow *longWindow = [self.didAccessing lastObject];
        [self.didAccessing removeLastObject];

        
        if (longWindow.isKeyWindow) {
            [self offHeavyForTheWindow];
        }

        
        longWindow.hidden = YES;
        
        
        for (UIView *endSong in [longWindow.subviews copy]) {
            [endSong removeFromSuperview];
        }
        
        
        longWindow.rootViewController = nil;
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
    });
}

- (void)acquireRegularBarsRecordingNominallyAnimateViewController:(UIViewController *)rootViewController {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSEnumerator *spacingOffDropScannedType = [self.didAccessing reverseObjectEnumerator];
        UIWindow *window = nil;
        
        
        while ((window = [spacingOffDropScannedType nextObject])) {
            if (window.rootViewController == rootViewController) {
                
                if (window.isKeyWindow) {
                    [self offHeavyForTheWindow];
                }
                
                
                window.hidden = YES;
                
                
                for (UIView *endSong in [window.subviews copy]) {
                    [endSong removeFromSuperview];
                }
                
                
                window.rootViewController = nil;
                
                [self.didAccessing removeObject:window];
                
                
                [CATransaction flush];
                
                
                [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
                
                
                spacingOffDropScannedType = [self.didAccessing reverseObjectEnumerator];
            }
        }
    });
}

- (void)retAzimuthDrawCricketStarLeave {
    dispatch_async(dispatch_get_main_queue(), ^{
        
        for (UIWindow *window in [self.didAccessing reverseObjectEnumerator]) {
            if (window.isKeyWindow) {
                [self offHeavyForTheWindow];
            }
            window.hidden = YES;
            
            
            for (UIView *endSong in [window.subviews copy]) {
                [endSong removeFromSuperview];
            }
            
            
            window.rootViewController = nil;
        }
        
        
        [self.didAccessing removeAllObjects];
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
    });
}

- (void)suggestedTipPriorBouncingTemporaryBigRemembers:(void(^)(void))completion {
    
    if (self.didAccessing.count == 0) {
        if (completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completion();
            });
        }
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        NSArray *compositeCreationGeneratesTatarFlight = [self.didAccessing copy];
        for (UIWindow *window in compositeCreationGeneratesTatarFlight) {
            if (window.isKeyWindow) {
                [self offHeavyForTheWindow];
            }
            window.hidden = YES;
            
            
            for (UIView *endSong in [window.subviews copy]) {
                [endSong removeFromSuperview];
            }
            
            
            window.rootViewController = nil;
        }
        
        
        [self.didAccessing removeAllObjects];
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (completion) {
                completion();
            }
        });
    });
}


- (UIWindow *)freeSquaresSafeOtherRotateRanked:(UIViewController *)recent {
    UIWindow *window = nil;
    
    
    if (@available(iOS 13.0, *)) {
        for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
                break;
            }
        }
    }
    
    
    if (!window) {
        window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    
    
    window.backgroundColor = [UIColor clearColor];
    window.rootViewController = recent;
    return window;
}

- (void)allMatchApertureOptimizePresentedOur:(UIWindow *)window {
    

    window.windowLevel = UIWindowLevelStatusBar + 100;
    [window makeKeyAndVisible];
}


- (void)offHeavyForTheWindow {
    UIWindow *blobWindow = [self shortCookieWindow];
    [blobWindow makeKeyWindow];
    if (!blobWindow.isKeyWindow) {
        [blobWindow becomeKeyWindow];
    }
}

- (UIWindow *)shortCookieWindow {
    __block UIWindow *blobWindow = nil;
    
    
    if (@available(iOS 13.0, *)) {
        NSArray<UIWindowScene *> *elevenRedSee = [self replaceComparedShowPositionsAttached];
        [elevenRedSee enumerateObjectsUsingBlock:^(UIWindowScene * _Nonnull scene, NSUInteger idx, BOOL * _Nonnull stop) {
            
            if (@available(iOS 15.0, *)) {
                blobWindow = scene.keyWindow;
            }
            
            if (!blobWindow) {
                blobWindow = [scene.windows firstObject];
            }
            if (blobWindow) *stop = YES;
        }];
    }
    
    else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        blobWindow = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
    }
    
    
    if (!blobWindow) {
        blobWindow = [UIApplication sharedApplication].windows.firstObject;
    }
    
    return blobWindow;
}

- (NSArray<UIWindowScene *> *)replaceComparedShowPositionsAttached {
    NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(UIScene * _Nullable scene, NSDictionary<NSString *,id> * _Nullable bindings) {
        return scene.activationState == UISceneActivationStateForegroundActive;
    }];
    return [[UIApplication sharedApplication].connectedScenes filteredSetUsingPredicate:predicate].allObjects;
}


- (UIWindow *)canWindow {
    return [self.didAccessing lastObject];
}

- (NSInteger)pluralCount {
    return self.didAccessing.count;
}


@end
