Skip to content

Commit 08d70d3

Browse files
authored
Remove reference to internal class (#393)
1 parent 4a1e267 commit 08d70d3

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ VisUI is licensed under Apache2 license meaning that you can use it for free in
1515

1616
[![Maven Central](https://img.shields.io/maven-central/v/com.kotcrab.vis/vis-ui.svg)](https://search.maven.org/artifact/com.kotcrab.vis/vis-ui)
1717

18-
Please refer to [libGDX documentation](https://libgdx.com/wiki/articles/dependency-management-with-gradle) if you don't know how to mange dependencies with Gradle. Alternatively JAR can be downloaded from [Maven repository](http://search.maven.org/#search|gav|1|g%3A%22com.kotcrab.vis%22%20AND%20a%3A%22vis-ui%22). If you are creating new project, you can use gdx-setup to automatically add VisUI for you. (press 'Show Third Party Extension' button)
18+
Please refer to [libGDX documentation](https://libgdx.com/wiki/articles/dependency-management-with-gradle) if you don't know how to manage dependencies with Gradle. Alternatively JAR can be downloaded from [Maven repository](http://search.maven.org/#search|gav|1|g%3A%22com.kotcrab.vis%22%20AND%20a%3A%22vis-ui%22). If you are creating new project, you can use gdx-setup to automatically add VisUI for you. (press 'Show Third Party Extension' button)
1919

2020
#### Manual Gradle setup:
2121

ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.kotcrab.vis.ui.widget.file;
1818

19-
import com.apple.eio.FileManager;
2019
import com.badlogic.gdx.Gdx;
2120
import com.badlogic.gdx.files.FileHandle;
2221
import com.badlogic.gdx.utils.Array;
@@ -25,6 +24,7 @@
2524

2625
import java.io.File;
2726
import java.io.IOException;
27+
import java.lang.reflect.InvocationTargetException;
2828
import java.text.DecimalFormat;
2929
import java.util.Comparator;
3030

@@ -164,19 +164,26 @@ public static void showDirInExplorer (FileHandle dir) throws IOException {
164164
dirToShow = dir.parent().file();
165165
}
166166

167-
if (OsUtils.isMac()) {
168-
FileManager.revealInFinder(dirToShow);
169-
} else {
167+
try {
168+
// Using reflection to avoid importing AWT desktop which would trigger Android Lint errors
169+
// This is desktop only, rarely called, performance drop is negligible
170+
// Basically 'Desktop.getDesktop().open(dirToShow);'
171+
Class desktopClass = Class.forName("java.awt.Desktop");
172+
Object desktop = desktopClass.getMethod("getDesktop").invoke(null);
170173
try {
171-
// Using reflection to avoid importing AWT desktop which would trigger Android Lint errors
172-
// This is desktop only, rarely called, performance drop is negligible
173-
// Basically 'Desktop.getDesktop().open(dirToShow);'
174-
Class desktopClass = Class.forName("java.awt.Desktop");
175-
Object desktop = desktopClass.getMethod("getDesktop").invoke(null);
174+
// browseFileDirectory was introduced in JDK 9
175+
desktopClass.getMethod("browseFileDirectory", File.class).invoke(desktop, dirToShow);
176+
} catch (NoSuchMethodException | InvocationTargetException e) {
177+
// browseFileDirectory throws UnsupportedOperationException on some platforms, which is then
178+
// wrapped in InvocationTargetException because it's accessed via reflection.
179+
// throw again all other exceptions we didn't expect
180+
if (e instanceof InvocationTargetException && !(e.getCause() instanceof UnsupportedOperationException)) {
181+
throw e;
182+
}
176183
desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow);
177-
} catch (Exception e) {
178-
Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e);
179184
}
185+
} catch (Exception e) {
186+
Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e);
180187
}
181188
}
182189
}

0 commit comments

Comments
 (0)