fix: enable BrowserWindow.id
access post-destruction (#38241)
fix: enable BrowserWindow id access post-destruction
This commit is contained in:
parent
042663e190
commit
9bd9d312f8
2 changed files with 15 additions and 0 deletions
|
@ -12,6 +12,14 @@ BrowserWindow.prototype._init = function (this: BWT) {
|
||||||
// Avoid recursive require.
|
// Avoid recursive require.
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
|
// Set ID at constructon time so it's accessible after
|
||||||
|
// underlying window destruction.
|
||||||
|
const id = this.id;
|
||||||
|
Object.defineProperty(this, 'id', {
|
||||||
|
value: id,
|
||||||
|
writable: false
|
||||||
|
});
|
||||||
|
|
||||||
const nativeSetBounds = this.setBounds;
|
const nativeSetBounds = this.setBounds;
|
||||||
this.setBounds = (bounds, ...opts) => {
|
this.setBounds = (bounds, ...opts) => {
|
||||||
bounds = {
|
bounds = {
|
||||||
|
|
|
@ -126,6 +126,13 @@ describe('BrowserWindow module', () => {
|
||||||
w.webContents.on('destroyed', () => w.close());
|
w.webContents.on('destroyed', () => w.close());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow access to id after destruction', async () => {
|
||||||
|
const closed = once(w, 'closed');
|
||||||
|
w.destroy();
|
||||||
|
await closed;
|
||||||
|
expect(w.id).to.be.a('number');
|
||||||
|
});
|
||||||
|
|
||||||
it('should emit unload handler', async () => {
|
it('should emit unload handler', async () => {
|
||||||
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
|
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
|
||||||
const closed = once(w, 'closed');
|
const closed = once(w, 'closed');
|
||||||
|
|
Loading…
Reference in a new issue