|
16 | 16 |
|
17 | 17 | package com.kotcrab.vis.ui.widget.file;
|
18 | 18 |
|
19 |
| -import com.apple.eio.FileManager; |
20 | 19 | import com.badlogic.gdx.Gdx;
|
21 | 20 | import com.badlogic.gdx.files.FileHandle;
|
22 | 21 | import com.badlogic.gdx.utils.Array;
|
|
25 | 24 |
|
26 | 25 | import java.io.File;
|
27 | 26 | import java.io.IOException;
|
| 27 | +import java.lang.reflect.InvocationTargetException; |
28 | 28 | import java.text.DecimalFormat;
|
29 | 29 | import java.util.Comparator;
|
30 | 30 |
|
@@ -164,19 +164,26 @@ public static void showDirInExplorer (FileHandle dir) throws IOException {
|
164 | 164 | dirToShow = dir.parent().file();
|
165 | 165 | }
|
166 | 166 |
|
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); |
170 | 173 | 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 | + } |
176 | 183 | desktopClass.getMethod("open", File.class).invoke(desktop, dirToShow);
|
177 |
| - } catch (Exception e) { |
178 |
| - Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e); |
179 | 184 | }
|
| 185 | + } catch (Exception e) { |
| 186 | + Gdx.app.log("VisUI", "Can't open file " + dirToShow.getPath(), e); |
180 | 187 | }
|
181 | 188 | }
|
182 | 189 | }
|
0 commit comments