Cristian006/frameless-titlebar

How can I "unmaximise" after maximising window?

Closed this issue · 4 comments

After upgrading to 2.1.3, I can no longer unmaximise the window in an Electron app. This worked in version 1.0.8.

To Reproduce

  1. Instantiate a TitleBar with prop: onMaximize={ () => remote.getCurrentWindow().maximize() }
  2. Run app and click on the Maximise button.
  3. Click Maximise button again.
  4. Nothing happens.

Expected behavior
After maximising, the button should change appearance, and clicking again should revert the window to its previous dimensions.

I could of course write my own logic in the onMaximize handler, but I still wouldn't get the right icon shown in the maximised state.

Desktop (please complete the following information):

  • OS: Windows 10

My current solution is:

componentDidMount() {
    const currentWindow = remote.getCurrentWindow();
    currentWindow.on("maximize", () => this.setState({ maximized: true }));
    currentWindow.on("unmaximize", () => this.setState({ maximized: false }));
  }

  componentWillUnmount() {
    const currentWindow = remote.getCurrentWindow();
    currentWindow.removeListener("maximize", () =>
      this.setState({ maximized: true })
    );
    currentWindow.removeListener("unmaximize", () =>
      this.setState({ maximized: false })
    );
  }

And then in the props do

onMaximize={() => {
              if (this.state.maximized) {
                currentWindow.unmaximize();
              } else {
                currentWindow.maximize();
              }
            }}

However, like you said, the buttons don't change icons. I think it was lost between v1.x to the newer versions. I would be down to help re-implementing it though a PR if it's needed.

Thanks for posting a solution, @anqingchen.

Unforunately I don't really have time to work on a PR for this library at the moment, so I will revert back down to 1.0.8 for now as that version was working just fine for me.

@anqingchen the title bar component changed in v2 to call onMaximize, onMinimize, onClose props when the window control buttons are pressed to remove electron as a dependency. It allows apps to individually handle their own application logic. I just noticed that the maximize icon doesn't update once maximized to the restore icon. Working on a solution that will be released with v2.2. Thanks!

tegab commented

great project. any update on unmaximise?