Skip to content

Commit 01f9747

Browse files
authored
Merge branch 'main' into feature/issue-4352-background-auto-download-update
2 parents 4c2c01d + afbf567 commit 01f9747

23 files changed

Lines changed: 987 additions & 218 deletions

HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
import org.jackhuang.hmcl.theme.Themes;
4343
import org.jackhuang.hmcl.upgrade.UpdateChecker;
4444
import org.jackhuang.hmcl.upgrade.UpdateHandler;
45-
import org.jackhuang.hmcl.util.CrashReporter;
46-
import org.jackhuang.hmcl.util.FileSaver;
47-
import org.jackhuang.hmcl.util.Lang;
48-
import org.jackhuang.hmcl.util.StringUtils;
45+
import org.jackhuang.hmcl.util.*;
4946
import org.jackhuang.hmcl.util.io.JarUtils;
5047
import org.jackhuang.hmcl.util.platform.*;
5148

@@ -347,6 +344,8 @@ public static void main(String[] args) {
347344
LOG.info("XDG Current Desktop: " + System.getenv("XDG_CURRENT_DESKTOP"));
348345
}
349346

347+
LOG.info("Zlib Compatible: " + ZlibUtils.IS_ZLIB_COMPATIBLE);
348+
350349
Lang.thread(SystemInfo::initialize, "Detection System Information", true);
351350

352351
launch(Launcher.class, args);

