diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/BCV.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/BCV.java index 98e62a09..aadc3c16 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/BCV.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/BCV.java @@ -22,6 +22,7 @@ import the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection; import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; +import the.bytecode.club.bytecodeviewer.util.SleepUtil; import static the.bytecode.club.bytecodeviewer.Constants.DEV_MODE; import static the.bytecode.club.bytecodeviewer.Constants.fs; @@ -290,14 +291,9 @@ public class BCV */ public static void hideFrame(JFrame frame, long milliseconds) { - new Thread(()->{ - long started = System.currentTimeMillis(); - while(System.currentTimeMillis()-started <= milliseconds) - { - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { } - } + new Thread(()-> + { + SleepUtil.sleep(milliseconds); frame.setVisible(false); }, "Timed Swing Hide").start(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java index edc262fa..54fcec43 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java @@ -13,6 +13,7 @@ import the.bytecode.club.bytecodeviewer.resources.ExternalResources; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; +import the.bytecode.club.bytecodeviewer.util.SleepUtil; import static the.bytecode.club.bytecodeviewer.Constants.fs; import static the.bytecode.club.bytecodeviewer.Constants.nl; @@ -95,15 +96,10 @@ public class JavaCompiler extends InternalCompiler Process process = pb.start(); BytecodeViewer.createdProcesses.add(process); - Thread failSafe = new Thread(() -> { - long started = System.currentTimeMillis(); - while (System.currentTimeMillis() - started <= 10_000) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + Thread failSafe = new Thread(() -> + { + //wait 10 seconds + SleepUtil.sleep(10_000); if (process.isAlive()) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java index d7c5000e..ad89b081 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/BootCheck.java @@ -47,15 +47,8 @@ public class BootCheck implements Runnable @Override public void run() { - long start = System.currentTimeMillis(); - //7 second failsafe - while (System.currentTimeMillis() - start < 7000) - { - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { } - } + SleepUtil.sleep(7000); //if it's failed to boot and it's not downloading attempt to load the libraries failSafeLoadLibraries(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/SleepUtil.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/SleepUtil.java new file mode 100644 index 00000000..d134673d --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/SleepUtil.java @@ -0,0 +1,20 @@ +package the.bytecode.club.bytecodeviewer.util; + +/** + * @author Konloch + * @since 8/21/2024 + */ +public class SleepUtil +{ + public static void sleep(long ms) + { + try + { + Thread.sleep(ms); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +}