Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions atom/browser/api/atom_api_top_level_window.cc
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_top_level_window.h
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/native_window.h
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/native_window_mac.h
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions atom/browser/native_window_mac.mm
Expand Up @@ -886,6 +886,16 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

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();

Expand Down
7 changes: 7 additions & 0 deletions atom/browser/native_window_views.cc
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/native_window_views.h
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions docs/api/browser-window.md
Expand Up @@ -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)
```