HMCL/src/main/java/org/jackhuang/hmcl/terracotta/TerracottaBundle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ protected Context getContext(HttpResponse<?> response, boolean checkETag, String
7171
return new Context() {
7272
@Override
7373
public void withResult(boolean success) {
74+
super.withResult(success);
7475
delegate.withResult(success);
7576
}
7677

78+
@Override
79+
public void reset() throws IOException {
80+
delegate.reset();
81+
}
82+
7783
@Override
7884
public void write(byte[] buffer, int offset, int len) throws IOException {
7985
context.checkCancellation();

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/OfflineAccountSkinPane.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.jfoenix.controls.JFXComboBox;
2222
import com.jfoenix.controls.JFXDialogLayout;
2323
import com.jfoenix.controls.JFXTextField;
24+
import javafx.animation.PauseTransition;
2425
import javafx.application.Platform;
2526
import javafx.beans.InvalidationListener;
2627
import javafx.geometry.Insets;
@@ -29,6 +30,7 @@
2930
import javafx.scene.input.DragEvent;
3031
import javafx.scene.input.TransferMode;
3132
import javafx.scene.layout.*;
33+
import javafx.util.Duration;
3234
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
3335
import org.jackhuang.hmcl.auth.offline.Skin;
3436
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
@@ -135,7 +137,9 @@ public OfflineAccountSkinPane(OfflineAccount account) {
135137
capeSelector.setValue(account.getSkin().getLocalCapePath());
136138
}
137139

138-
skinBinding = FXUtils.observeWeak(() -> {
140+
PauseTransition pauseTransition = new PauseTransition(Duration.seconds(1));
141+
142+
Runnable loadSkin = () -> {
139143
getSkin().load(account.getUsername())
140144
.whenComplete(Schedulers.javafx(), (result, exception) -> {
141145
if (exception != null) {
@@ -157,6 +161,23 @@ public OfflineAccountSkinPane(OfflineAccount account) {
157161
result.getCape() != null ? result.getCape().getImage() : null);
158162
}
159163
}).start();
164+
};
165+
166+
pauseTransition.setOnFinished(e -> loadSkin.run());
167+
168+
skinBinding = FXUtils.observeWeak(() -> {
169+
Skin.Type selectedType = skinItem.getSelectedData();
170+
171+
if (selectedType == Skin.Type.CUSTOM_SKIN_LOADER_API) {
172+
if (!cslApiField.validate()) {
173+
pauseTransition.stop();
174+
return;
175+
}
176+
pauseTransition.playFromStart();
177+
} else {
178+
pauseTransition.stop();
179+
loadSkin.run();
180+
}
160181
}, skinItem.selectedDataProperty(), cslApiField.textProperty(), modelCombobox.valueProperty(), skinSelector.valueProperty(), capeSelector.valueProperty());
161182

162183
FXUtils.onChangeAndOperate(skinItem.selectedDataProperty(), selectedData -> {

HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/LineSelectButton.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import com.jfoenix.controls.JFXPopup;
2121
import javafx.beans.InvalidationListener;
2222
import javafx.beans.binding.Bindings;
23-
import javafx.beans.property.ListProperty;
24-
import javafx.beans.property.ObjectProperty;
25-
import javafx.beans.property.SimpleListProperty;
26-
import javafx.beans.property.SimpleObjectProperty;
23+
import javafx.beans.property.*;
2724
import javafx.collections.FXCollections;
2825
import javafx.collections.ObservableList;
2926
import javafx.css.PseudoClass;
@@ -36,6 +33,8 @@
3633
import org.jackhuang.hmcl.ui.FXUtils;
3734
import org.jackhuang.hmcl.ui.SVG;
3835
import org.jackhuang.hmcl.util.javafx.MappedObservableList;
36+
import org.jetbrains.annotations.NotNull;
37+
import org.jetbrains.annotations.UnknownNullability;
3938

4039
import java.util.Collection;
4140
import java.util.Objects;
@@ -44,7 +43,7 @@
4443
import static org.jackhuang.hmcl.ui.FXUtils.determineOptimalPopupPosition;
4544

4645
/// @author Glavo
47-
public class LineSelectButton<T> extends LineButton {
46+
public class LineSelectButton<T extends @UnknownNullability Object> extends LineButton {
4847

4948
private static final String DEFAULT_STYLE_CLASS = "line-select-button";
5049
private static final PseudoClass SELECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("selected");
@@ -57,13 +56,9 @@ public LineSelectButton() {
5756
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
5857

5958
InvalidationListener updateTrailingText = observable -> {
59+
Function<T, String> converter = getConverter();
6060
T value = getValue();
61-
if (value != null) {
62-
Function<T, String> converter = getConverter();
63-
setTrailingText(converter != null ? converter.apply(value) : value.toString());
64-
} else {
65-
setTrailingText(null);
66-
}
61+
setTrailingText(converter != null ? converter.apply(value) : Objects.toString(value, ""));
6762
};
6863
converterProperty().addListener(updateTrailingText);
6964
valueProperty().addListener(updateTrailingText);
@@ -96,9 +91,6 @@ public void fire() {
9691
var itemTitleLabel = new Label();
9792
itemTitleLabel.getStyleClass().add("title-label");
9893
itemTitleLabel.textProperty().bind(Bindings.createStringBinding(() -> {
99-
if (item == null)
100-
return "";
101-
10294
Function<T, String> converter = getConverter();
10395
return converter != null ? converter.apply(item) : Objects.toString(item, "");
10496
}, converterProperty()));
@@ -173,10 +165,14 @@ public Function<T, String> getConverter() {
173165
return converterProperty().get();
174166
}
175167

176-
public void setConverter(Function<T, String> value) {
168+
public void setConverter(Function<T, String> value) { // TODO: rename
177169
converterProperty().set(value);
178170
}
179171

172+
public void setNullSafeConverter(Function<@NotNull T, String> value) {
173+
converterProperty().set(it -> it != null ? value.apply(it) : "");
174+
}
175+
180176
private ObjectProperty<Function<T, String>> descriptionConverter;
181177

182178
public ObjectProperty<Function<T, String>> descriptionConverterProperty() {

HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public ModpackInfoPageSkin(ModpackInfoPage skinnable) {
316316
if (skinnable.options.isRequireAuthlibInjectorServer()) {
317317
var serversSelectButton = new LineSelectButton<AuthlibInjectorServer>();
318318
serversSelectButton.setTitle(i18n("account.injector.server"));
319-
serversSelectButton.setConverter(AuthlibInjectorServer::getName);
319+
serversSelectButton.setNullSafeConverter(AuthlibInjectorServer::getName);
320320
serversSelectButton.setDescriptionConverter(AuthlibInjectorServer::getUrl);
321321
serversSelectButton.itemsProperty().set(config().getAuthlibInjectorServers());
322322

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ public DownloadSettingsPage() {
7878
var versionListSourcePane = new LineSelectButton<String>();
7979
versionListSourcePane.disableProperty().bind(autoChooseDownloadSource.selectedProperty().not());
8080
versionListSourcePane.setTitle(i18n("settings.launcher.version_list_source"));
81-
versionListSourcePane.setConverter(converter);
81+
versionListSourcePane.setNullSafeConverter(converter);
8282
versionListSourcePane.setDescriptionConverter(descriptionConverter);
8383
versionListSourcePane.setItems(DownloadProviders.AUTO_PROVIDERS.keySet());
8484
versionListSourcePane.valueProperty().bindBidirectional(config().versionListSourceProperty());
8585

8686
var downloadSourcePane = new LineSelectButton<String>();
8787
downloadSourcePane.disableProperty().bind(autoChooseDownloadSource.selectedProperty());
8888
downloadSourcePane.setTitle(i18n("settings.launcher.download_source"));
89-
downloadSourcePane.setConverter(converter);
89+
downloadSourcePane.setNullSafeConverter(converter);
9090
downloadSourcePane.setDescriptionConverter(descriptionConverter);
9191
downloadSourcePane.setItems(DownloadProviders.DIRECT_PROVIDERS.keySet());
9292
downloadSourcePane.valueProperty().bindBidirectional(config().downloadTypeProperty());
9393

9494
var defaultAddonSourcePane = new LineSelectButton<String>();
9595
defaultAddonSourcePane.setTitle(i18n("settings.launcher.default_addon_source"));
96-
defaultAddonSourcePane.setConverter(key -> I18n.i18n("mods." + key));
96+
defaultAddonSourcePane.setNullSafeConverter(key -> I18n.i18n("mods." + key));
9797
defaultAddonSourcePane.setItems("modrinth", "curseforge");
9898
defaultAddonSourcePane.valueProperty().bindBidirectional(config().defaultAddonSourceProperty());
9999

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public PersonalizationPage() {
7979
{
8080
var brightnessPane = new LineSelectButton<String>();
8181
brightnessPane.setTitle(i18n("settings.launcher.brightness"));
82-
brightnessPane.setConverter(name -> i18n("settings.launcher.brightness." + name));
82+
brightnessPane.setNullSafeConverter(name -> i18n("settings.launcher.brightness." + name));
8383
brightnessPane.setItems("auto", "light", "dark");
8484
brightnessPane.valueProperty().bindBidirectional(config().themeBrightnessProperty());
8585

@@ -295,7 +295,7 @@ public void changed(ObservableValue<? extends EnumBackgroundImage> observable, E
295295
var fontAntiAliasingPane = new LineSelectButton<Optional<FontSmoothingType>>();
296296
fontAntiAliasingPane.setTitle(i18n("settings.launcher.font.anti_aliasing"));
297297
fontAntiAliasingPane.setSubtitle(i18n("settings.take_effect_after_restart"));
298-
fontAntiAliasingPane.setConverter(value ->
298+
fontAntiAliasingPane.setNullSafeConverter(value ->
299299
value.isPresent()
300300
? i18n("settings.launcher.font.anti_aliasing." + value.get().name().toLowerCase(Locale.ROOT))
301301
: i18n("settings.launcher.font.anti_aliasing.auto")

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected int getTrailingTextIndex() {
110110
updateButton.setOnAction(e -> onUpdate(updateChannel));
111111

112112
updatePane.setConverter(channel -> i18n("update.channel." + channel.channelName));
113+
updatePane.setNullSafeConverter(channel -> i18n("update.channel." + channel.channelName));
113114
updatePane.setItems(List.of(UpdateChannel.STABLE, UpdateChannel.DEVELOPMENT));
114115
updatePane.setDescriptionConverter(channel -> i18n("update.note." + channel.channelName));
115116

@@ -186,7 +187,7 @@ protected int getTrailingTextIndex() {
186187
chooseLanguagePane.setSubtitle(i18n("settings.take_effect_after_restart"));
187188

188189
SupportedLocale currentLocale = I18n.getLocale();
189-
chooseLanguagePane.setConverter(locale -> {
190+
chooseLanguagePane.setNullSafeConverter(locale -> {
190191
if (locale.isDefault())
191192
return locale.getDisplayName(currentLocale);
192193
else if (locale.isSameLanguage(currentLocale))

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/AdvancedVersionSettingPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public AdvancedVersionSettingPage(Profile profile, @Nullable String versionId, V
191191

192192
graphicsBackendPane = new LineSelectButton<>();
193193
graphicsBackendPane.setTitle(i18n("settings.advanced.graphics_backend"));
194-
graphicsBackendPane.setConverter(backend -> i18n("settings.advanced.graphics_backend." + backend.name().toLowerCase(Locale.ROOT)));
194+
graphicsBackendPane.setNullSafeConverter(backend -> i18n("settings.advanced.graphics_backend." + backend.name().toLowerCase(Locale.ROOT)));
195195
graphicsBackendPane.setDescriptionConverter(backend -> switch (backend) {
196196
case DEFAULT -> i18n("settings.advanced.graphics_backend.default.desc");
197197
case OPENGL -> i18n("settings.advanced.graphics_backend.opengl.desc");
@@ -210,7 +210,7 @@ else if (gameVersion.compareTo("26.2-snapshot-2") < 0)
210210

211211
rendererPane = new LineSelectButton<>();
212212
rendererPane.setTitle(i18n("settings.advanced.renderer"));
213-
rendererPane.setConverter(e -> i18n("settings.advanced.renderer." + e.name().toLowerCase(Locale.ROOT)));
213+
rendererPane.setNullSafeConverter(e -> i18n("settings.advanced.renderer." + e.name().toLowerCase(Locale.ROOT)));
214214
rendererPane.setDescriptionConverter(e -> {
215215
String bundleKey = "settings.advanced.renderer." + e.name().toLowerCase(Locale.ROOT) + ".desc";
216216
return I18n.hasKey(bundleKey) ? i18n(bundleKey) : null;

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public VersionSettingsPage(boolean globalSetting) {
336336
launcherVisibilityPane = new LineSelectButton<>();
337337
launcherVisibilityPane.setTitle(i18n("settings.advanced.launcher_visible"));
338338
launcherVisibilityPane.setItems(LauncherVisibility.values());
339-
launcherVisibilityPane.setConverter(e -> i18n("settings.advanced.launcher_visibility." + e.name().toLowerCase(Locale.ROOT)));
339+
launcherVisibilityPane.setNullSafeConverter(e -> i18n("settings.advanced.launcher_visibility." + e.name().toLowerCase(Locale.ROOT)));
340340

341341
BorderPane dimensionPane = new BorderPane();
342342
{
@@ -372,7 +372,7 @@ public VersionSettingsPage(boolean globalSetting) {
372372
enableDebugLogOutputPane.setTitle(i18n("settings.enable_debug_log_output"));
373373
processPriorityPane = new LineSelectButton<>();
374374
processPriorityPane.setTitle(i18n("settings.advanced.process_priority"));
375-
processPriorityPane.setConverter(e -> i18n("settings.advanced.process_priority." + e.name().toLowerCase(Locale.ROOT)));
375+
processPriorityPane.setNullSafeConverter(e -> i18n("settings.advanced.process_priority." + e.name().toLowerCase(Locale.ROOT)));
376376
processPriorityPane.setDescriptionConverter(e -> {
377377
String bundleKey = "settings.advanced.process_priority." + e.name().toLowerCase(Locale.ROOT) + ".desc";
378378
return I18n.hasKey(bundleKey) ? i18n(bundleKey) : null;

0 commit comments

Comments
 (0)