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

View File

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

View File

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