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

fix: enable BrowserWindow.id access post-destruction #38309

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/browser/api/browser-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ BrowserWindow.prototype._init = function (this: BWT) {
// Avoid recursive require.
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;
this.setBounds = (bounds, ...opts) => {
bounds = {
Expand Down
7 changes: 7 additions & 0 deletions spec/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ describe('BrowserWindow module', () => {
w.webContents.on('destroyed', () => w.close());
});

it('should allow access to id after destruction', async () => {
const closed = emittedOnce(w, 'closed');
w.destroy();
await closed;
expect(w.id).to.be.a('number');
});

it('should emit unload handler', async () => {
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
const closed = emittedOnce(w, 'closed');
Expand Down
Loading