public boolean isRunning(int maxTime) { if (!isValid()) { return false; } for (int n = 0; n < maxTime; n++) { int retVal = _osUtil.isRunning(makeAppEntry()); if (retVal > 0) { return true; } RunTime.pause(1); } return false; }
/** * tries to make it the foreground application bringing its window with the given number to front * * @param num window * @return the App instance or null on failure */ public App focus(int num) { if (!isValid()) { if (!appWindow.startsWith("!")) { return this; } } if (isImmediate) { appPID = _osUtil.switchto(appNameGiven, num); } else { init(_osUtil.switchto(makeAppEntry(), num)); } if (appPID < 0) { Debug.error("App.focus failed: " + (num > 0 ? " #" + num : "") + " " + this.toString()); return null; } else { Debug.action("App.focus: " + (num > 0 ? " #" + num : "") + " " + this.toStringShort()); if (appPID < 1) { init(); } } return this; } //</editor-fold>
/** * tries to close the app defined by this App instance * * @return this or null on failure */ public int close() { if (!isValid()) { return 0; } if (appPID > -1) { init(appPID); } else if (isImmediate) { init(); } int ret = _osUtil.close(makeAppEntry()); if (ret > -1) { Debug.action("App.close: %s", this.toStringShort()); appPID = -1; appWindow = ""; } else { Debug.error("App.close %s did not work", this); } return ret; } //</editor-fold>
private App openAndWait(int waitTime) { if (isImmediate) { appPID = _osUtil.open(appNameGiven); } else { AppEntry appEntry = makeAppEntry(); init(_osUtil.open(appEntry)); } if (appPID < 0) { Debug.error("App.open failed: " + appNameGiven + " not found"); notFound = true; } else { Debug.action("App.open " + this.toStringShort()); } if (isImmediate && notFound) { return null; } if (waitTime > 0) { if (!isRunning(waitTime)) { return null; } } return this; } //</editor-fold>