mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-11 12:04:39 +02:00
fix(YouTube - NavigationBarHook): Increase nav button latch timeout.
This commit is contained in:
parent
41aaeafbe9
commit
9e496b1da3
@ -25,20 +25,21 @@ public final class NavigationBar {
|
|||||||
* How long to wait for the set nav button latch to be released. Maximum wait time must
|
* How long to wait for the set nav button latch to be released. Maximum wait time must
|
||||||
* be as small as possible while still allowing enough time for the nav bar to update.
|
* be as small as possible while still allowing enough time for the nav bar to update.
|
||||||
* <p>
|
* <p>
|
||||||
* YT calls it's back button handlers out of order,
|
* YT calls it's back button handlers out of order, and litho starts filtering before the
|
||||||
* and litho starts filtering before the navigation bar is updated.
|
* navigation bar is updated. Fixing this situation and not needlessly waiting requires
|
||||||
|
* somehow detecting if a back button key/gesture will not change the active tab.
|
||||||
* <p>
|
* <p>
|
||||||
* Fixing this situation and not needlessly waiting requires somehow
|
* On average the time between pressing the back button and the first litho event is
|
||||||
* detecting if a back button key-press will cause a tab change.
|
* about 10-20ms. Waiting up to 75-150ms should be enough time to handle normal use cases
|
||||||
|
* and not be noticeable, since YT typically takes 100-200ms (or more) to update the view.
|
||||||
* <p>
|
* <p>
|
||||||
* Typically after pressing the back button, the time between the first litho event and
|
* This delay is only noticeable when the device back button/gesture will not
|
||||||
* when the nav button is updated is about 10-20ms. Using 50-100ms here should be enough time
|
* change the current navigation tab, such as backing out of the watch history.
|
||||||
* and not noticeable, since YT typically takes 100-200ms (or more) to update the view anyways.
|
|
||||||
* <p>
|
* <p>
|
||||||
* This issue can also be avoided on a patch by patch basis, by avoiding calls to
|
* This issue can also be avoided on a patch by patch basis, by avoiding calls to
|
||||||
* {@link NavigationButton#getSelectedNavigationButton()} unless absolutely necessary.
|
* {@link NavigationButton#getSelectedNavigationButton()} unless absolutely necessary.
|
||||||
*/
|
*/
|
||||||
private static final long LATCH_AWAIT_TIMEOUT_MILLISECONDS = 75;
|
private static final long LATCH_AWAIT_TIMEOUT_MILLISECONDS = 120;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as a workaround to fix the issue of YT calling back button handlers out of order.
|
* Used as a workaround to fix the issue of YT calling back button handlers out of order.
|
||||||
@ -84,7 +85,8 @@ public final class NavigationBar {
|
|||||||
// The latch is released from the main thread, and waiting from the main thread will always timeout.
|
// The latch is released from the main thread, and waiting from the main thread will always timeout.
|
||||||
// This situation has only been observed when navigating out of a submenu and not changing tabs.
|
// This situation has only been observed when navigating out of a submenu and not changing tabs.
|
||||||
// and for that use case the nav bar does not change so it's safe to return here.
|
// and for that use case the nav bar does not change so it's safe to return here.
|
||||||
Logger.printDebug(() -> "Cannot block main thread waiting for nav button. Using last known navbar button status.");
|
Logger.printDebug(() -> "Cannot block main thread waiting for nav button. " +
|
||||||
|
"Using last known navbar button status.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +104,9 @@ public final class NavigationBar {
|
|||||||
Logger.printDebug(() -> "Latch wait timed out");
|
Logger.printDebug(() -> "Latch wait timed out");
|
||||||
|
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Logger.printException(() -> "Latch wait interrupted failure", ex); // Will never happen.
|
// Calling YouTube thread was interrupted.
|
||||||
|
Logger.printException(() -> "Latch wait interrupted", ex);
|
||||||
|
Thread.currentThread().interrupt(); // Restore interrupt status flag.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +260,8 @@ public final class NavigationBar {
|
|||||||
* <p>
|
* <p>
|
||||||
* All code calling this method should handle a null return value.
|
* All code calling this method should handle a null return value.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Due to issues with how YT processes physical back button events,
|
* <b>Due to issues with how YT processes physical back button/gesture events,
|
||||||
* this patch uses workarounds that can cause this method to take up to 75ms
|
* this patch uses workarounds that can cause this method to take up to 120ms
|
||||||
* if the device back button was recently pressed.</b>
|
* if the device back button was recently pressed.</b>
|
||||||
*
|
*
|
||||||
* @return The active navigation tab.
|
* @return The active navigation tab.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user