feat: add app.isHidden API for macOS (#32155)
* feat: add app.isHidden API * Update docs/api/app.md Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fixed isHidden tests * Update docs/api/app.md Co-authored-by: John Kleinschmidt <jkleinsc@github.com> * Update spec-main/api-app-spec.ts Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
This commit is contained in:
parent
9c3b159b95
commit
a9296229c8
5 changed files with 28 additions and 1 deletions
|
@ -606,6 +606,10 @@ You should seek to use the `steal` option as sparingly as possible.
|
|||
|
||||
Hides all application windows without minimizing them.
|
||||
|
||||
### `app.isHidden()` _macOS_
|
||||
|
||||
Returns `boolean` - `true` if the application—including all of its windows—is hidden (e.g. with `Command-H`), `false` otherwise.
|
||||
|
||||
### `app.show()` _macOS_
|
||||
|
||||
Shows application windows after they were hidden. Does not automatically focus
|
||||
|
|
|
@ -1769,6 +1769,7 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
|
|||
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
|
||||
.SetMethod("isHidden", base::BindRepeating(&Browser::IsHidden, browser))
|
||||
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
|
||||
.SetMethod("setUserActivity",
|
||||
base::BindRepeating(&Browser::SetUserActivity, browser))
|
||||
|
|
|
@ -158,6 +158,7 @@ class Browser : public WindowListObserver {
|
|||
|
||||
// Hide the application.
|
||||
void Hide();
|
||||
bool IsHidden();
|
||||
|
||||
// Show the application.
|
||||
void Show();
|
||||
|
|
|
@ -117,6 +117,10 @@ void Browser::Hide() {
|
|||
[[AtomApplication sharedApplication] hide:nil];
|
||||
}
|
||||
|
||||
bool Browser::IsHidden() {
|
||||
return [[AtomApplication sharedApplication] isHidden];
|
||||
}
|
||||
|
||||
void Browser::Show() {
|
||||
[[AtomApplication sharedApplication] unhide:nil];
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import { promisify } from 'util';
|
|||
import { app, BrowserWindow, Menu, session, net as electronNet } from 'electron/main';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { closeWindow, closeAllWindows } from './window-helpers';
|
||||
import { ifdescribe, ifit } from './spec-helpers';
|
||||
import { ifdescribe, ifit, waitUntil } from './spec-helpers';
|
||||
import split = require('split')
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, '../spec/fixtures');
|
||||
|
@ -1575,6 +1575,23 @@ describe('app module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
ifdescribe(process.platform === 'darwin')('app hide and show API', () => {
|
||||
describe('app.isHidden', () => {
|
||||
it('returns true when the app is hidden', async () => {
|
||||
app.hide();
|
||||
await expect(
|
||||
waitUntil(() => app.isHidden())
|
||||
).to.eventually.be.fulfilled();
|
||||
});
|
||||
it('returns false when the app is shown', async () => {
|
||||
app.show();
|
||||
await expect(
|
||||
waitUntil(() => !app.isHidden())
|
||||
).to.eventually.be.fulfilled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const dockDescribe = process.platform === 'darwin' ? describe : describe.skip;
|
||||
dockDescribe('dock APIs', () => {
|
||||
after(async () => {
|
||||
|
|
Loading…
Reference in a new issue