I’m working on a package that needs to tell whether the sidebar is open. I know I could grab the DOM element using a selector, but that seems pretty hacky/brittle. I was hoping there was a more MVC-ish way of doing this.
From the top of my head, I think this should work:
isTreeViewOpen = -> unless atom.packages.isPackageLoaded('tree-view') || atom.packages.isPackageActive('tree-view') # tree-view package is neither loaded nor activated return false treeViewPkg = atom.packages.getActivePackage 'tree-view' treeView = treeViewPkg.mainModule.treeView unless treeView?.panel? # treeView hasn't been created or assigned a panel yet return false panelView = atom.views.getView treeView.panel unless panelView.parentNode? # tree view's panel isn't attached to DOM return false return true
I cant test this right now, and there might be a few more checks you want to perform, but it should give you a start
Works great (though I changed your || to && on the 2nd line). Thank you!
In that case, you don’t even need the
isLoaded, as an activated package is always also loaded. Guess you wouldn’t need it anyway, because the tree view can only be shown if the package is actually activated