Closed HazelNutHoney closed 6 months ago
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,
});
});
@AlexTorresDev I created a pr that fixes this issue
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