Skip to content

Commit 43a5bc0

Browse files
committed
Define ATS on macOS to work properly on Java11+
1 parent 5c95232 commit 43a5bc0

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

filescanner-cocoa-macosx-x86_64/src/main/java/de/carne/filescanner/platform/FileScannerPlatform.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,54 @@
1616
*/
1717
package de.carne.filescanner.platform;
1818

19+
import org.eclipse.swt.internal.cocoa.NSBundle;
20+
import org.eclipse.swt.internal.cocoa.NSDictionary;
21+
import org.eclipse.swt.internal.cocoa.NSMutableDictionary;
22+
import org.eclipse.swt.internal.cocoa.NSNumber;
23+
import org.eclipse.swt.internal.cocoa.NSString;
24+
import org.eclipse.swt.internal.cocoa.OS;
25+
26+
import de.carne.boot.logging.Log;
27+
1928
/**
2029
* Utility class providing platform dependent functions.
2130
*/
2231
public final class FileScannerPlatform {
2332

33+
private static final Log LOG = new Log();
34+
2435
FileScannerPlatform() {
2536
// Prevent instantiation
2637
}
2738

39+
/**
40+
* Performs platform specific setup tasks.
41+
*/
42+
public static void setupPlatform() {
43+
NSBundle mainBundle = NSBundle.mainBundle();
44+
boolean atsDefined = false;
45+
46+
if (mainBundle != null) {
47+
NSDictionary dictionary = mainBundle.infoDictionary();
48+
49+
if (dictionary != null
50+
&& dictionary.isKindOfClass(OS.objc_lookUpClass(NSMutableDictionary.class.getSimpleName()))) {
51+
NSMutableDictionary mutableDictionary = new NSMutableDictionary(dictionary);
52+
NSMutableDictionary ats = NSMutableDictionary.dictionaryWithCapacity(3);
53+
NSNumber trueValue = NSNumber.numberWithBool(true);
54+
55+
ats.setValue(trueValue, NSString.stringWith("NSAllowsArbitraryLoads"));
56+
ats.setValue(trueValue, NSString.stringWith("NSAllowsArbitraryLoadsForMedia"));
57+
ats.setValue(trueValue, NSString.stringWith("NSAllowsArbitraryLoadsInWebContent"));
58+
mutableDictionary.setObject(ats, NSString.stringWith("NSAppTransportSecurity"));
59+
atsDefined = true;
60+
}
61+
}
62+
if (!atsDefined) {
63+
LOG.warning("Failed to setup App Transport Security policy");
64+
}
65+
}
66+
2867
/**
2968
* Gets the CSS font size based upon the platform specific font height.
3069
*

filescanner-gtk-linux-x86_64/shared-src/main/java/de/carne/filescanner/FileScannerMain.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import de.carne.boot.Exceptions;
3232
import de.carne.boot.logging.Log;
3333
import de.carne.boot.logging.Logs;
34+
import de.carne.filescanner.platform.FileScannerPlatform;
3435
import de.carne.filescanner.swt.main.MainUI;
3536
import de.carne.swt.UserApplication;
3637
import de.carne.swt.graphics.ResourceException;
@@ -67,6 +68,8 @@ public int run(@Nullable String[] args) {
6768
int status;
6869

6970
try {
71+
FileScannerPlatform.setupPlatform();
72+
7073
CmdLineProcessor logConfigCmdLine = buildLogConfigCmdLine(args);
7174

7275
logConfigCmdLine.process();

filescanner-gtk-linux-x86_64/src/main/java/de/carne/filescanner/platform/FileScannerPlatform.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public final class FileScannerPlatform {
2525
// Prevent instantiation
2626
}
2727

28+
/**
29+
* Performs platform specific setup tasks.
30+
*/
31+
public static void setupPlatform() {
32+
// Nothing to do here
33+
}
34+
2835
/**
2936
* Gets the CSS font size based upon the platform specific font height.
3037
*

filescanner-win32-win32-x86_64/src/main/java/de/carne/filescanner/platform/FileScannerPlatform.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public final class FileScannerPlatform {
2525
// Prevent instantiation
2626
}
2727

28+
/**
29+
* Performs platform specific setup tasks.
30+
*/
31+
public static void setupPlatform() {
32+
// Nothing to do here
33+
}
34+
2835
/**
2936
* Gets the CSS font size based upon the platform specific font height.
3037
*

0 commit comments

Comments
 (0)