fix: correctly emit BrowserWindow alwaysOnTop status in change event (#19463)
* fix: correctly emit alwaysOnTop in change event * add a test for emitted alwaysOnTop value
This commit is contained in:
parent
4d23b9e031
commit
504407c5df
2 changed files with 26 additions and 11 deletions
|
@ -756,9 +756,7 @@ void NativeWindowViews::SetAlwaysOnTop(ui::ZOrderLevel z_order,
|
|||
const std::string& level,
|
||||
int relativeLevel,
|
||||
std::string* error) {
|
||||
if (z_order != widget()->GetZOrderLevel())
|
||||
NativeWindow::NotifyWindowAlwaysOnTopChanged();
|
||||
|
||||
bool level_changed = z_order != widget()->GetZOrderLevel();
|
||||
widget()->SetZOrderLevel(z_order);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
@ -773,6 +771,11 @@ void NativeWindowViews::SetAlwaysOnTop(ui::ZOrderLevel z_order,
|
|||
}
|
||||
#endif
|
||||
MoveBehindTaskBarIfNeeded();
|
||||
|
||||
// This must be notified at the very end or IsAlwaysOnTop
|
||||
// will not yet have been updated to reflect the new status
|
||||
if (level_changed)
|
||||
NativeWindow::NotifyWindowAlwaysOnTopChanged();
|
||||
}
|
||||
|
||||
ui::ZOrderLevel NativeWindowViews::GetZOrderLevel() {
|
||||
|
|
|
@ -1040,22 +1040,24 @@ describe('BrowserWindow module', () => {
|
|||
|
||||
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
|
||||
let w = null as unknown as BrowserWindow
|
||||
|
||||
beforeEach(() => {
|
||||
w = new BrowserWindow({show: false})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await closeWindow(w)
|
||||
w = null as unknown as BrowserWindow
|
||||
})
|
||||
|
||||
it('sets the window as always on top', () => {
|
||||
expect(w.isAlwaysOnTop()).to.equal(false)
|
||||
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop')
|
||||
w.setAlwaysOnTop(true, 'screen-saver')
|
||||
expect(w.isAlwaysOnTop()).to.equal(true)
|
||||
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop')
|
||||
w.setAlwaysOnTop(false)
|
||||
expect(w.isAlwaysOnTop()).to.equal(false)
|
||||
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop')
|
||||
w.setAlwaysOnTop(true)
|
||||
expect(w.isAlwaysOnTop()).to.equal(true)
|
||||
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop')
|
||||
})
|
||||
|
||||
ifit(process.platform === 'darwin')('raises an error when relativeLevel is out of bounds', () => {
|
||||
|
@ -1069,13 +1071,23 @@ describe('BrowserWindow module', () => {
|
|||
})
|
||||
|
||||
ifit(process.platform === 'darwin')('resets the windows level on minimize', () => {
|
||||
expect(w.isAlwaysOnTop()).to.equal(false)
|
||||
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop')
|
||||
w.setAlwaysOnTop(true, 'screen-saver')
|
||||
expect(w.isAlwaysOnTop()).to.equal(true)
|
||||
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop')
|
||||
w.minimize()
|
||||
expect(w.isAlwaysOnTop()).to.equal(false)
|
||||
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop')
|
||||
w.restore()
|
||||
expect(w.isAlwaysOnTop()).to.equal(true)
|
||||
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop')
|
||||
})
|
||||
|
||||
ifit(process.platform !== 'darwin')('causes the right value to be emitted on `always-on-top-changed`', (done) => {
|
||||
w.on('always-on-top-changed', (e, alwaysOnTop) => {
|
||||
expect(alwaysOnTop).to.be.true('is not alwaysOnTop')
|
||||
done()
|
||||
})
|
||||
|
||||
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop')
|
||||
w.setAlwaysOnTop(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue