title: How to make sure that a new view controller is visible to the user?
body: <p>First of all the native macOS application is made into an accessory type application 3 seconds after launching (to show an info screen first, before the app goes into the system menu bar):</p>
  
  <pre class="lang-swift prettyprint-override"><code>DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
      NSApplication.shared.setActivationPolicy(.accessory)
  }
  </code></pre>
  
  <p>It has a status bar menu created with:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class func createMenu(color: Bool) -&gt; Void {
      let statusBar = NSStatusBar.system
      self.sharedInstance.storedStatusItem = statusBar.statusItem(withLength: NSStatusItem.variableLength)
      self.sharedInstance.storedStatusItem.menu = ABCMenu.statusBarMenu()
  }
  </code></pre>
  
  <p>The user has several options in the status bar menu to open different screens with controls. One of them is shown with:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class func showServiceViewController() -&gt; Void {
  
      let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
      guard let vc = storyboard.instantiateController(withIdentifier: "ABCServiceViewController") as? ABCServiceViewController, let checkedWindow = ABCUIManager.sharedInstance.window else {
          return
      }
  
      checkedWindow.contentViewController = vc
      checkedWindow.setIsVisible(true)
      checkedWindow.orderFrontRegardless()
  }
  </code></pre>
  
  <p>The problem is that sometimes the selected view controller is not brought to the background and has to be found underneath many other already opened applications and windows. Most of the time it works fine, but not always.</p>
  
  <p>Are there any better ways to assure that the new view controller is always brought up to the highest level and shown to the user?</p>
  
  <p>Thank you for any suggestions.</p>