Browse Source

feat: allow windows to be excluded from the windows menu (#17404)

* feat: allow windows to be excluded from the windows menu

* excludedfromWindowsMenu => excludedFromShownWindowsMenu

* implement no-op for win & linux
Shelley Vohr 6 years ago
parent
commit
4e57a732a8

+ 11 - 0
atom/browser/api/atom_api_top_level_window.cc

@@ -567,6 +567,14 @@ void TopLevelWindow::SetSkipTaskbar(bool skip) {
   window_->SetSkipTaskbar(skip);
 }
 
+void TopLevelWindow::SetExcludedFromShownWindowsMenu(bool excluded) {
+  window_->SetExcludedFromShownWindowsMenu(excluded);
+}
+
+bool TopLevelWindow::IsExcludedFromShownWindowsMenu() {
+  return window_->IsExcludedFromShownWindowsMenu();
+}
+
 void TopLevelWindow::SetSimpleFullScreen(bool simple_fullscreen) {
   window_->SetSimpleFullScreen(simple_fullscreen);
 }
@@ -1133,6 +1141,9 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("addTabbedWindow", &TopLevelWindow::AddTabbedWindow)
       .SetMethod("setWindowButtonVisibility",
                  &TopLevelWindow::SetWindowButtonVisibility)
+      .SetProperty("excludedFromShownWindowsMenu",
+                   &TopLevelWindow::IsExcludedFromShownWindowsMenu,
+                   &TopLevelWindow::SetExcludedFromShownWindowsMenu)
 #endif
       .SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
       .SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)

+ 2 - 0
atom/browser/api/atom_api_top_level_window.h

@@ -145,6 +145,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
   std::string GetTitle();
   void FlashFrame(bool flash);
   void SetSkipTaskbar(bool skip);
+  void SetExcludedFromShownWindowsMenu(bool excluded);
+  bool IsExcludedFromShownWindowsMenu();
   void SetSimpleFullScreen(bool simple_fullscreen);
   bool IsSimpleFullScreen();
   void SetKiosk(bool kiosk);

+ 2 - 0
atom/browser/native_window.h

@@ -136,6 +136,8 @@ class NativeWindow : public base::SupportsUserData,
   virtual std::string GetTitle() = 0;
   virtual void FlashFrame(bool flash) = 0;
   virtual void SetSkipTaskbar(bool skip) = 0;
+  virtual void SetExcludedFromShownWindowsMenu(bool excluded) = 0;
+  virtual bool IsExcludedFromShownWindowsMenu() = 0;
   virtual void SetSimpleFullScreen(bool simple_fullscreen) = 0;
   virtual bool IsSimpleFullScreen() = 0;
   virtual void SetKiosk(bool kiosk) = 0;

+ 2 - 0
atom/browser/native_window_mac.h

@@ -87,6 +87,8 @@ class NativeWindowMac : public NativeWindow {
   std::string GetTitle() override;
   void FlashFrame(bool flash) override;
   void SetSkipTaskbar(bool skip) override;
+  void SetExcludedFromShownWindowsMenu(bool excluded) override;
+  bool IsExcludedFromShownWindowsMenu() override;
   void SetSimpleFullScreen(bool simple_fullscreen) override;
   bool IsSimpleFullScreen() override;
   void SetKiosk(bool kiosk) override;

+ 10 - 0
atom/browser/native_window_mac.mm

@@ -886,6 +886,16 @@ void NativeWindowMac::FlashFrame(bool flash) {
 
 void NativeWindowMac::SetSkipTaskbar(bool skip) {}
 
+bool NativeWindowMac::IsExcludedFromShownWindowsMenu() {
+  NSWindow* window = GetNativeWindow().GetNativeNSWindow();
+  return [window isExcludedFromWindowsMenu];
+}
+
+void NativeWindowMac::SetExcludedFromShownWindowsMenu(bool excluded) {
+  NSWindow* window = GetNativeWindow().GetNativeNSWindow();
+  [window setExcludedFromWindowsMenu:excluded];
+}
+
 void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
   NSWindow* window = GetNativeWindow().GetNativeNSWindow();
 

+ 7 - 0
atom/browser/native_window_views.cc

@@ -721,6 +721,13 @@ bool NativeWindowViews::IsMaximizable() {
 #endif
 }
 
+void NativeWindowViews::SetExcludedFromShownWindowsMenu(bool excluded) {}
+
+bool NativeWindowViews::IsExcludedFromShownWindowsMenu() {
+  // return false on unsupported platforms
+  return false;
+}
+
 void NativeWindowViews::SetFullScreenable(bool fullscreenable) {
   fullscreenable_ = fullscreenable;
 }

+ 2 - 0
atom/browser/native_window_views.h

@@ -97,6 +97,8 @@ class NativeWindowViews : public NativeWindow,
   std::string GetTitle() override;
   void FlashFrame(bool flash) override;
   void SetSkipTaskbar(bool skip) override;
+  void SetExcludedFromShownWindowsMenu(bool excluded) override;
+  bool IsExcludedFromShownWindowsMenu() override;
   void SetSimpleFullScreen(bool simple_fullscreen) override;
   bool IsSimpleFullScreen() override;
   void SetKiosk(bool kiosk) override;

+ 21 - 0
docs/api/browser-window.md

@@ -1648,3 +1648,24 @@ removed in future Electron releases.
 [vibrancy-docs]: https://developer.apple.com/documentation/appkit/nsvisualeffectview?preferredLanguage=objc
 [window-levels]: https://developer.apple.com/documentation/appkit/nswindow/level
 [chrome-content-scripts]: https://developer.chrome.com/extensions/content_scripts#execution-environment
+
+### Properties
+
+#### `win.excludedFromShownWindowsMenu` _macOS_
+
+A `Boolean` property that determines whether the window is excluded from the application’s Windows menu. `false` by default.
+
+```js
+const win = new BrowserWindow({ height: 600, width: 600 })
+
+const template = [
+  {
+    role: 'windowmenu'
+  }
+]
+
+win.excludedFromShownWindowsMenu = true
+
+const menu = Menu.buildFromTemplate(template)
+Menu.setApplicationMenu(menu)
+```