the rot rottens

Fixes Desktop.browse not working on Linux
This commit is contained in:
Voxelstice 2026-06-03 20:19:15 +03:00
parent 1043470ca6
commit 41140ecf7c

View File

@ -3,10 +3,13 @@ package com.hbm.inventory.gui;
import java.awt.Desktop;
import java.io.File;
import java.io.PrintWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.net.URI;
import java.util.Arrays;
import java.util.Objects;
import org.lwjgl.opengl.GL11;
@ -37,6 +40,17 @@ public class GUIScreenRadioAUTOCAL extends GuiScreen {
this.autocal = autocal;
}
private void browse(URI uri) throws IOException {
// workaround for Java not supporting all platforms, mostly for Linux
if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(uri);
} else {
if (Runtime.getRuntime().exec(new String[] { "which", "xdg-open" }).getInputStream().read() != -1) {
Runtime.getRuntime().exec(new String[] { "xdg-open", uri.toString() });
}
}
}
@Override
public void initGui() {
super.initGui();
@ -71,7 +85,7 @@ public class GUIScreenRadioAUTOCAL extends GuiScreen {
if(!uploadFolder.exists()) uploadFolder.mkdir();
if(!script.exists()) script.createNewFile();
script.setExecutable(false);
Desktop.getDesktop().browse(script.toURI());
browse(script.toURI());
} catch(Throwable ex) { MainRegistry.logger.error("Couldn't open link", ex); }
}
@ -89,7 +103,7 @@ public class GUIScreenRadioAUTOCAL extends GuiScreen {
printer.close();
} catch(Throwable e) { }
}
Desktop.getDesktop().browse(doc.toURI());
browse(doc.toURI());
} catch(Throwable ex) { MainRegistry.logger.error("Couldn't open link", ex); }
}