Skip to content

Commit a7b4b9f

Browse files
committed
resolve startup issue where F5 was not pressed
1 parent c137c27 commit a7b4b9f

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java

+32-17
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void setConfig(Configuration config, Stage primaryStage,
156156
@Override
157157
protected Void call() throws Exception {
158158
System.out.println("Waiting for normal state via asyncDebugView");
159-
asyncDebugView().get(); // Wait for the async operation to complete
159+
asyncDebugView().get(); // Wait for the async operation to complete
160160
waitForNormalState();
161161
System.out.println("before update");
162162
removeOldJars(config);
@@ -168,27 +168,42 @@ protected Void call() throws Exception {
168168

169169
}
170170

171-
public Future<String> asyncDebugView() throws InterruptedException {
171+
public Future<String> asyncDebugView() {
172172
CompletableFuture<String> completableFuture = new CompletableFuture<>();
173173
Executors.newCachedThreadPool().submit(() -> {
174-
System.out.println("asyncDebugView futuer start!!!!!!!");
174+
System.out.println("asyncDebugView future start!");
175175
System.out.println("StartupState = " + startupState);
176-
int counter = 0;
177-
while (startupState == App.state.WAIT || startupState == App.state.DEBUG) {
176+
177+
// Duration to wait (e.g., 3 seconds)
178+
long waitDuration = 3000; // milliseconds
179+
long startTime = System.currentTimeMillis();
180+
181+
// Check for the DEBUG state every 100ms
182+
while (System.currentTimeMillis() - startTime < waitDuration) {
183+
if (startupState == App.state.DEBUG) {
184+
System.out.println("DEBUG mode activated, keeping state as DEBUG");
185+
completableFuture.complete("Debug Mode");
186+
return "Debug Mode"; // Return String indicating the debug mode
187+
}
178188
try {
179-
if (counter == 500 && startupState != App.state.DEBUG) {
180-
startupState = App.state.NORMAL;
181-
}
182-
Thread.sleep(5);
183-
counter++;
184-
} catch (InterruptedException ex) {
185-
// On purpose
189+
Thread.sleep(100);
190+
} catch (InterruptedException e) {
191+
Thread.currentThread().interrupt();
192+
completableFuture.completeExceptionally(e);
193+
return "Interrupted"; // Return String indicating an interruption
186194
}
187195
}
188-
completableFuture.complete("Hello");
189-
return null;
196+
197+
// If DEBUG mode not activated within timeout, set to NORMAL
198+
if (startupState != App.state.DEBUG) {
199+
System.out.println("Timeout reached without DEBUG mode, setting state to NORMAL");
200+
startupState = App.state.NORMAL;
201+
}
202+
203+
completableFuture.complete("Normal State");
204+
return "Normal State"; // Return String indicating normal state
190205
});
191-
206+
192207
System.out.println("Return future");
193208
return completableFuture;
194209
}
@@ -209,7 +224,7 @@ void update() {
209224
Task<Void> doUpdate = new Task<>() {
210225
@Override
211226
protected Void call() throws Exception {
212-
//asyncDebugView().get();
227+
// asyncDebugView().get();
213228
if (!config.requiresUpdate()) {
214229
if (!daemonDirExists()) {
215230
extractDaemon();
@@ -535,7 +550,7 @@ public void launchApp() {
535550
stage.hide();
536551
});
537552
}
538-
553+
539554
private void setupInjectable() {
540555
inject = new Injectable() {
541556
@InjectSource

0 commit comments

Comments
 (0)