Skip to content

Commit bdf235a

Browse files
committed
feat(GUI): Server Safe mod
1 parent dfa65d7 commit bdf235a

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/main/java/i18nupdatemod/core/LoadDetailUI.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ public class LoadDetailUI {
1818
private final boolean useGUI;
1919

2020
private LoadDetailUI() {
21-
useGUI = Boolean.parseBoolean(System.getProperty("java.awt.headless"));
21+
useGUI = !Boolean.parseBoolean(System.getProperty("java.awt.headless", "false"));
22+
23+
if (!useGUI) {
24+
frame = null;
25+
statusBar = null;
26+
logArea = null;
27+
return;
28+
}
2229

2330
frame = new JFrame();
2431
frame.setTitle("I18nUpdateMod-资源包下载进度");
@@ -94,21 +101,36 @@ public static LoadDetailUI getInstance() {
94101
}
95102

96103
public static void show() {
97-
getInstance().frame.setVisible(true);
104+
LoadDetailUI gui = getInstance();
105+
if (!gui.useGUI || gui.frame == null) {
106+
return;
107+
}
108+
gui.frame.setVisible(true);
98109
}
99110

100111
public static void hide() {
101-
getInstance().frame.setVisible(false);
112+
LoadDetailUI gui = getInstance();
113+
if (!gui.useGUI || gui.frame == null) {
114+
return;
115+
}
116+
gui.frame.setVisible(false);
102117
}
103118

104119
private void shutdown(){
120+
if (!useGUI) {
121+
I18nUpdateMod.shouldShutdown = true;
122+
return;
123+
}
105124
hide();
106125
I18nUpdateMod.shouldShutdown = true;
107126
}
108127

109128
public static void setStage(LoadStage stage) {
129+
LoadDetailUI gui = getInstance();
130+
if (!gui.useGUI || gui.statusBar == null || gui.logArea == null) {
131+
return;
132+
}
110133
SwingUtilities.invokeLater(() -> {
111-
LoadDetailUI gui = getInstance();
112134
gui.statusBar.setString(LoadStage.getDescription(stage));
113135
gui.statusBar.setValue(stage.getValue());
114136
gui.logArea.append("当前阶段: " + LoadStage.getDescription(stage) + "\n");
@@ -117,8 +139,11 @@ public static void setStage(LoadStage stage) {
117139
}
118140

119141
public static void appendLog(String log) {
142+
LoadDetailUI gui = getInstance();
143+
if (!gui.useGUI || gui.logArea == null) {
144+
return;
145+
}
120146
SwingUtilities.invokeLater(() -> {
121-
LoadDetailUI gui = getInstance();
122147
gui.logArea.append(log + "\n");
123148
gui.logArea.setCaretPosition(gui.logArea.getDocument().getLength());
124149
});

0 commit comments

Comments
 (0)