Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ public void setDisableAutoShowUpdateDialog(boolean disableAutoShowUpdateDialog)
this.disableAutoShowUpdateDialog.set(disableAutoShowUpdateDialog);
}

@SerializedName("backgroundAutoDownloadUpdate")
private final BooleanProperty backgroundAutoDownloadUpdate = new SimpleBooleanProperty(false);

public BooleanProperty backgroundAutoDownloadUpdateProperty() {
return backgroundAutoDownloadUpdate;
}

public boolean isBackgroundAutoDownloadUpdate() {
return backgroundAutoDownloadUpdate.get();
}

public void setBackgroundAutoDownloadUpdate(boolean backgroundAutoDownloadUpdate) {
this.backgroundAutoDownloadUpdate.set(backgroundAutoDownloadUpdate);
}

@SerializedName("disableAprilFools")
private final BooleanProperty disableAprilFools = new SimpleBooleanProperty(false);

Expand Down
17 changes: 17 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.jackhuang.hmcl.setting.*;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.upgrade.RemoteVersion;
import org.jackhuang.hmcl.upgrade.UpdateHandler;
import org.jackhuang.hmcl.ui.account.AccountListPage;
import org.jackhuang.hmcl.ui.animation.AnimationUtils;
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
Expand Down Expand Up @@ -119,6 +121,8 @@ public final class Controllers {
});
private static Lazy<RootPage> rootPage = new Lazy<>(RootPage::new);
private static DecoratorController decorator;
@Nullable
private static Path lastPendingUpdateNotificationJar;
private static DownloadPage downloadPage;
private static Lazy<AccountListPage> accountListPage = new Lazy<>(() -> {
AccountListPage accountListPage = new AccountListPage();
Expand Down Expand Up @@ -622,6 +626,18 @@ public static void showToast(String content) {
decorator.showToast(content);
}

public static void showPendingUpdateNotification(Path stagedJar, RemoteVersion version) {
FXUtils.checkFxUserThread();
if (stagedJar.equals(lastPendingUpdateNotificationJar)) {
return;
}
lastPendingUpdateNotificationJar = stagedJar;
decorator.showPersistentSnackbar(
i18n("update.background_downloaded.toast", version.version()),
i18n("update.restart_to_apply"),
() -> UpdateHandler.applyStagedUpdate(stagedJar));
}

public static void onHyperlinkAction(String href) {
if (href.startsWith("hmcl://")) {
switch (href) {
Expand All @@ -644,6 +660,7 @@ public static boolean isStopped() {
}

public static void shutdown() {
lastPendingUpdateNotificationJar = null;
rootPage = null;
versionPage = null;
gameListPage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ public void showToast(String content) {
decorator.getSnackbar().fireEvent(new JFXSnackbar.SnackbarEvent(new JFXSnackbarLayout(content)));
}

public void showPersistentSnackbar(String message, String actionText, Runnable action) {
FXUtils.checkFxUserThread();
JFXSnackbarLayout layout = new JFXSnackbarLayout(message, actionText, e -> action.run());
decorator.getSnackbar().enqueue(new JFXSnackbar.SnackbarEvent(layout, Duration.INDEFINITE));
}

// ==== Wizard ====

public void startWizard(WizardProvider wizardProvider) {
Expand Down
23 changes: 19 additions & 4 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public SettingsPage() {
{

JFXButton updateButton = FXUtils.newToggleButton4(SVG.UPDATE, 20);
updateButton.setOnAction(e -> onUpdate());
updateButton.setPadding(Insets.EMPTY);
FXUtils.installFastTooltip(updateButton, i18n("update.tooltip"));

Expand All @@ -108,6 +107,9 @@ protected int getTrailingTextIndex() {
updatePane.setTitle(i18n("update"));
updatePane.setValue(UpdateChannel.getChannel());

updateButton.setOnAction(e -> onUpdate(updateChannel));

updatePane.setConverter(channel -> i18n("update.channel." + channel.channelName));
updatePane.setNullSafeConverter(channel -> i18n("update.channel." + channel.channelName));
updatePane.setItems(List.of(UpdateChannel.STABLE, UpdateChannel.DEVELOPMENT));
updatePane.setDescriptionConverter(channel -> i18n("update.note." + channel.channelName));
Expand All @@ -118,8 +120,6 @@ protected int getTrailingTextIndex() {
updateListener = any -> {
boolean outdated = UpdateChecker.isOutdated();

updateButton.setVisible(outdated);
updateButton.setManaged(outdated);
updatePane.pseudoClassStateChanged(PseudoClass.getPseudoClass("active"), outdated);

if (UpdateChecker.isOutdated()) {
Expand Down Expand Up @@ -162,6 +162,19 @@ protected int getTrailingTextIndex() {
updatePaneList.getContent().add(disableAutoShowUpdateDialogPane);
}

{
LineToggleButton backgroundDownloadPane = new LineToggleButton();
backgroundDownloadPane.setTitle(i18n("settings.launcher.update.background_auto_download"));
backgroundDownloadPane.setSubtitle(i18n("settings.launcher.update.background_auto_download.subtitle"));
backgroundDownloadPane.selectedProperty().bindBidirectional(config().backgroundAutoDownloadUpdateProperty());
backgroundDownloadPane.selectedProperty().addListener((obs, oldVal, newVal) -> {
if (Boolean.TRUE.equals(newVal) && !Boolean.TRUE.equals(oldVal)) {
UpdateHandler.tryAutoDownloadIfOutdated();
}
});
updatePaneList.getContent().add(backgroundDownloadPane);
}

rootPane.getChildren().addAll(ComponentList.createComponentListTitle(i18n("update")), updatePaneList);
}

Expand Down Expand Up @@ -270,9 +283,11 @@ private void openLogFolder() {
FXUtils.openFolder(LOG.getLogFile().getParent());
}

private void onUpdate() {
private void onUpdate(ObjectProperty<UpdateChannel> updateChannel) {
RemoteVersion target = UpdateChecker.getLatestVersion();
if (target == null) {
UpdateChecker.requestCheckUpdate(updateChannel.get(), config().isAcceptPreviewUpdate());
Controllers.showToast(i18n("update.checking"));
return;
}
UpdateHandler.updateFrom(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private UpdateChecker() {

public static void init() {
requestCheckUpdate(UpdateChannel.getChannel(), config().isAcceptPreviewUpdate());
outdated.addListener(obs -> UpdateHandler.onOutdatedStateMayHaveChanged());
}

public static RemoteVersion getLatestVersion() {
Expand Down
Loading