diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java index f2f0c539e..fb7201037 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorDownloader.java @@ -45,6 +45,11 @@ public class AuthlibInjectorDownloader { private Path artifactLocation; private Supplier downloadProvider; + /** + * The flag will be reset after application restart. + */ + private boolean updateChecked = false; + /** * @param artifactsDirectory where to save authlib-injector artifacts */ @@ -57,14 +62,17 @@ public class AuthlibInjectorDownloader { synchronized (artifactLocation) { Optional local = getLocalArtifact(); - try { - update(local); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to download authlib-injector", e); - if (!local.isPresent()) { - throw e; + if (!local.isPresent() || !updateChecked) { + try { + update(local); + updateChecked = true; + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to download authlib-injector", e); + if (!local.isPresent()) { + throw e; + } + LOG.warning("Fallback to use cached artifact: " + local.get()); } - LOG.warning("Fallback to use cached artifact: " + local.get()); } return getLocalArtifact().orElseThrow(() -> new IOException("The updated authlib-inejector cannot be recognized")); @@ -72,6 +80,7 @@ public class AuthlibInjectorDownloader { } private void update(Optional local) throws IOException { + LOG.info("Checking update of authlib-injector"); AuthlibInjectorVersionInfo latest = getLatestArtifactInfo(); if (local.isPresent() && local.get().getBuildNumber() >= latest.buildNumber) {