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

BUG: Window minWidth and minHeight not working (FIX) #253

Closed
HazelNutHoney opened this issue Feb 6, 2024 · 2 comments · Fixed by #254
Closed

BUG: Window minWidth and minHeight not working (FIX) #253

HazelNutHoney opened this issue Feb 6, 2024 · 2 comments · Fixed by #254
Labels
bug Something isn't working

Comments

@HazelNutHoney
Copy link
Contributor

HazelNutHoney commented Feb 6, 2024

I was using custom electron titlebar and when I tried to use minWidth, or minHeightit was not working when I disabled the titlebar from my window it worked.

Here is my mainWindow code

const mainWindow = new BrowserWindow({
        width: 1024,
        height: 600,
        titleBarOverlay: true,
        titleBarStyle: "hidden",
        minHeight: 600,
        minWidth: 1024,
        webPreferences: {
            sandbox: false,
            preload: path.join(__dirname, "preload.js"),
            nodeIntegration: true,
        },
});
@HazelNutHoney
Copy link
Contributor Author

HazelNutHoney commented Feb 6, 2024

A fix for this is in the index.js in the custom-electron-titlebar/titlebar folder in this.currentOptions under the last option which is tooltips for me

tooltips: {
     close: 'Close',
     maximize: 'Maximize',
     minimize: 'Minimize',
     restoreDown: 'Restore Down'
},

then add

minWidth: 400,
minHeight: 270,

then in the same file in the setupMenubar function located at line 157 for me add

_get__("electron_1").ipcRenderer.send('window-set-minimumSize', this.currentOptions.minWidth, this.currentOptions.minHeight)

at the bottom of the function under (0, _get__("dom_1").append)(this.titlebar, this.menuBarContainer); in the options.d.ts file located in cusotm-electron-titlebar/titlebar add

/**
* Controls the Minimum Width the user is allowed to resize the window to.
* **The default is 400*
*/
minWidth?: 400,

/**
* Controls the Minimum Height the user is allowed to resize the window to.
* **The default is 270*
*/
minHeight?: 270,

under the tooltips defintion, and lastly in the custom-electron-titlebar/main in setup-titlebar.js add

ipcMain.on('window-set-minimumSize', (event, width, height) => {
    const window = BrowserWindow.fromWebContents(event.sender);
    /* eslint-disable indent */
    if (window) {
      console.log(width, height);
      window?.setMinimumSize(width, height);
    }
  });

under

ipcMain.on('window-event', (event, eventName) => {
    const window = BrowserWindow.fromWebContents(event.sender);
    /* eslint-disable indent */
    if (window) {
      switch (eventName) {
        case 'window-minimize':
          window?.minimize();
          break;
        case 'window-maximize':
          window?.isMaximized() ? window.unmaximize() : window?.maximize();
          break;
        case 'window-close':
          window?.close();
          break;
        case 'window-is-maximized':
          event.returnValue = window?.isMaximized();
          break;
        default:
          break;
      }
    }
  });

To use this in your preload.js file in the titlebar options add a minWidth and minHeight like you would normally to the mainWindow just this time its in titlebarOptions instead an example of this in the options is

window.addEventListener("DOMContentLoaded", () => {
    // Title bar implementation
    new Titlebar({
        minWidth: 1080,
        minHeight: 720,
    });
});

@HazelNutHoney HazelNutHoney reopened this Feb 6, 2024
@HazelNutHoney HazelNutHoney changed the title BUG: Window MinWidth and Height not working BUG: Window MinWidth and Height not working (FIX) Feb 6, 2024
@HazelNutHoney HazelNutHoney changed the title BUG: Window MinWidth and Height not working (FIX) BUG: Window minWidth and minHeight not working (FIX) Feb 6, 2024
@AlexTorresDev AlexTorresDev added the bug Something isn't working label Feb 6, 2024
@HazelNutHoney
Copy link
Contributor Author

@AlexTorresDev I created a pr that fixes this issue

@AlexTorresDev AlexTorresDev linked a pull request May 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants