-
Notifications
You must be signed in to change notification settings - Fork 909
[Enhancement] 启动器检查更新失败时显示提示 #6286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,10 +37,7 @@ | |
| import org.jackhuang.hmcl.ui.SVG; | ||
| import org.jackhuang.hmcl.ui.construct.*; | ||
| import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; | ||
| import org.jackhuang.hmcl.upgrade.RemoteVersion; | ||
| import org.jackhuang.hmcl.upgrade.UpdateChannel; | ||
| import org.jackhuang.hmcl.upgrade.UpdateChecker; | ||
| import org.jackhuang.hmcl.upgrade.UpdateHandler; | ||
| import org.jackhuang.hmcl.upgrade.*; | ||
| import org.jackhuang.hmcl.util.Lang; | ||
| import org.jackhuang.hmcl.util.StringUtils; | ||
| import org.jackhuang.hmcl.util.i18n.I18n; | ||
|
|
@@ -113,7 +110,7 @@ protected int getTrailingTextIndex() { | |
|
|
||
| final StringProperty lblUpdateSubProperty = updatePane.subtitleProperty(); | ||
|
|
||
| { | ||
| if (IntegrityChecker.DISABLE_SELF_INTEGRITY_CHECK || IntegrityChecker.isSelfVerified()) { | ||
| updateListener = any -> { | ||
| boolean outdated = UpdateChecker.isOutdated(); | ||
|
|
||
|
|
@@ -125,14 +122,24 @@ protected int getTrailingTextIndex() { | |
| lblUpdateSubProperty.set(i18n("update.newest_version", UpdateChecker.getLatestVersion().version())); | ||
| } else if (UpdateChecker.isCheckingUpdate()) { | ||
| lblUpdateSubProperty.set(i18n("update.checking")); | ||
| } else if (UpdateChecker.errorProperty().get() != null) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an earlier successful check found an update and a later check fails (for example, after toggling Preview), Useful? React with 👍 / 👎. |
||
| Throwable t = UpdateChecker.errorProperty().get(); | ||
| String msg = t.getClass().getSimpleName() + ": " + t.getLocalizedMessage(); | ||
| lblUpdateSubProperty.set(i18n("update.check_failed", msg)); | ||
| } else { | ||
| lblUpdateSubProperty.set(i18n("update.latest")); | ||
| } | ||
| }; | ||
| UpdateChecker.latestVersionProperty().addListener(new WeakInvalidationListener(updateListener)); | ||
| UpdateChecker.outdatedProperty().addListener(new WeakInvalidationListener(updateListener)); | ||
| UpdateChecker.checkingUpdateProperty().addListener(new WeakInvalidationListener(updateListener)); | ||
| UpdateChecker.errorProperty().addListener(new WeakInvalidationListener(updateListener)); | ||
| updateListener.invalidated(null); | ||
| } else { | ||
| updateButton.setVisible(false); | ||
| updateButton.setManaged(false); | ||
| lblUpdateSubProperty.set(i18n("update.unverified")); | ||
| updateListener = null; | ||
| } | ||
|
|
||
| updatePaneList.getContent().add(updatePane); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ private UpdateChecker() { | |
| }, | ||
| latestVersion); | ||
| private static final ReadOnlyBooleanWrapper checkingUpdate = new ReadOnlyBooleanWrapper(false); | ||
| private static final ReadOnlyObjectWrapper<Throwable> error = new ReadOnlyObjectWrapper<>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new wrapper is assigned Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The added Useful? React with 👍 / 👎. |
||
|
|
||
| public static void init() { | ||
| requestCheckUpdate(UpdateChannel.getChannel(), settings().acceptPreviewUpdateProperty().get()); | ||
|
|
@@ -83,6 +84,10 @@ public static ReadOnlyBooleanProperty checkingUpdateProperty() { | |
| return checkingUpdate.getReadOnlyProperty(); | ||
| } | ||
|
|
||
| public static ReadOnlyObjectProperty<Throwable> errorProperty() { | ||
| return error.getReadOnlyProperty(); | ||
| } | ||
|
|
||
| private static RemoteVersion checkUpdate(UpdateChannel channel, boolean preview) throws IOException { | ||
| if (!IntegrityChecker.DISABLE_SELF_INTEGRITY_CHECK && !IntegrityChecker.isSelfVerified()) { | ||
| throw new IOException("Self verification failed"); | ||
|
|
@@ -109,16 +114,22 @@ public static void requestCheckUpdate(UpdateChannel channel, boolean preview) { | |
|
|
||
| thread(() -> { | ||
| RemoteVersion result = null; | ||
| Throwable t = null; | ||
| try { | ||
| result = checkUpdate(channel, preview); | ||
| LOG.info("Latest version (" + channel + ", preview=" + preview + ") is " + result); | ||
| } catch (Throwable e) { | ||
| t = e; | ||
| LOG.warning("Failed to check for update", e); | ||
| } | ||
| Throwable throwable = t; | ||
|
|
||
| RemoteVersion finalResult = result; | ||
| Platform.runLater(() -> { | ||
| if (finalResult != null) { | ||
| if (throwable != null) { | ||
| error.set(throwable); | ||
| } else { | ||
| error.set(null); | ||
| latestVersion.set(finalResult); | ||
| } | ||
|
ToobLac marked this conversation as resolved.
|
||
| checkingUpdate.set(false); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntegrityChecker.isSelfVerified()is explicitly blocking and, on its first call, reads and hashes the entire launcher JAR. This condition runs whileSettingsPageis being constructed on the JavaFX thread; therefore opening or preloading Settings before the background update check has completed can freeze the UI until verification finishes. Keep this verification in the existing background update-check path and publish its result back to the UI instead.Useful? React with 👍 / 👎.