Skip to content

Commit

Permalink
Fix quitting on macOS
Browse files Browse the repository at this point in the history
The QuitHandler that proxies our Exit action needs to call
the performQuit() method on the QuitResponse that it receives.
See the Javadoc for com.apple.eawt.QuitHandler.handleQuitRequestWith()
which says:

  /**
   * Invoked when the application is asked to quit.
   *
   * Implementors must call either {@link QuitResponse#cancelQuit()}, {@link QuitResponse#performQuit()}, or ensure the application terminates.
   * The process (or log-out) requesting this app to quit will be blocked until the {@link QuitResponse} is handled.
   ...

Fixes #247
  • Loading branch information
jkaving committed Oct 15, 2020
1 parent d04f11d commit 13bd07c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void actionPerformed(final ActionEvent e) {
}

// Used by OS X adaptations
public void quit() {
public boolean quit() {
actionPerformed(null);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void addOSXHandler(String handlerClassName,

Class<?> handlerClass = Class.forName(handlerClassName);
if (action != null) {
Object aboutHandlerProxy =
Object handlerProxy =
Proxy.newProxyInstance(OSXSupport.class.getClassLoader(),
new Class[]{handlerClass},
new InvocationHandler() {
Expand All @@ -121,10 +121,14 @@ public Object invoke(Object o, Method method, Object[] args) throws Throwable {
if (method.getName().equals(handlerMethodName)) {
action.actionPerformed(null);
}
if (method.getName().equals("handleQuitRequestWith")) {
Object quitResponse = args[1];
Class.forName("com.apple.eawt.QuitResponse").getDeclaredMethod("performQuit").invoke(quitResponse);
}
return null;
}
});
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, aboutHandlerProxy);
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, handlerProxy);
} else {
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, (Object) null);
}
Expand Down

0 comments on commit 13bd07c

Please sign in to comment.