@@ -20,6 +20,33 @@ BOOL isInPlayInteractionVC = NO;
2020BOOL isPureViewVisible = NO ;
2121BOOL clearButtonForceHidden = NO ;
2222BOOL isAppActive = YES ;
23+ BOOL dyyyIsPerformingFloatClearOperation = NO ;
24+
25+ static NSInteger dyyyClearButtonMutationDepth = 0 ;
26+
27+ static inline void DYYYBeginClearButtonMutation (void ) {
28+ dyyyClearButtonMutationDepth++;
29+ dyyyIsPerformingFloatClearOperation = YES ;
30+ }
31+
32+ static inline void DYYYEndClearButtonMutation (void ) {
33+ if (dyyyClearButtonMutationDepth > 0 ) {
34+ dyyyClearButtonMutationDepth--;
35+ }
36+ dyyyIsPerformingFloatClearOperation = dyyyClearButtonMutationDepth > 0 ;
37+ }
38+
39+ static void DYYYPerformClearButtonMutation (dispatch_block_t block) {
40+ if (!block) {
41+ return ;
42+ }
43+ DYYYBeginClearButtonMutation ();
44+ @try {
45+ block ();
46+ } @finally {
47+ DYYYEndClearButtonMutation ();
48+ }
49+ }
2350
2451
2552HideUIButton *hideButton;
@@ -49,26 +76,60 @@ UIWindow *getKeyWindow(void) {
4976 return keyWindow;
5077}
5178
52- void updateClearButtonVisibility ( ) {
53- if (!hideButton || !isAppActive)
79+ static void DYYYApplyClearButtonHiddenState (HideUIButton *button, BOOL hidden ) {
80+ if (!button) {
5481 return ;
55-
56- __weak HideUIButton *weakButton = hideButton;
57- dispatch_async (dispatch_get_main_queue (), ^{
58- HideUIButton *strongButton = weakButton;
59- if (!strongButton) {
82+ }
83+ void (^applyBlock)(HideUIButton *) = ^(HideUIButton *target) {
84+ if (!target) {
6085 return ;
6186 }
62- if (!dyyyInteractionViewVisible) {
63- strongButton.hidden = YES ;
64- return ;
87+ if (target.hidden != hidden) {
88+ target.hidden = hidden;
6589 }
90+ };
6691
67- BOOL shouldHide = dyyyCommentViewVisible || clearButtonForceHidden || isPureViewVisible;
68- if (strongButton.hidden != shouldHide) {
69- strongButton.hidden = shouldHide;
92+ if ([NSThread isMainThread ]) {
93+ applyBlock (button);
94+ } else {
95+ __weak HideUIButton *weakButton = button;
96+ dispatch_async (dispatch_get_main_queue (), ^{
97+ applyBlock (weakButton);
98+ });
99+ }
100+ }
101+
102+ static BOOL DYYYShouldHideClearButton (void ) {
103+ BOOL clearModeActive = (hideButton && hideButton.isElementsHidden );
104+ if (clearModeActive) {
105+ if (!isAppActive) {
106+ return YES ;
70107 }
71- });
108+ return clearButtonForceHidden;
109+ }
110+ if (!isAppActive) {
111+ return YES ;
112+ }
113+ if (!dyyyInteractionViewVisible) {
114+ return YES ;
115+ }
116+ if (dyyyCommentViewVisible) {
117+ return YES ;
118+ }
119+ if (isPureViewVisible) {
120+ return YES ;
121+ }
122+ if (clearButtonForceHidden) {
123+ return YES ;
124+ }
125+ return NO ;
126+ }
127+
128+ void updateClearButtonVisibility () {
129+ if (!hideButton) {
130+ return ;
131+ }
132+ DYYYApplyClearButtonHiddenState (hideButton, DYYYShouldHideClearButton ());
72133}
73134
74135void showClearButton (void ) {
@@ -78,37 +139,30 @@ void showClearButton(void) {
78139
79140void hideClearButton (void ) {
80141 clearButtonForceHidden = YES ;
81- if (hideButton) {
82- __weak HideUIButton *weakButton = hideButton;
83- dispatch_async (dispatch_get_main_queue (), ^{
84- HideUIButton *strongButton = weakButton;
85- if (!strongButton) {
86- return ;
87- }
88- strongButton.hidden = YES ;
89- });
90- }
142+ updateClearButtonVisibility ();
91143}
92144
93145static void forceResetAllUIElements (void ) {
94- UIWindow *window = getKeyWindow ();
95- if (!window)
96- return ;
97- Class StackViewClass = NSClassFromString (@" AWEElementStackView" );
98- for (NSString *className in targetClassNames) {
99- Class viewClass = NSClassFromString (className);
100- if (!viewClass)
101- continue ;
102- NSMutableArray *views = [NSMutableArray array ];
103- findViewsOfClassHelper (window, viewClass, views);
104- for (UIView *view in views) {
105- if ([view isKindOfClass: StackViewClass]) {
106- view.alpha = DYGetGlobalAlpha ();
107- } else {
108- view.alpha = 1.0 ; // 恢复透明度
146+ DYYYPerformClearButtonMutation (^{
147+ UIWindow *window = getKeyWindow ();
148+ if (!window)
149+ return ;
150+ Class StackViewClass = NSClassFromString (@" AWEElementStackView" );
151+ for (NSString *className in targetClassNames) {
152+ Class viewClass = NSClassFromString (className);
153+ if (!viewClass)
154+ continue ;
155+ NSMutableArray *views = [NSMutableArray array ];
156+ findViewsOfClassHelper (window, viewClass, views);
157+ for (UIView *view in views) {
158+ if ([view isKindOfClass: StackViewClass]) {
159+ view.alpha = DYGetGlobalAlpha ();
160+ } else {
161+ view.alpha = 1.0 ; // 恢复透明度
162+ }
109163 }
110164 }
111- }
165+ });
112166}
113167static void reapplyHidingToAllElements (HideUIButton *button) {
114168 if (!button || !button.isElementsHidden )
@@ -415,9 +469,11 @@ void initTargetClassNames(void) {
415469
416470- (void )restoreAWEPlayInteractionProgressContainerView {
417471 if ([[NSUserDefaults standardUserDefaults ] boolForKey: @" DYYYRemoveTimeProgress" ] || [[NSUserDefaults standardUserDefaults ] boolForKey: @" DYYYHideTimeProgress" ]) {
418- for (UIWindow *window in [UIApplication sharedApplication ].windows ) {
419- [self recursivelyRestoreAWEPlayInteractionProgressContainerViewInView: window];
420- }
472+ DYYYPerformClearButtonMutation (^{
473+ for (UIWindow *window in [UIApplication sharedApplication ].windows ) {
474+ [self recursivelyRestoreAWEPlayInteractionProgressContainerViewInView: window];
475+ }
476+ });
421477 }
422478}
423479
@@ -450,15 +506,17 @@ void initTargetClassNames(void) {
450506 }
451507}
452508- (void )hideUIElements {
453- [self .hiddenViewsList removeAllObjects ];
454- [self findAndHideViews: targetClassNames];
455- [self hideAWEPlayInteractionProgressContainerView ];
456- self.isElementsHidden = YES ;
457- // self.hidden should be managed by updateClearButtonVisibility
458- updateClearButtonVisibility ();
459- if (self.superview ) {
460- [self .superview bringSubviewToFront: self ];
461- }
509+ DYYYPerformClearButtonMutation (^{
510+ [self .hiddenViewsList removeAllObjects ];
511+ [self findAndHideViews: targetClassNames];
512+ [self hideAWEPlayInteractionProgressContainerView ];
513+ self.isElementsHidden = YES ;
514+ // self.hidden should be managed by updateClearButtonVisibility
515+ updateClearButtonVisibility ();
516+ if (self.superview ) {
517+ [self .superview bringSubviewToFront: self ];
518+ }
519+ });
462520}
463521
464522- (void )hideAWEPlayInteractionProgressContainerView {
0 commit comments