From 952aa0e8a2dc242d7b5293e292d9f86375a6c0c7 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 15 Jul 2017 15:00:41 +0200 Subject: [PATCH] RuffyScripter.waitForMenuToBeLeft: add timeout. --- .../main/java/de/jotomo/ruffyscripter/RuffyScripter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index b472b11c22..89237d793f 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -99,7 +99,7 @@ public class RuffyScripter { }; public boolean isPumpBusy() { - return activeCmd != null; // || currentMenu == null || currentMenu.getType() != MenuType.MAIN_MENU; + return activeCmd != null; } private volatile Command activeCmd = null; @@ -287,8 +287,12 @@ public class RuffyScripter { * Wait till a menu changed has completed, "away" from the menu provided as argument. */ public void waitForMenuToBeLeft(MenuType menuType) { + long timeout = System.currentTimeMillis() + 30 * 1000; while (currentMenu.getType() == menuType) { - SystemClock.sleep(250); + if (System.currentTimeMillis() > timeout) { + throw new CommandException().message("Timeout waiting for menu " + menuType + " to be left"); + } + SystemClock.sleep(50); } }