Skip to content

Commit

Permalink
Remove reference to internal class (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
fourlastor authored Jun 30, 2024
1 parent 4a1e267 commit 08d70d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VisUI is licensed under Apache2 license meaning that you can use it for free in

[![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)

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)
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)

#### Manual Gradle setup:

Expand Down
29 changes: 18 additions & 11 deletions ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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

import com.apple.eio.FileManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
Expand All @@ -25,6 +24,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.util.Comparator;

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

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

0 comments on commit 08d70d3

Please sign in to comment.