From 32194f0f71222d5e0de81fc99641c47a7ce98236 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 24 Aug 2021 18:28:57 +0200 Subject: [PATCH] fix: crash when using TouchBarScrubber arrow button (#30661) --- 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 aa37c1e7aa98..889e39030985 100644 --- a/docs/api/touch-bar-scrubber.md +++ b/docs/api/touch-bar-scrubber.md @@ -15,7 +15,7 @@ _This class is not exported from the `'electron'` module. It is only available a * `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 e4b47a29543a..6b3a1383dd0e 100644 --- a/shell/browser/ui/cocoa/electron_touch_bar.mm +++ b/shell/browser/ui/cocoa/electron_touch_bar.mm @@ -735,7 +735,10 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.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;