public static void main(String[] args) throws Exception { // We don't want to do the full argument parsing here as that might easily change in update // versions // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); parser .accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) .withRequiredArg(); parser .accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)) .withRequiredArg(); OptionSet options; try { options = parser.parse(args); } catch (OptionException ex) { System.out.println("error: " + ex.getMessage()); System.out.println(); parser.printHelpOn(System.out); System.exit(EXIT_FAILURE); return; } BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options); // need to call that before BitsquareAppMain().execute(args) initAppDir(bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY)); // For some reason the JavaFX launch process results in us losing the thread context class // loader: reset it. // In order to work around a bug in JavaFX 8u25 and below, you must include the following code // as the first line of your realMain method: Thread.currentThread().setContextClassLoader(BitsquareAppMain.class.getClassLoader()); new BitsquareAppMain().execute(args); }
public void init() { log.info("UpdateFX current version " + Version.PATCH_VERSION); // process.timeout() will cause an error state back but we don't want to break startup in case // of an timeout timeoutTimer = Utilities.setTimeout( 10000, () -> { log.error("Timeout reached for UpdateFX"); process.onCompleted(); }); String userAgent = environment.getProperty(BitsquareEnvironment.APP_NAME_KEY) + Version.VERSION; // Check if there is a new minor version release out. The release_url should be empty if no // release is available, otherwise the download url. try { releaseUrl = Utilities.readTextFileFromServer(UPDATES_BASE_URL + "/release_url", userAgent); if (releaseUrl != null && releaseUrl.length() > 0) { log.info("New release available at: " + releaseUrl); state.set(State.NEW_RELEASE); timeoutTimer.cancel(); return; } else { // All ok. Empty file if we have no new release. } } catch (IOException e) { // ignore. File might be missing } Updater updater = new Updater( UPDATES_BASE_URL, userAgent, Version.PATCH_VERSION, Paths.get(environment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY)), ROOT_CLASS_PATH, UPDATE_SIGNING_KEYS, UPDATE_SIGNING_THRESHOLD) { @Override protected void updateProgress(long workDone, long max) { // log.trace("updateProgress " + workDone + "/" + max); super.updateProgress(workDone, max); } }; /* updater.progressProperty().addListener((observableValue, oldValue, newValue) -> { log.trace("progressProperty newValue = " + newValue); });*/ log.info("Checking for updates!"); updater.setOnSucceeded( event -> { try { UpdateSummary summary = updater.get(); log.info("summary " + summary.toString()); if (summary.descriptions != null && summary.descriptions.size() > 0) { log.info("One liner: {}", summary.descriptions.get(0).getOneLiner()); log.info("{}", summary.descriptions.get(0).getDescription()); } if (summary.highestVersion > Version.PATCH_VERSION) { log.info("UPDATE_AVAILABLE"); state.set(State.UPDATE_AVAILABLE); // We stop the timeout and treat it not completed. // The user should click the restart button manually if there are updates available. timeoutTimer.cancel(); } else if (summary.highestVersion == Version.PATCH_VERSION) { log.info("UP_TO_DATE"); state.set(State.UP_TO_DATE); timeoutTimer.cancel(); process.onCompleted(); } } catch (Throwable e) { log.error("Exception at processing UpdateSummary: " + e.getMessage()); // we treat errors as update not as critical errors to prevent startup, // so we use state.onCompleted() instead of state.onError() state.set(State.FAILURE); timeoutTimer.cancel(); process.onCompleted(); } }); updater.setOnFailed( event -> { log.error("Update failed: " + updater.getException()); updater.getException().printStackTrace(); // we treat errors as update not as critical errors to prevent startup, // so we use state.onCompleted() instead of state.onError() state.set(State.FAILURE); timeoutTimer.cancel(); process.onCompleted(); }); Thread thread = new Thread(updater, "Online update check"); thread.setDaemon(true); thread.start(); }