Skip to content

Commit 13bd07c

Browse files
committed
Fix quitting on macOS
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
1 parent d04f11d commit 13bd07c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Exit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public void actionPerformed(final ActionEvent e) {
3939
}
4040

4141
// Used by OS X adaptations
42-
public void quit() {
42+
public boolean quit() {
4343
actionPerformed(null);
44+
return true;
4445
}
4546
}

src/main/java/com/tagtraum/perf/gcviewer/view/util/OSXSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static void addOSXHandler(String handlerClassName,
112112

113113
Class<?> handlerClass = Class.forName(handlerClassName);
114114
if (action != null) {
115-
Object aboutHandlerProxy =
115+
Object handlerProxy =
116116
Proxy.newProxyInstance(OSXSupport.class.getClassLoader(),
117117
new Class[]{handlerClass},
118118
new InvocationHandler() {
@@ -121,10 +121,14 @@ public Object invoke(Object o, Method method, Object[] args) throws Throwable {
121121
if (method.getName().equals(handlerMethodName)) {
122122
action.actionPerformed(null);
123123
}
124+
if (method.getName().equals("handleQuitRequestWith")) {
125+
Object quitResponse = args[1];
126+
Class.forName("com.apple.eawt.QuitResponse").getDeclaredMethod("performQuit").invoke(quitResponse);
127+
}
124128
return null;
125129
}
126130
});
127-
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, aboutHandlerProxy);
131+
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, handlerProxy);
128132
} else {
129133
application.getClass().getMethod(handlerSetterMethodName, handlerClass).invoke(application, (Object) null);
130134
}

0 commit comments

Comments
 (0)