Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8293700

[macos] Provide Quit handler for system menu bar

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx19
    • javafx
    • None

      In one project, we have to handle the quit-logic for MacOS ourselves,
      when the <quit app> menu entry is used.
      As background information - this menu entry is set in the class com.sun.glass.ui.mac.MacApplication.
      It's basically hard coded. Currently, in this project, the menu entry doesn't work in some cases.

      My Solution would be:

      Provide a method "Platform.setQuiteHandler(Supplier<Boolean>)"
      This handler is called when quit <appname> from the menu is called.
      If the handler returns true, all windows are closed. Otherwise, nothing happens.

      It would look like the following:
      ```
      /**
       * Sets the handler to be called when the application is about to quit.
       * Currently, this can only happen on MacOS.
       *
       * This handler is called, when the user selects
       * the "Quit <appname>" from the application menu.
       * When the provided handler returns true,
       * the application will close all windows.
       * If the handler returns false, the application will not quit.
       *
       * @param The new quit handler.
       */
      public static void setQuitHandler(Supplier x) {
          ...
      }
      ```

      I've got a working version for this change.

      Is this something, which is wanted for JavaFX?
      Should I create a pullrequest for this?

      Florian Kirmaier

            fkirmaier Florian Kirmaier
            fkirmaier Florian Kirmaier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: