Fix Mac sandbox issues
This commit is contained in:
parent
4debb73ffc
commit
87125a98a9
|
@ -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();
|
||||||
|
final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
|
||||||
|
|
||||||
@Override
|
SwingUtilities.invokeLater(() -> {
|
||||||
public Boolean call() throws Exception {
|
try {
|
||||||
final JDialog dialog = new JDialog(owner);
|
JDialog dialog = new JDialog(owner);
|
||||||
final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
|
|
||||||
DropToUnlock d = new DropToUnlock(model) {
|
DropToUnlock d = new DropToUnlock(model) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -194,29 +191,20 @@ 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();
|
|
||||||
} 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 (dialogCancelled.get()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
storeSecurityScopedBookmarks(model);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DropToUnlock(Collection<File> model) {
|
public DropToUnlock(Collection<File> model) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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()));
|
||||||
|
|
Loading…
Reference in New Issue