Menu refresh fails for separators


#1

I’m trying to add some new features fo favorites package and I’ve got this show stopper.

Added this in .atom/init.js


let favoritesMenu = undefined  // disposable menu

atom.commands.add('atom-workspace', '000:Refresh', event => {
  refresh()
})
atom.commands.add('atom-workspace', '000:Dispose', event => {
  dispose()
})

function refresh(){
  if(favoritesMenu){
    favoritesMenu.dispose()
  }
  const favoriteMenuItems = []
  favoriteMenuItems.push({ label: 'item1'})
  favoriteMenuItems.push({ type: 'separator'})
  favoriteMenuItems.push({ label: 'item2'})

  favoritesMenu = atom.menu.add ([
    {
      label: 'File',
      submenu : [{
        label: 'Test',
        submenu: favoriteMenuItems
      }]
    }
  ])

}
function dispose(){
  if(favoritesMenu){
    favoritesMenu.dispose()
  }

}

If I execute command 000:Refresh multiple times I end up with this

When I do 000:Dispose it removes all items except for separator.

I thought favoritesMenu.dispose() will do its job of removing all items. Seems it forgets about separators.

I ran out of ideas. Any help would be much appreciated.


#2

Hello.

I have tried your tasks in the development console. My findings support your findings which I now repeat in descriptions below.

The result is:

My observations:

  • Creating the menu items the first time works like expected.

  • When the object is disposed the “Test” item remains with an “empty” sub-menu. In actual fact the “sub-menu” is not empty - it has a separator.
    image

  • The left-over separator remains when you call the re-creation of the menu.

  • When disposing the object and then restarting Atom, makes the “Test” menu item to go away. That makes me wonder if an update trigger is not required.

I have no solution for you.


#3

update… Occurrence reported on:
https://github.com/atom/atom/issues/16508