In an ordinary electron app, regular application etiquette of the OS the user is using is applied. However, for me (Using Windows OS), the F11 keybind (typically used to put apps into fullscreen and out of fullscreen) only works for putting my electron app in fullscreen. Once in fullscreen, when the button is pressed again, it does not revert back to the application’s original size before going into fullscreen, instead doing nothing and requiring me to implement a button to take the app out of fullscreen.
Here is the app in question:
const { app, BrowserWindow, screen, ipcMain } = require('electron');
let max = true;
const createWindow = () => {
const targetDisplay = screen.getPrimaryDisplay();
let {width, height} = targetDisplay.workAreaSize;
const win = new BrowserWindow({
width: width,
height: height,
icon: "icon.png" ,
fullscreen: false,
autoHideMenuBar: true,
frame: false,
transparent: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
allowRunningInsecureContent: true
}
});
win.loadFile('src/os/index.html');
win.on('move', () => {
const targetDisplay = screen.getDisplayMatching(win.getBounds());
});
win.on('enter-full-screen', () =>{
win.webContents.send('fullScreen');
})
win.on('leave-full-screen', () =>{
win.webContents.send('fullScreen');
})
ipcMain.on('closeWindow', () => {
win.close();
});
ipcMain.on('minimizeWindow', () => {
win.minimize();
});
ipcMain.on('resizeWindow', () => {
const targetDisplay = screen.getDisplayMatching(win.getBounds());
const { width, height } = targetDisplay.workAreaSize;
if (max === false) {
win.setPosition(targetDisplay.bounds.x, targetDisplay.bounds.y, true);
win.setSize(width, height, true)
max = true;
} else {
win.setPosition(targetDisplay.bounds.x + width/4.0, targetDisplay.bounds.y + height/4.0, true);
win.setSize(width/2.0, height/2.0, true);
max = false;
}
});
}
app.whenReady().then(() => {
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
};
});
I at first thought this was due to electron not being able to run browser insecure content. However, after specifying to the window that it was allowed to run insecure content, with the lineallowRunningInsecureContent: true
, the same issue continued.
Any ideas why this might be?