rhysd / electron-about-window

'About This App' mini-window for Electron apps
https://www.npmjs.com/package/about-window
MIT License
409 stars 46 forks source link

Calling openAboutWindow multiple times presents multiple about windows #72

Open BillyRayPreachersSon opened 2 years ago

BillyRayPreachersSon commented 2 years ago

I'm using electron:^16.0.5, about-window:^1.15.2, and running on Mac OS Big Sur 11.6.1.

Wiring up a call to openAboutWindow from my About context menu item's click handler, the About window opens as expected when the menu item is chosen.

However, if the menu item is chosen again before the About window is closed, multiple About windows will be presented.

Is it possible to show the first window if it is still present?

{
  label: 'About',
  click: () => openAboutWindow({
    ...
  }),
},
BillyRayPreachersSon commented 2 years ago

For the moment, I've worked around this by keeping track of the About window, but it would be nice to not have this extra code. Perhaps if multiple windows are desirable, make this configurable?

let aboutWindow = null;

function closeAboutWindow() {
  aboutWindow.off('close', closeAboutWindow);
  aboutWindow = null;
}

function openSingleAboutWindow() {
  if (aboutWindow) {
    aboutWindow.show();
  } else {
    aboutWindow = openAboutWindow({
      ...
    });
    aboutWindow.on('close', closeAboutWindow);
  }
}

...

{
  label: 'About',
  click: openSingleAboutWindow,
},