Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
Pressing Win + D causes an electron window that is not allowed to minimize to minimize on Windows 10

Using electron 16.9.1, I have built an app whose window is not allowed to minimize and whose alwaysOnTop property is set to false. To put it another way, the idea is to have a window that cannot be minimized and which is always "underneath" other windows.

The configuration of the window looks like this:

const win = new BrowserWindow({
    resizable: false,
    movable: false,
    minimizable: false,
    maximizable: false,
    alwaysOnTop: true,
    fullscreenable: false,
    show: false,
    frame: false,
    backgroundColor: "#00FFFFFF",
    transparent: true,
    webPreferences: {
        nodeIntegration: true,
        contextIsolation: false
    }
});

It works fine, the functions of the app function as I have planned, with but one tiny flaw: once I use the Win + D shortcut, the window is minimized. I am aware that many apps behave this way, but what I really want to know is whether there is a way to avoid this.

[Update] I realized the impossibility of what I am trying to ask for, and instead, I am now trying another approach: to listen to a "show the desktop" event in electron. Every time that event is triggered, I will show the window again. And so, the problem has now changed to: how do I monitor such an event?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What I really want to achieve is allowing any window to get over it, but not the desktop.

Every time that event is triggered, I will show the window again. And so, the problem has now changed to: how do I monitor such an event?

When minimizable: true is set, the BrowserWindow does fire minimize event when Win+D and Win+M are pressed. So, we can set minimizable: true and listen to those, including user minimize, events and restore the window. As frame:false is set user won't see minimize button only option of clicking on taskbar icon will be available.

let mainWindow;
let counter = 0;

function createWindow() {
 mainWindow = new BrowserWindow({
  width: 600,
  height: 300,
  show: false,
  resizable: false,
  movable: false,
  minimizable: true,   /* keep it true */
  maximizable: false,
  alwaysOnTop: false,
  fullscreenable: false,
  frame: false,
  backgroundColor: '#00FFFFFF',
  webPreferences: {
   preload: path.join(__dirname, 'preload.js'),
   contextIsolation: true,
   enableRemoteModule: false,
   nodeIntegration: false,
  },
 });

 mainWindow.loadURL(indexPath);
 
 //try to restore window on minimize
 mainWindow.on('minimize', (e) => {
  e.preventDefault();
  console.log('minimize', ++counter);
  //try changing delay value
  setTimeout(() => mainWindow.restore(), 200);
 });

 mainWindow.on('restore', () => {
  console.log('restore', counter);
 });

 mainWindow.once('ready-to-show', () => {
  mainWindow.show();
  if (dev) {
   mainWindow.webContents.openDevTools();
  }
 });

 mainWindow.on('closed', function () {
  mainWindow = null;
 });
}


Desktop doesn't come infront immediately it takes time so we can't keep delay too low to restore our window. I've deliberately kept the delay high in the code for the demo. Once you call restore, next restore calls have no effect. Drawback is user will be able click on the application icon in taskbar and the application will bounce back.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Now We have to deal with disabling keyboard shortcut Win-D,
so we use globalShortcut module.

const { app, globalShortcut } = require('electron')
globalShortcut.unregister('Super+D')

try these keys INSTEAD of Super:

  • Meta

Also try Capital D and small d

PLEASE ALSO TRY:

globalShortcut.register('Super+D', function() {
        console.log('Blocked');
        return false;
    })

Don't get confused that I am asking you to register the key that you actually asked to unregister, THIS IDEA OF REGISTERING KEY CAME AS someone in GitHub said

Registering key in electron app makes it not to work anywhere.

Refer documentation:https://www.electronjs.org/docs/latest/api/global-shortcut#globalshortcutregisteraccelerator-callback

P. S I am sure this won't mostly work as windows owns the right of Win key but try it, I ask you to try many times as I have not tried it 😁


See
https://stackoverflow.com/a/44308648/14862885
It introduces you to a new module electronLocalshortcut
try:

const {app, globalShortcut} = require('electron');

win = new BrowserWindow();

electronLocalshortcut.register(win, 'Super+D', () => {//Even this uses the same REGISTER method to disable shortcut
    console.log('Windows Button pressed');
    return false;
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda