diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 03430af57cc5..bd34993fb119 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -103,7 +103,6 @@ class NativeWindowMac : public NativeWindow, void SetTouchBar( const std::vector& items) override; void RefreshTouchBarItem(const std::string& item_id) override; - std::vector GetTouchBarItems(); // content::RenderWidgetHost::InputEventObserver: void OnInputEvent(const blink::WebInputEvent& event) override; @@ -158,8 +157,6 @@ class NativeWindowMac : public NativeWindow, base::scoped_nsobject window_; base::scoped_nsobject window_delegate_; - std::vector touch_bar_items_; - // Event monitor for scroll wheel event. id wheel_event_monitor_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b3ab36ed31f4..b59360ec3725 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -353,7 +353,7 @@ bool ScopedDisableResize::disable_resize_ = false; - (void)setShell:(atom::NativeWindowMac*)shell; - (void)setEnableLargerThanScreen:(bool)enable; - (void)enableWindowButtonsOffset; -- (void)resetTouchBar; +- (void)resetTouchBar:(const std::vector&)settings; - (void)refreshTouchBarItem:(const std::string&)item_id; @end @@ -368,7 +368,10 @@ bool ScopedDisableResize::disable_resize_ = false; enable_larger_than_screen_ = enable; } -- (void)resetTouchBar { +- (void)resetTouchBar:(const std::vector&)settings { + atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self + window:shell_ + settings:settings]); self.touchBar = nil; } @@ -377,8 +380,7 @@ bool ScopedDisableResize::disable_resize_ = false; } - (NSTouchBar*)makeTouchBar { - atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self window:shell_]); - return [atom_touch_bar_ makeTouchBarFromSettings:shell_->GetTouchBarItems()]; + return [atom_touch_bar_ makeTouchBar]; } - (nullable NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar @@ -1374,18 +1376,13 @@ void NativeWindowMac::SetVibrancy(const std::string& type) { void NativeWindowMac::SetTouchBar( const std::vector& items) { - touch_bar_items_ = items; - [window_ resetTouchBar]; + [window_ resetTouchBar:items]; } void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) { [window_ refreshTouchBarItem:item_id]; } -std::vector NativeWindowMac::GetTouchBarItems() { - return touch_bar_items_; -} - void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) { switch (event.type) { case blink::WebInputEvent::GestureScrollBegin: diff --git a/atom/browser/ui/cocoa/atom_touch_bar.h b/atom/browser/ui/cocoa/atom_touch_bar.h index d0146ec5f9f1..738536678b8d 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.h +++ b/atom/browser/ui/cocoa/atom_touch_bar.h @@ -19,15 +19,16 @@ @interface AtomTouchBar : NSObject { @protected + std::vector ordered_settings_; std::map settings_; std::map> items_; id delegate_; atom::NativeWindow* window_; } -- (id)initWithDelegate:(id)delegate window:(atom::NativeWindow*)window; +- (id)initWithDelegate:(id)delegate window:(atom::NativeWindow*)window settings:(const std::vector&)settings; -- (NSTouchBar*)makeTouchBarFromSettings:(const std::vector&)settings; +- (NSTouchBar*)makeTouchBar; - (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items; - (NSMutableArray*)identifiersFromSettings:(const std::vector&)settings; - (void)refreshTouchBarItem:(const std::string&)item_id; diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index 8a746ccbe2f1..277123f3bca7 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -20,16 +20,18 @@ static NSTouchBarItemIdentifier PopOverIdentifier = @"com.electron.touchbar.popo static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slider."; - (id)initWithDelegate:(id)delegate - window:(atom::NativeWindow*)window { + window:(atom::NativeWindow*)window + settings:(const std::vector&)settings { if ((self = [super init])) { delegate_ = delegate; window_ = window; + ordered_settings_ = settings; } return self; } -- (NSTouchBar*)makeTouchBarFromSettings:(const std::vector&)settings { - NSMutableArray* identifiers = [self identifiersFromSettings:settings]; +- (NSTouchBar*)makeTouchBar { + NSMutableArray* identifiers = [self identifiersFromSettings:ordered_settings_]; return [self touchBarFromItemIdentifiers:identifiers]; }