I think you should also check to see if there is a Modal Dialog open and not try to send it a message in that case.  It would be great to check for a brackets modal dialog as well but I think we should at least check that a File Open / Save As, etc... dialog isn't open