* Fix for Mac OS X quit behaviour (Dock->Quit, CTRL+Q) not being executed when application is closed via Quit rather than clicking [X] on the main window

This commit is contained in:
Reinhard Pointner 2014-10-09 17:30:43 +00:00
parent 3455ea9e0e
commit 92b2ecc8ba
4 changed files with 34 additions and 34 deletions

View File

@ -30,7 +30,6 @@
<classpathentry kind="lib" path="lib/xmlrpc.jar"/>
<classpathentry kind="lib" path="lib/xz.jar"/>
<classpathentry kind="lib" path="lib/ObjCBridge.jar"/>
<classpathentry kind="lib" path="lib/build/AppleJavaExtensions.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -28,6 +28,17 @@ public final class HistorySpooler {
return instance;
}
// commit session history on shutdown
static {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
HistorySpooler.getInstance().commit();
}
});
}
private File persistentHistoryFile = new File(getApplicationFolder(), "history.xml");
private int persistentHistoryTotalSize = -1;
private boolean persistentHistoryEnabled = true;

View File

@ -170,15 +170,6 @@ public class Main {
// CLI mode => run command-line interface and then exit
if (args.runCLI()) {
// commit session history on shutdown
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
HistorySpooler.getInstance().commit();
}
}));
// default cross-platform laf used in scripting to nimbus instead of metal (if possible)
if (args.script != null && !isHeadless()) {
try {
@ -272,6 +263,8 @@ public class Main {
@Override
public void windowClosing(WindowEvent e) {
e.getWindow().setVisible(false);
// make sure any long running operations are done now and not later on the shutdownhook thread
HistorySpooler.getInstance().commit();
if (!isAppStore()) {

View File

@ -1,9 +1,8 @@
package net.filebot.mac;
import java.awt.EventQueue;
import java.awt.Window;
import java.awt.event.WindowEvent;
import java.io.File;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -11,10 +10,6 @@ import javax.swing.UIManager;
import ca.weblite.objc.Client;
import com.apple.eawt.Application;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;
public class MacAppUtilities {
private static Client _objc;
@ -40,7 +35,9 @@ public class MacAppUtilities {
public static void setWindowCanFullScreen(Window window) {
try {
com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true);
Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");
Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, boolean.class });
setWindowCanFullScreen.invoke(null, window, true);
} catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
}
@ -48,7 +45,10 @@ public class MacAppUtilities {
public static void requestForeground() {
try {
com.apple.eawt.Application.getApplication().requestForeground(true);
Class<?> application = Class.forName("com.apple.eawt.Application");
Object instance = application.getMethod("getApplication").invoke(null);
Method requestForeground = application.getMethod("requestForeground", new Class<?>[] { boolean.class });
requestForeground.invoke(instance, true);
} catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "requestForeground not supported: " + t);
}
@ -56,7 +56,9 @@ public class MacAppUtilities {
public static void revealInFinder(File file) {
try {
com.apple.eio.FileManager.revealInFinder(file);
Class<?> fileManager = Class.forName("com.apple.eio.FileManager");
Method revealInFinder = fileManager.getMethod("revealInFinder", new Class<?>[] { File.class });
revealInFinder.invoke(null, file);
} catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "revealInFinder not supported: " + t);
}
@ -67,21 +69,16 @@ public class MacAppUtilities {
UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant"));
// make sure Application Quit Events get forwarded to normal Window Listeners
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
@Override
public void handleQuit(ApplicationEvent evt) {
for (Window window : Window.getOwnerlessWindows()) {
// close all windows
window.setVisible(false);
// call window listeners
EventQueue.invokeLater(() -> {
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
});
}
}
});
try {
Class<?> application = Class.forName("com.apple.eawt.Application");
Object instance = application.getMethod("getApplication").invoke(null);
Class<?> quitStrategy = Class.forName("com.apple.eawt.QuitStrategy");
Method setQuitStrategy = application.getMethod("setQuitStrategy", quitStrategy);
Object closeAllWindows = quitStrategy.getField("CLOSE_ALL_WINDOWS").get(null);
setQuitStrategy.invoke(instance, closeAllWindows);
} catch (Throwable t) {
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setQuitStrategy not supported: " + t);
}
}
public static boolean isLockedFolder(File folder) {