mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 21:36:21 -04:00
Fix NullPointerException in SwingUtils.invokeAndWait
This commit is contained in:
parent
6968809499
commit
1f7eb04215
@ -30,6 +30,7 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.system.OS;
|
||||
import org.jackhuang.hellominecraft.views.LogWindow;
|
||||
|
||||
/**
|
||||
@ -96,7 +97,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
text += "\n Content: \n ";
|
||||
text += s + "\n\n";
|
||||
text += "-- System Details --\n";
|
||||
text += " Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version") + "\n";
|
||||
text += " Operating System: " + OS.getSystemVersion() + "\n";
|
||||
text += " Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n";
|
||||
text += " Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor") + "\n";
|
||||
if (enableLogger)
|
||||
|
@ -56,10 +56,9 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
@ -152,6 +151,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
|
||||
SwingUtils.clearDefaultTable(lstInstallers);
|
||||
if (versions != null)
|
||||
for (InstallerVersionList.InstallerVersion v : versions)
|
||||
if (v != null)
|
||||
model.addRow(new Object[]{v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion});
|
||||
}
|
||||
});
|
||||
|
@ -87,6 +87,13 @@ public final class StrUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsOne(String base, String... match) {
|
||||
for (String s : match)
|
||||
if (base.contains(s))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsOne(List<String> base, List<String> match) {
|
||||
for (String a : base)
|
||||
for (String b : match)
|
||||
|
@ -26,6 +26,7 @@ import java.io.InputStreamReader;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.StringTokenizer;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
|
||||
/**
|
||||
* @author huangyuhui
|
||||
@ -108,4 +109,18 @@ public enum OS {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getLinuxReleaseVersion() throws IOException {
|
||||
return FileUtils.readFileToString(new File("/etc/issue"));
|
||||
}
|
||||
|
||||
public static String getSystemVersion() {
|
||||
if (os() == LINUX)
|
||||
try {
|
||||
return getLinuxReleaseVersion();
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to catch /etc/issue");
|
||||
}
|
||||
return System.getProperty("os.name") + " (" + System.getProperty("os.arch") + "), " + System.getProperty("os.version");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ import java.awt.FontMetrics;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
@ -222,12 +225,19 @@ public class SwingUtils {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static final ThreadLocal<Object> THREAD_LOCAL = new ThreadLocal<>();
|
||||
private static final Map<Integer, Object> INVOKE_AND_WAIT_MAP = Collections.synchronizedMap(new HashMap<>());
|
||||
private static int INVOKE_AND_WAIT_ID = 0;
|
||||
private static final Object INVOKE_AND_WAIT_LOCK = new Object();
|
||||
|
||||
public static <T> T invokeAndWait(NonFunction<T> x) {
|
||||
Runnable r = () -> THREAD_LOCAL.set(x.apply());
|
||||
int id;
|
||||
synchronized (INVOKE_AND_WAIT_LOCK) {
|
||||
id = ++INVOKE_AND_WAIT_ID;
|
||||
}
|
||||
int fuck = id;
|
||||
Runnable r = () -> INVOKE_AND_WAIT_MAP.put(fuck, x.apply());
|
||||
invokeAndWait(r);
|
||||
return (T) THREAD_LOCAL.get();
|
||||
return (T) INVOKE_AND_WAIT_MAP.remove(id);
|
||||
}
|
||||
|
||||
public static void invokeAndWait(Runnable r) {
|
||||
|
@ -69,7 +69,7 @@ public class ProgressPainter extends SynthPainter {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
g2.setPaint(new LinearGradientPaint(x, y + 2, x, y + h - 2, BAR_FG_PTS, BAR_FG));
|
||||
if (x + 2 < w - 5 && y + 2 < h - 5)
|
||||
g2.drawRect(x + 2, y + 2, w - 5, h - 5);
|
||||
g2.fillRect(x + 2, y + 2, w - 5, h - 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user