Merge pull request #2933 from Voxelstice/autocal-browse-fix

AUTOCAL "Desktop.browse" Linux function fix
This commit is contained in:
HbmMods 2026-06-16 16:41:43 +02:00 committed by GitHub
commit bb688e2f4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,11 +3,14 @@ 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 org.lwjgl.Sys;
import org.lwjgl.opengl.GL11;
import com.hbm.lib.RefStrings;
@ -37,6 +40,21 @@ 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 (Sys.getVersion().charAt(0) == '3') {
// probably a LWJGL3ify user, open the folder instead since that somehow seems to work
File uploadFolder = new File(MainRegistry.configDir.getParentFile(), "hbmComputerUpload");
if (uploadFolder.exists()) Sys.openURL(uploadFolder.toString());
} else {
Sys.openURL(uri.toString());
}
}
}
@Override
public void initGui() {
super.initGui();
@ -71,7 +89,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 +107,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); }
}