1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Fix Mac sandbox issues

This commit is contained in:
Reinhard Pointner 2016-02-03 18:52:42 +00:00
parent 4debb73ffc
commit 87125a98a9
3 changed files with 19 additions and 32 deletions

View File

@ -18,6 +18,8 @@ import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.SecondaryLoop;
import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -25,7 +27,6 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.util.Collection; import java.util.Collection;
@ -33,10 +34,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -136,13 +133,13 @@ public class DropToUnlock extends JList<File> {
return true; return true;
} }
// show selection dialog on EDT // show dialog on EDT and wait for user input
RunnableFuture<Boolean> showPermissionDialog = new FutureTask<Boolean>(new Callable<Boolean>() { final SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
@Override
public Boolean call() throws Exception {
final JDialog dialog = new JDialog(owner);
final AtomicBoolean dialogCancelled = new AtomicBoolean(true); final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
SwingUtilities.invokeLater(() -> {
try {
JDialog dialog = new JDialog(owner);
DropToUnlock d = new DropToUnlock(model) { DropToUnlock d = new DropToUnlock(model) {
@Override @Override
@ -194,30 +191,21 @@ public class DropToUnlock extends JList<File> {
// show and wait for user input // show and wait for user input
dialog.setVisible(true); dialog.setVisible(true);
} finally {
// abort if user has closed the window before all folders have been unlocked secondaryLoop.exit();
return !dialogCancelled.get();
} }
}); });
// show dialog on EDT and wait for user input if (!secondaryLoop.enter()) {
try { throw new IllegalStateException("SecondaryLoop.enter()");
if (SwingUtilities.isEventDispatchThread()) { }
showPermissionDialog.run(); if (dialogCancelled.get()) {
} else { return false;
SwingUtilities.invokeAndWait(showPermissionDialog);
} }
// store security-scoped bookmark if dialog was accepted
if (showPermissionDialog.get()) {
storeSecurityScopedBookmarks(model); storeSecurityScopedBookmarks(model);
return true; return true;
} }
return false;
} catch (InterruptedException | InvocationTargetException | ExecutionException e) {
throw new RuntimeException("Failed to request permissions: " + e.getMessage(), e);
}
}
public DropToUnlock(Collection<File> model) { public DropToUnlock(Collection<File> model) {
super(model.toArray(new File[0])); super(model.toArray(new File[0]));

View File

@ -86,7 +86,7 @@ public class MacAppUtilities {
// Enter the loop to block the current event handler, but leave UI responsive // Enter the loop to block the current event handler, but leave UI responsive
if (!secondaryLoop.enter()) { if (!secondaryLoop.enter()) {
throw new RuntimeException("SecondaryLoop.enter()"); throw new IllegalStateException("SecondaryLoop.enter()");
} }
return result; return result;

View File

@ -185,7 +185,6 @@ public class SubtitleUploadDialog extends JDialog {
protected void done() { protected void done() {
try { try {
List<SubtitleSearchResult> options = get(); List<SubtitleSearchResult> options = get();
System.out.println(options);
if (options.size() > 0) { if (options.size() > 0) {
SelectDialog<Movie> dialog = new SelectDialog<Movie>(SubtitleUploadDialog.this, options); SelectDialog<Movie> dialog = new SelectDialog<Movie>(SubtitleUploadDialog.this, options);
dialog.setLocation(getOffsetLocation(dialog.getOwner())); dialog.setLocation(getOffsetLocation(dialog.getOwner()));