Skip to content

Commit

Permalink
fix: enable BrowserWindow id access post-destruction
Browse files Browse the repository at this point in the history
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed May 16, 2023
1 parent e6dc982 commit a3d20a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit a3d20a9

Please sign in to comment.