From c55eb396828d7c36ca25fcd00a0dd154c7bd60f2 Mon Sep 17 00:00:00 2001 From: Daniele Conti Date: Sat, 29 Jun 2024 10:26:32 +0200 Subject: [PATCH 1/5] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ecc085aa..8e2306b4 100644 --- a/README.md +++ b/README.md @@ -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: From 4ad9de355be7939d677e427c55e5b95a219f10e7 Mon Sep 17 00:00:00 2001 From: Daniele Conti Date: Sat, 29 Jun 2024 10:44:10 +0200 Subject: [PATCH 2/5] Remove usage of internal API --- .../kotcrab/vis/ui/widget/file/FileUtils.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java index 19b69d32..a76f12d9 100644 --- a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java +++ b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java @@ -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; @@ -164,19 +163,15 @@ 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); - desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow); - } catch (Exception e) { - Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e); - } - } - } + 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); + desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow); + } catch (Exception e) { + Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e); + } + } } From ce3c237f3987ec280666688a4d1079a05e497ed1 Mon Sep 17 00:00:00 2001 From: Daniele Conti Date: Sat, 29 Jun 2024 13:54:46 +0200 Subject: [PATCH 3/5] Use browseFileDirectory if available --- .../java/com/kotcrab/vis/ui/widget/file/FileUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java index a76f12d9..a4ca307b 100644 --- a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java +++ b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java @@ -169,7 +169,12 @@ public static void showDirInExplorer (FileHandle dir) throws IOException { // Basically 'Desktop.getDesktop().open(dirToShow);' Class desktopClass = Class.forName("java.awt.Desktop"); Object desktop = desktopClass.getMethod("getDesktop").invoke(null); - desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow); + try { + // browseFileDirectory was introduced in JDK 9 + desktopClass.getMethod("browseFileDirectory", File.class).invoke(desktop, dirToShow); + } catch (NoSuchMethodException ignored) { + desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow); + } } catch (Exception e) { Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e); } From 48a28774fa7247acfedfe352ce830f8856a309ac Mon Sep 17 00:00:00 2001 From: Daniele Conti Date: Sat, 29 Jun 2024 14:07:43 +0200 Subject: [PATCH 4/5] Reindent file with tabs --- .../kotcrab/vis/ui/widget/file/FileUtils.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java index a4ca307b..573ec080 100644 --- a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java +++ b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java @@ -163,20 +163,20 @@ public static void showDirInExplorer (FileHandle dir) throws IOException { dirToShow = dir.parent().file(); } - 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); try { // browseFileDirectory was introduced in JDK 9 desktopClass.getMethod("browseFileDirectory", File.class).invoke(desktop, dirToShow); } catch (NoSuchMethodException ignored) { 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); + } + } } From f0e81c02d184ddf10c67c89b66e4637672ca92f9 Mon Sep 17 00:00:00 2001 From: Daniele Conti Date: Sat, 29 Jun 2024 14:24:59 +0200 Subject: [PATCH 5/5] Catch UnsupportedOperationException thrown by browseFileDirectory --- .../java/com/kotcrab/vis/ui/widget/file/FileUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java index 573ec080..a601fd7c 100644 --- a/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java +++ b/ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileUtils.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; import java.util.Comparator; @@ -172,7 +173,13 @@ public static void showDirInExplorer (FileHandle dir) throws IOException { try { // browseFileDirectory was introduced in JDK 9 desktopClass.getMethod("browseFileDirectory", File.class).invoke(desktop, dirToShow); - } catch (NoSuchMethodException ignored) { + } 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) {