Skip to content

Commit

Permalink
Revert "Fix + improve launch method (MeteorDevelopment#3983)" - Don't…
Browse files Browse the repository at this point in the history
… use AWT

This reverts commit d752b5b.
  • Loading branch information
MineGame159 committed Aug 21, 2023
1 parent d752b5b commit c178e97
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions launch/src/main/java/meteordevelopment/meteorclient/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
package meteordevelopment.meteorclient;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Locale;

Expand All @@ -22,40 +20,28 @@ public static void main(String[] args) throws UnsupportedLookAndFeelException, C
null,
"To install Meteor Client you need to put it in your mods folder and run Fabric for latest Minecraft version.",
"Meteor Client",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.YES_NO_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
new String[] { "Open Wiki", "Open Mods Folder", "Join our Discord" },
new String[] { "Open Wiki", "Open Mods Folder" },
null
);

switch (option) {
case 0: {
try {
Desktop.getDesktop().browse(URI.create("https://meteorclient.com/faq/installation"));
} catch (IOException ignored) {}
break;
}
case 0: getOS().open("https://meteorclient.com/installation"); break;
case 1: {
String path;

switch (getOS()) {
case WINDOWS: path = System.getenv("AppData") + "/.minecraft/mods"; break;
case OSX: path = System.getProperty("user.home") + "/Library/Application Support/minecraft/mods"; break;
default: path = System.getProperty("user.home") + "/.minecraft/mods"; break;
default: path = System.getProperty("user.home") + "/.minecraft"; break;
}

File mods = new File(path);
if (!mods.exists()) mods.mkdirs();
try {
Desktop.getDesktop().open(mods);
} catch (IOException ignored) {}
break;
}
case 2: {
try {
Desktop.getDesktop().browse(URI.create("https://discord.com/invite/bBGQZvd"));
} catch (IOException ignored) {}

getOS().open(mods);
break;
}
}
Expand All @@ -73,8 +59,52 @@ private static OperatingSystem getOS() {

private enum OperatingSystem {
LINUX,
WINDOWS,
OSX,
WINDOWS {
@Override
protected String[] getURLOpenCommand(URL url) {
return new String[] { "rundll32", "url.dll,FileProtocolHandler", url.toString() };
}
},
OSX {
@Override
protected String[] getURLOpenCommand(URL url) {
return new String[] { "open", url.toString() };
}
},
UNKNOWN;

public void open(URL url) {
try {
Runtime.getRuntime().exec(getURLOpenCommand(url));
} catch (IOException e) {
e.printStackTrace();
}
}

public void open(String url) {
try {
open(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

public void open(File file) {
try {
open(file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

protected String[] getURLOpenCommand(URL url) {
String string = url.toString();

if ("file".equals(url.getProtocol())) {
string = string.replace("file:", "file://");
}

return new String[] { "xdg-open", string };
}
}
}

0 comments on commit c178e97

Please sign in to comment.