简体   繁体   中英

Electron "unminimize"

I'm trying to find a way to make electron go from minimized, back to the last size of the open app - that is, simulating what happens when you click on a minimized app normally.

What I ideally want (but obviously doesn't work as it is not a function):

if (mainWindow.isMinimized()) {
    mainWindow.unminimize()
  }

What would also be acceptable, but I haven't been able to get to work:

if (mainWindow.isMinimized()) {
    mainWindow.setSize(1100, 950)
  }

What currently works, but doesn't bring me the desired result:

if (mainWindow.isMinimized()) {
    mainWindow.maximize()
  }

If anyone has a cool trick to simulate this function, or atleast a tip on how to go from minimized to a set screen size, you'd make my day! :)

AFIAK mainWindow.setSize(width, height[, animate]) doesn't know about the window state (ie maximized or minimzed). Therefore changing the size parameters with mainWindow.setSize() won't effect the state of the window.

As OliverRadini points out you can use mainWindow.restore() . The docs are pretty simple...

win.restore()

Restores the window from minimized state to its previous state.

So, using your code you should be able to do...

if (mainWindow.isMinimized()) {
    mainWindow.restore()
}

Hope that helps!

For those who are looking to restore the window size using the maximize button after it's been maximized:

onMaximizeWindow() {
    if (this.electronService.window.isMaximized()) this.electronService.window.restore();
    else this.electronService.window.maximize();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM