Skip to content

MenuItem of type 'checkbox' doesn't get visually updated when modifying 'checked'' value. #5055

@hvmonteiro

Description

@hvmonteiro
  • Electron version: 0.37.2
  • Operating system: Fedora 23 and Windows 7

MenuItem of type 'checkbox' doesn't get updated in it's corresponding Menu when the value changes from true to false and vice-versa. This happens in both Linux and Windows.

According to documentation http://electron.atom.io/docs/v0.37.4/api/menu-item/#instance-properties that property can be changed at runtime, and I can confirm it does get changed, but it's value is not reflected in the corresponding menu.
If you click on the Menu Item, the checkbox visually changes correctly (loops from checked to unchecked) but the value of it's 'item.checked' is not changed correctly to 'false' if unchecked or 'true' if checked.

Here's a small portion of the code I used to check this:


var sysTrayMenu = [{
  label: 'Show Window',
  type: 'checkbox',
  checked: true,
  click: function (item, BrowserWindow) {
    if (mainWindow.isVisible()) {
      mainWindow.hide();
      item.checked = false;
    } else {
      mainWindow.show();
      item.checked = true;
    }
    console.log(contextMenu.items[0].checked);
  }
}, {
  label: 'On Top',
  type: 'checkbox',
  checked: false,
  click: function (item, BrowserWindow) {
    mainWindow.setAlwaysOnTop(item.checked);
    appMenu.items[0].submenu.items[3].checked = item.checked;
  }
}, {
  type: 'separator'
}, {
  label: 'Quit',
  accelerator: 'CmdOrCtrl+Q',
  click: function (item, BrowserWindow) {
    if (mainWindow) mainWindow.close();
  }
}];
var contextMenu = Menu.buildFromTemplate(sysTrayMenu);
  mainWindow.on('minimize', function () {
    if (appMenu.items[0].submenu.items[2].checked) { // appMenu Item 'Minimize To Tray'
      console.log(contextMenu.items[0].checked); // Value is set to 'true'
      contextMenu.items[0].checked = false; // Value does get modified
      console.log(contextMenu.items[0].checked); // Value is correctly set to 'false'
      mainWindow.hide();
    }
  });
  • Maybe I'm using it wrong. But it doesn't seem so.

Cheers,
Hugo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions