From 5d98e5e78ac209ea22473d81f035242a63b8eef1 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 25 Aug 2021 10:06:12 +0900 Subject: [PATCH] fix: crash when using TouchBarScrubber arrow button (#30680) Co-authored-by: Shelley Vohr --- docs/api/touch-bar-scrubber.md | 2 +- shell/browser/ui/cocoa/electron_touch_bar.mm | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/api/touch-bar-scrubber.md b/docs/api/touch-bar-scrubber.md index c21f6e1383fd2..264c93e4dfc20 100644 --- a/docs/api/touch-bar-scrubber.md +++ b/docs/api/touch-bar-scrubber.md @@ -14,7 +14,7 @@ Process: [Main](../glossary.md#main-process) * `highlightedIndex` Integer - The index of the item the user touched. * `selectedStyle` String (optional) - Selected item style. Can be `background`, `outline` or `none`. Defaults to `none`. * `overlayStyle` String (optional) - Selected overlay item style. Can be `background`, `outline` or `none`. Defaults to `none`. - * `showArrowButtons` Boolean (optional) - Defaults to `false`. + * `showArrowButtons` Boolean (optional) - Whether to show arrow buttons. Defaults to `false` and is only shown if `items` is non-empty. * `mode` String (optional) - Can be `fixed` or `free`. The default is `free`. * `continuous` Boolean (optional) - Defaults to `true`. diff --git a/shell/browser/ui/cocoa/electron_touch_bar.mm b/shell/browser/ui/cocoa/electron_touch_bar.mm index e4b47a29543a7..6b3a1383dd0ed 100644 --- a/shell/browser/ui/cocoa/electron_touch_bar.mm +++ b/shell/browser/ui/cocoa/electron_touch_bar.mm @@ -735,7 +735,10 @@ - (void)updateScrubber:(NSCustomTouchBarItem*)item bool showsArrowButtons = false; settings.Get("showArrowButtons", &showsArrowButtons); - scrubber.showsArrowButtons = showsArrowButtons; + // The scrubber will crash if the user tries to scroll + // and there are no items. + if ([self numberOfItemsForScrubber:scrubber] > 0) + scrubber.showsArrowButtons = showsArrowButtons; std::string selectedStyle; std::string overlayStyle;