Skip to content

Commit

Permalink
Use a separate thread for every custom update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
henkelmax committed Apr 2, 2024
1 parent 3c19514 commit fbc43b4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

public interface UpdateChecker {

/**
* Gets called when ModMenu is checking for updates.
* This is done in a separate thread, so this call can/should be blocking.
*
* @return The update info
*/
UpdateInfo checkForUpdates();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.terraformersmc.modmenu.util;

import com.terraformersmc.modmenu.util.mod.Mod;

public class UpdateCheckerThread extends Thread {

protected UpdateCheckerThread(Mod mod, Runnable runnable) {
super(runnable);
setDaemon(true);
setName("Update Checker/%s".formatted(mod.getName()));
}

public static void run(Mod mod, Runnable runnable) {
new UpdateCheckerThread(mod, runnable).start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ public static void checkForUpdates() {
return;
}

Util.getMainWorkerExecutor().execute(() -> {
LOGGER.info("Checking mod updates...");
checkForModrinthUpdates();
checkForCustomUpdates();
});
LOGGER.info("Checking mod updates...");
Util.getMainWorkerExecutor().execute(UpdateCheckerUtil::checkForModrinthUpdates);
checkForCustomUpdates();
}

public static void checkForCustomUpdates() {
Expand All @@ -52,7 +50,7 @@ public static void checkForCustomUpdates() {
if (updateChecker == null) {
return;
}
mod.setUpdateInfo(updateChecker.checkForUpdates());
UpdateCheckerThread.run(mod, () -> mod.setUpdateInfo(updateChecker.checkForUpdates()));
});
}

Expand Down

0 comments on commit fbc43b4

Please sign in to comment.