Browse Source

Reset helper when makeTouchBar is called

Kevin Sawicki 8 years ago
parent
commit
14ef5c5957
2 changed files with 8 additions and 13 deletions
  1. 4 9
      atom/browser/native_window_mac.mm
  2. 4 4
      atom/browser/ui/cocoa/atom_touch_bar.mm

+ 4 - 9
atom/browser/native_window_mac.mm

@@ -352,9 +352,8 @@ bool ScopedDisableResize::disable_resize_ = false;
 - (void)setShell:(atom::NativeWindowMac*)shell;
 - (void)setEnableLargerThanScreen:(bool)enable;
 - (void)enableWindowButtonsOffset;
-- (void)reloadTouchBar;
-- (void)refreshTouchBarItem:(mate::Arguments*)args;
 - (void)resetTouchBar;
+- (void)refreshTouchBarItem:(mate::Arguments*)args;
 @end
 
 @interface AtomNSWindow () <NSTouchBarDelegate>
@@ -365,7 +364,6 @@ bool ScopedDisableResize::disable_resize_ = false;
 
 - (void)setShell:(atom::NativeWindowMac*)shell {
   shell_ = shell;
-  touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self window:shell]);
 }
 
 - (void)setEnableLargerThanScreen:(bool)enable {
@@ -376,16 +374,12 @@ bool ScopedDisableResize::disable_resize_ = false;
   self.touchBar = nil;
 }
 
-- (void)reloadTouchBar {
-  [touch_bar_ clear];
-  self.touchBar = nil;
-}
-
 - (void)refreshTouchBarItem:(mate::Arguments*)args {
   [touch_bar_ refreshTouchBarItem:args];
 }
 
 - (NSTouchBar*)makeTouchBar {
+  touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self window:shell_]);
   return [touch_bar_ makeTouchBarFromItemOptions:shell_->GetTouchBarItems()];
 }
 
@@ -1377,6 +1371,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
 }
 
 void NativeWindowMac::DestroyTouchBar() {
+  touch_bar_items_.clear();
   [window_ resetTouchBar];
 }
 
@@ -1384,7 +1379,7 @@ void NativeWindowMac::SetTouchBar(mate::Arguments* args) {
   std::vector<mate::PersistentDictionary> items;
   if (args->GetNext(&items)) {
     touch_bar_items_ = items;
-    [window_ reloadTouchBar];
+    [window_ resetTouchBar];
   }
 }
 

+ 4 - 4
atom/browser/ui/cocoa/atom_touch_bar.mm

@@ -161,7 +161,7 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
 }
 
 - (NSTouchBarItem*)makeButtonForID:(NSString*)id
-                             withIdentifier:(NSString*)identifier {
+                    withIdentifier:(NSString*)identifier {
   std::string s_id([id UTF8String]);
   if (![self hasItemWithID:s_id]) return nil;
 
@@ -213,7 +213,7 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
 }
 
 - (NSTouchBarItem*)makeLabelForID:(NSString*)id
-                            withIdentifier:(NSString*)identifier {
+                   withIdentifier:(NSString*)identifier {
   std::string s_id([id UTF8String]);
   if (![self hasItemWithID:s_id]) return nil;
 
@@ -260,7 +260,7 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
 }
 
 - (NSTouchBarItem*)makeSliderForID:(NSString*)id
-                             withIdentifier:(NSString*)identifier {
+                    withIdentifier:(NSString*)identifier {
   std::string s_id([id UTF8String]);
   if (![self hasItemWithID:s_id]) return nil;
 
@@ -296,7 +296,7 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
 }
 
 - (NSTouchBarItem*)makePopoverForID:(NSString*)id
-                              withIdentifier:(NSString*)identifier {
+                     withIdentifier:(NSString*)identifier {
   std::string s_id([id UTF8String]);
   if (![self hasItemWithID:s_id]) return nil;