* 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:
parent
3455ea9e0e
commit
92b2ecc8ba
|
@ -30,7 +30,6 @@
|
||||||
<classpathentry kind="lib" path="lib/xmlrpc.jar"/>
|
<classpathentry kind="lib" path="lib/xmlrpc.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/xz.jar"/>
|
<classpathentry kind="lib" path="lib/xz.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ObjCBridge.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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -28,6 +28,17 @@ public final class HistorySpooler {
|
||||||
return instance;
|
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 File persistentHistoryFile = new File(getApplicationFolder(), "history.xml");
|
||||||
private int persistentHistoryTotalSize = -1;
|
private int persistentHistoryTotalSize = -1;
|
||||||
private boolean persistentHistoryEnabled = true;
|
private boolean persistentHistoryEnabled = true;
|
||||||
|
|
|
@ -170,15 +170,6 @@ public class Main {
|
||||||
|
|
||||||
// CLI mode => run command-line interface and then exit
|
// CLI mode => run command-line interface and then exit
|
||||||
if (args.runCLI()) {
|
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)
|
// default cross-platform laf used in scripting to nimbus instead of metal (if possible)
|
||||||
if (args.script != null && !isHeadless()) {
|
if (args.script != null && !isHeadless()) {
|
||||||
try {
|
try {
|
||||||
|
@ -272,6 +263,8 @@ public class Main {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
e.getWindow().setVisible(false);
|
e.getWindow().setVisible(false);
|
||||||
|
|
||||||
|
// make sure any long running operations are done now and not later on the shutdownhook thread
|
||||||
HistorySpooler.getInstance().commit();
|
HistorySpooler.getInstance().commit();
|
||||||
|
|
||||||
if (!isAppStore()) {
|
if (!isAppStore()) {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package net.filebot.mac;
|
package net.filebot.mac;
|
||||||
|
|
||||||
import java.awt.EventQueue;
|
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -11,10 +10,6 @@ import javax.swing.UIManager;
|
||||||
|
|
||||||
import ca.weblite.objc.Client;
|
import ca.weblite.objc.Client;
|
||||||
|
|
||||||
import com.apple.eawt.Application;
|
|
||||||
import com.apple.eawt.ApplicationAdapter;
|
|
||||||
import com.apple.eawt.ApplicationEvent;
|
|
||||||
|
|
||||||
public class MacAppUtilities {
|
public class MacAppUtilities {
|
||||||
|
|
||||||
private static Client _objc;
|
private static Client _objc;
|
||||||
|
@ -40,7 +35,9 @@ public class MacAppUtilities {
|
||||||
|
|
||||||
public static void setWindowCanFullScreen(Window window) {
|
public static void setWindowCanFullScreen(Window window) {
|
||||||
try {
|
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) {
|
} catch (Throwable t) {
|
||||||
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
|
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +45,10 @@ public class MacAppUtilities {
|
||||||
|
|
||||||
public static void requestForeground() {
|
public static void requestForeground() {
|
||||||
try {
|
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) {
|
} catch (Throwable t) {
|
||||||
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "requestForeground not supported: " + 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) {
|
public static void revealInFinder(File file) {
|
||||||
try {
|
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) {
|
} catch (Throwable t) {
|
||||||
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "revealInFinder not supported: " + 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"));
|
UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant"));
|
||||||
|
|
||||||
// make sure Application Quit Events get forwarded to normal Window Listeners
|
// make sure Application Quit Events get forwarded to normal Window Listeners
|
||||||
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
|
try {
|
||||||
|
Class<?> application = Class.forName("com.apple.eawt.Application");
|
||||||
@Override
|
Object instance = application.getMethod("getApplication").invoke(null);
|
||||||
public void handleQuit(ApplicationEvent evt) {
|
Class<?> quitStrategy = Class.forName("com.apple.eawt.QuitStrategy");
|
||||||
for (Window window : Window.getOwnerlessWindows()) {
|
Method setQuitStrategy = application.getMethod("setQuitStrategy", quitStrategy);
|
||||||
// close all windows
|
Object closeAllWindows = quitStrategy.getField("CLOSE_ALL_WINDOWS").get(null);
|
||||||
window.setVisible(false);
|
setQuitStrategy.invoke(instance, closeAllWindows);
|
||||||
|
} catch (Throwable t) {
|
||||||
// call window listeners
|
Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setQuitStrategy not supported: " + t);
|
||||||
EventQueue.invokeLater(() -> {
|
}
|
||||||
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLockedFolder(File folder) {
|
public static boolean isLockedFolder(File folder) {
|
||||||
|
|
Loading…
Reference in New Issue