diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index b67c9593..32efc000 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -4,7 +4,7 @@ parent org.unigrid.janus - 1.1.0-SNAPSHOT + 1.0.9-SNAPSHOT org.unigrid bootstrap diff --git a/bootstrap/src/main/java/org/unigrid/bootstrap/App.java b/bootstrap/src/main/java/org/unigrid/bootstrap/App.java index 33642f0c..7d013b00 100644 --- a/bootstrap/src/main/java/org/unigrid/bootstrap/App.java +++ b/bootstrap/src/main/java/org/unigrid/bootstrap/App.java @@ -40,6 +40,8 @@ of the License (see COPYING and COPYING.addendum). import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; +import java.util.Objects; +import java.util.Properties; import java.util.UUID; import javafx.application.HostServices; //import ch.qos.logback.classic.Level; @@ -113,6 +115,7 @@ public void start(Stage stage) throws IOException { stage.setResizable(false); stage.setScene(scene); stage.show(); + UpdateView.getInstance().setConfig(config, stage, inputArgs, hostServices); } diff --git a/bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java b/bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java index 83c64178..28e951e5 100644 --- a/bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java +++ b/bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java @@ -30,9 +30,8 @@ of the License (see COPYING and COPYING.addendum). import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Properties; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import javafx.animation.FadeTransition; @@ -81,6 +80,7 @@ public class UpdateView implements UpdateHandler, Injectable, Initializable { private Injectable inject; + private String bootstrapVersion = ""; private static UpdateView updateView = null; private static String startLoacation = getBaseDirectory(); @@ -98,11 +98,24 @@ public Stage getStage() { public void setConfig(Configuration config, Stage primaryStage, Map input, HostServices hostServices) { this.config = config; this.primaryStage = primaryStage; + Properties myProperties = new Properties(); + + try { + myProperties.load(App.class.getResourceAsStream("application.properties")); + bootstrapVersion = Objects.requireNonNull((String) myProperties.get("proj.ver")).replace("-SNAPSHOT", ""); + System.out.println("bootstrap version: " + bootstrapVersion); + } catch (IOException e) { + System.out.println(e.getMessage()); + System.out.println(e.getCause().toString()); + } + inject = new Injectable() { @InjectSource Map inputArgs = input; @InjectSource HostServices hostService = hostServices; + @InjectSource + String bootstrapVer = bootstrapVersion; }; System.out.println(input.get("URL")); diff --git a/bootstrap/src/main/resources-filtered/org/unigrid/bootstrap/application.properties b/bootstrap/src/main/resources-filtered/org/unigrid/bootstrap/application.properties new file mode 100644 index 00000000..3213b10a --- /dev/null +++ b/bootstrap/src/main/resources-filtered/org/unigrid/bootstrap/application.properties @@ -0,0 +1 @@ +proj.ver=${project.version} \ No newline at end of file diff --git a/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java b/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java index d365e85e..ddb02f11 100644 --- a/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java +++ b/config/UpdateWalletConfig/src/main/java/org/unigrid/updatewalletconfig/UpdateWalletConfig.java @@ -44,11 +44,11 @@ public static void main(String[] args) throws IOException { String configLocation = System.getProperty("user.dir"); String homeDir = System.getProperty("user.home"); String dir = configLocation; - String fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.1.0/fx-1.1.0-SNAPSHOT.jar"; + String fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; String linuxDaemon = "unigrid-2.9.3-x86_64-linux-gnu.tar.gz"; String windowsDaemon = "unigrid-2.9.3-win64.zip"; String osxDaemon = "unigrid-2.9.3-osx64.tar.gz"; - String fxVersion = "1.1.0"; + String fxVersion = "1.0.9"; String[] filePath = new String[]{ "/config-linux.xml", "/config-linux-test.xml", @@ -63,9 +63,9 @@ public static void main(String[] args) throws IOException { for (int i = 0; i < filePath.length; i++) { if ((i%2) == 0) { - fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.1.0/fx-1.1.0-SNAPSHOT.jar"; + fxJarUrl = "https://github.com/unigrid-project/unigrid-update/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; } else { - fxJarUrl = "https://github.com/unigrid-project/unigrid-update-testing/releases/download/v1.1.0/fx-1.1.0-SNAPSHOT.jar"; + fxJarUrl = "https://github.com/unigrid-project/unigrid-update-testing/releases/download/v1.0.9/fx-1.0.9-SNAPSHOT.jar"; } if (filePath[i].contains("linux")) { @@ -84,7 +84,7 @@ public static void main(String[] args) throws IOException { Configuration config = Configuration.builder() .basePath(basePath) - .file(FileMetadata.readFrom("../../fx/target/fx-1.1.0-SNAPSHOT.jar") + .file(FileMetadata.readFrom("../../fx/target/fx-1.0.9-SNAPSHOT.jar") .uri(fxJarUrl).modulepath()) .file(FileMetadata.readFrom("../../fx/target/jlink/cp/aopalliance-repackaged-3.0.3.jar") .uri(mavenUrl("org.glassfish.hk2.external", "aopalliance-repackaged", "3.0.3")).modulepath()) diff --git a/desktop/pom.xml b/desktop/pom.xml index ce47d06d..38905b8b 100644 --- a/desktop/pom.xml +++ b/desktop/pom.xml @@ -10,7 +10,7 @@ org.unigrid.janus parent - 1.1.0-SNAPSHOT + 1.0.9-SNAPSHOT org.unigrid.janus.Janus @@ -99,7 +99,7 @@ jpackage - 1.1.0 + 1.0.9 org.unigrid org.unigrid.bootstrap/org.unigrid.bootstrap.App @@ -122,7 +122,7 @@ jpackage - 1.1.0 + 1.0.9 target/dist/Unigrid diff --git a/fx/pom.xml b/fx/pom.xml index 706617bd..3da310b9 100644 --- a/fx/pom.xml +++ b/fx/pom.xml @@ -10,7 +10,7 @@ org.unigrid.janus parent - 1.1.0-SNAPSHOT + 1.0.9-SNAPSHOT org.unigrid.janus.Janus @@ -213,11 +213,11 @@ slf4j-api 2.0.0-alpha7 - + diff --git a/fx/src/main/java/org/unigrid/janus/Janus.java b/fx/src/main/java/org/unigrid/janus/Janus.java index 0090552d..29b071ae 100644 --- a/fx/src/main/java/org/unigrid/janus/Janus.java +++ b/fx/src/main/java/org/unigrid/janus/Janus.java @@ -49,6 +49,7 @@ of the License (see COPYING and COPYING.addendum). import org.unigrid.janus.view.MainWindow; import org.unigrid.janus.model.cdi.Eager; import org.unigrid.janus.controller.SplashScreenController; +import org.unigrid.janus.model.BootstrapModel; import org.unigrid.janus.model.JanusModel; import org.unigrid.janus.model.UpdateWallet; import org.unigrid.janus.model.Wallet; @@ -71,6 +72,7 @@ public class Janus extends BaseApplication implements PropertyChangeListener { @Inject private UpdateWallet updateWallet; @Inject private SplashScreenController splashController; @Inject private Wallet wallet; + @Inject private BootstrapModel bootModel; //@Inject private TrayService tray; private BooleanProperty ready = new SimpleBooleanProperty(false); diff --git a/fx/src/main/java/org/unigrid/janus/JanusLauncher.java b/fx/src/main/java/org/unigrid/janus/JanusLauncher.java index b0fad566..8a725084 100644 --- a/fx/src/main/java/org/unigrid/janus/JanusLauncher.java +++ b/fx/src/main/java/org/unigrid/janus/JanusLauncher.java @@ -27,6 +27,7 @@ of the License (see COPYING and COPYING.addendum). import javafx.stage.Stage; import lombok.SneakyThrows; import org.unigrid.janus.model.UpdateURL; +import org.unigrid.janus.model.BootstrapModel; import org.unigrid.janus.model.cdi.EagerExtension; import org.update4j.LaunchContext; import org.update4j.inject.InjectTarget; @@ -37,9 +38,16 @@ public class JanusLauncher implements Launcher { @InjectTarget private Map inputArgs = new HashMap(); - @InjectTarget + @InjectTarget(required = false) + // TODO enable once bootstraps are updated private HostServices hostService; + @InjectTarget(required = false) + private String bootstrapVer; + + @InjectTarget(required = false) + private String downloadUrl; + @Override @SneakyThrows public void run(LaunchContext lc) { System.out.println("before cotainer init"); @@ -59,11 +67,26 @@ public void run(LaunchContext lc) { UpdateURL.setWindowsUrl(inputArgs.get("URL")); } - if (inputArgs.containsKey("BootstrapURL")) { + System.out.println("bootstrapVer in fx: " + bootstrapVer); + + if(bootstrapVer != null && !bootstrapVer.equals("")) { + BootstrapModel.getInstance().setBootstrapVer(bootstrapVer); + } + + if (inputArgs.containsKey("downloadUrl")) { + BootstrapModel.getInstance().setDownloadUrl(inputArgs.get("downloadUrl")); + } + + if (inputArgs.containsKey("testing")) { + BootstrapModel.getInstance().setDownloadUrl(inputArgs.get("testing")); + } + + if(inputArgs.containsKey("BootstrapURL")){ UpdateURL.setBootstrapUrl(inputArgs.get("BootstrapURL")); } Platform.runLater(() -> { + System.out.println("run later"); Janus janus = container.select(Janus.class).get(); System.out.println(lc.getClassLoader()); Stage stage = new Stage(); diff --git a/fx/src/main/java/org/unigrid/janus/controller/WalletController.java b/fx/src/main/java/org/unigrid/janus/controller/WalletController.java index 85203daf..56d449f4 100644 --- a/fx/src/main/java/org/unigrid/janus/controller/WalletController.java +++ b/fx/src/main/java/org/unigrid/janus/controller/WalletController.java @@ -112,8 +112,13 @@ public void initialize(URL url, ResourceBundle rb) { public void compareBlockHeights() { //if (wallet.getCheckExplorer()) { - int explorerHeight = wallet.getExplorerHeight(); - System.out.println("EXPLORER HEIGHT: " + explorerHeight); + int explorerHeight; + try { + explorerHeight = wallet.getExplorerHeight(); + } catch (Exception e) { + explorerHeight = 0; + } + //System.out.println("EXPLORER HEIGHT: " + explorerHeight); if (wallet.getBlocks() < (explorerHeight - 100)) { // STOP LONG POLL IF RUNNING if (polling.getLongSyncTimerRunning()) { @@ -123,6 +128,7 @@ public void compareBlockHeights() { //wallet.setCheckExplorer(Boolean.TRUE); if (!polling.getSyncTimerRunning()) { polling.pollForSync(syncIntervalShort); + System.out.println("STARTING SHORT SYNC POLL"); } // FIRE SYNCING EVENT wallet.setSyncStatus(Wallet.SyncStatus.from("syncing")); @@ -136,6 +142,7 @@ public void compareBlockHeights() { // START LONG SYNC POLL if (!polling.getLongSyncTimerRunning()) { polling.longPollForSync(syncIntervalLong); + System.out.println("STARTING LONG SYNC POLL"); } System.out.println("BLOCK HEIGHT IS OK: " + wallet.getBlocks()); System.out.println("EXPLORER HEIGHT: " + explorerHeight); @@ -289,7 +296,7 @@ public void propertyChange(PropertyChangeEvent event) { } if (event.getPropertyName().equals(wallet.BLOCKS_PROPERTY)) { - if (!polling.getSyncTimerRunning() || !polling.getLongSyncTimerRunning()) { + if (!polling.getSyncTimerRunning() && !polling.getLongSyncTimerRunning()) { this.compareBlockHeights(); } } diff --git a/fx/src/main/java/org/unigrid/janus/controller/component/WindowBarController.java b/fx/src/main/java/org/unigrid/janus/controller/component/WindowBarController.java index 2a0cc31f..96086042 100644 --- a/fx/src/main/java/org/unigrid/janus/controller/component/WindowBarController.java +++ b/fx/src/main/java/org/unigrid/janus/controller/component/WindowBarController.java @@ -43,6 +43,7 @@ of the License (see COPYING and COPYING.addendum). import javafx.application.Platform; import javafx.util.Duration; import org.kordamp.ikonli.javafx.FontIcon; +import org.unigrid.janus.model.BootstrapModel; import org.unigrid.janus.model.UpdateWallet; import org.unigrid.janus.model.service.PollingService; import org.unigrid.janus.view.component.WindowBarButton; @@ -128,6 +129,12 @@ private void onExit(MouseEvent event) { // TODO: find a place to do this that is guaranteed to be called when // application is closed rpc.stopPolling(); + + //Force bootstrap update when it is awilable so the user has the latest one!!! + //TODO: maken an event of this insted or an observer + if(BootstrapModel.getInstance().getBootstrapUpdate()) { + update.doUpdate(); + } //final Window window = ((Node) event.getSource()).getScene().getWindow(); //window.fireEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST)); System.exit(0); @@ -173,6 +180,7 @@ public void run() { @FXML public void onUpdate(MouseEvent event) { + System.out.println("onUpdate clicked???"); updateButton.setVisible(false); update.doUpdate(); // TODO: move this code into UpdateWallet.java diff --git a/fx/src/main/java/org/unigrid/janus/model/BootstrapModel.java b/fx/src/main/java/org/unigrid/janus/model/BootstrapModel.java new file mode 100644 index 00000000..9d13427f --- /dev/null +++ b/fx/src/main/java/org/unigrid/janus/model/BootstrapModel.java @@ -0,0 +1,71 @@ +/* + The Janus Wallet + Copyright © 2021-2022 The Unigrid Foundation, UGD Software AB + + This program is free software: you can redistribute it and/or modify it under the terms of the + addended GNU Affero General Public License as published by the Free Software Foundation, version 3 + of the License (see COPYING and COPYING.addendum). + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received an addended copy of the GNU Affero General Public License with this program. + If not, see and . + */ + +package org.unigrid.janus.model; + +import jakarta.enterprise.context.ApplicationScoped; +import org.unigrid.janus.model.cdi.Eager; + +@Eager +@ApplicationScoped +public class BootstrapModel { + + private static BootstrapModel bootstrapModel = null; + private String bootstrapVer = "0.0.0"; + private String downloadUrl = "https://github.com/unigrid-project/janus-java/releases/download/"; + private Boolean testing = false; + + private boolean bootstrapUpdate = false; + + public static BootstrapModel getInstance() { + if (bootstrapModel == null) { + bootstrapModel = new BootstrapModel(); + } + return bootstrapModel; + } + + public String getBootstrapVer() { + return this.bootstrapVer; + } + + public void setBootstrapVer(String ver) { + this.bootstrapVer = ver; + } + + public void setBootstrapUpdate(boolean update) { + this.bootstrapUpdate = update; + } + + public boolean getBootstrapUpdate() { + return this.bootstrapUpdate; + } + + public String getDownloadUrl() { + return this.downloadUrl; + } + + public void setDownloadUrl(String url) { + this.downloadUrl = url; + } + + public Boolean getTesting() { + return this.testing; + } + + public void setTesting(Boolean test) { + this.testing = test; + } +} diff --git a/fx/src/main/java/org/unigrid/janus/model/UpdateURL.java b/fx/src/main/java/org/unigrid/janus/model/UpdateURL.java index ee497dba..f89db4bd 100644 --- a/fx/src/main/java/org/unigrid/janus/model/UpdateURL.java +++ b/fx/src/main/java/org/unigrid/janus/model/UpdateURL.java @@ -34,4 +34,5 @@ public class UpdateURL { @Getter @Setter private static String bootstrapUrl = "https://github.com/unigrid-project/janus-java/releases.atom"; + } diff --git a/fx/src/main/java/org/unigrid/janus/model/UpdateWallet.java b/fx/src/main/java/org/unigrid/janus/model/UpdateWallet.java index 82fd179d..207b0923 100644 --- a/fx/src/main/java/org/unigrid/janus/model/UpdateWallet.java +++ b/fx/src/main/java/org/unigrid/janus/model/UpdateWallet.java @@ -13,7 +13,6 @@ of the License (see COPYING and COPYING.addendum). You should have received an addended copy of the GNU Affero General Public License with this program. If not, see and . */ - package org.unigrid.janus.model; import jakarta.enterprise.context.ApplicationScoped; @@ -44,14 +43,22 @@ of the License (see COPYING and COPYING.addendum). import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import java.awt.Desktop; import java.io.BufferedReader; import java.io.File; +import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; -import java.util.Objects; +//import java.util.Objects; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; import javafx.application.Platform; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.stage.DirectoryChooser; +import javafx.stage.Stage; import org.apache.commons.io.FileUtils; import org.unigrid.janus.Janus; import org.unigrid.janus.model.entity.Feed; @@ -69,10 +76,12 @@ public class UpdateWallet extends TimerTask { private static DebugService debug = new DebugService(); private static final String BASE_URL = "https://raw.githubusercontent.com/unigrid-project/unigrid-update/main/%s"; private static final String BOOTSTRAP_URL = UpdateURL.getBootstrapUrl(); + private String DOWNLOAD_URL = BootstrapModel.getInstance().getDownloadUrl(); // private static PollingService polling = new PollingService(); private OS os = OS.CURRENT; + private int exitCode = 0; - private static final Map OS_CONFIG = ArrayUtils.toMap(new Object[][] { + private static final Map OS_CONFIG = ArrayUtils.toMap(new Object[][]{ {OS.LINUX, UpdateURL.getLinuxUrl()}, {OS.WINDOWS, UpdateURL.getWindowsUrl()}, {OS.MAC, UpdateURL.getMacUrl()} @@ -83,8 +92,6 @@ public enum UpdateState { UPDATE_NOT_READY } - private boolean bootstrapUpdate = false; - @Getter private static final String UPDATE_PROPERTY = "update"; @@ -94,10 +101,11 @@ public enum UpdateState { private static PropertyChangeSupport pcs; private Client client; private Feed githubJson; + private BootstrapModel bootstrapModel = BootstrapModel.getInstance(); public UpdateWallet() { System.out.println("Init walletUpdate"); - + bootstrapModel.getBootstrapVer(); initWebTarget(); if (this.pcs != null) { // TODO: Should this really be a fallthrough ? It looks dangerous. @@ -138,7 +146,7 @@ public void run() { } String title = "Unigrid"; - String launcherMessage = "New launcher update ready \nPlease press the update button!"; + String launcherMessage = "A new Unigrid launcher update is ready \nPlease press the update button!"; String fxMessage = "New update ready \nPlease press the update button!"; if (checkUpdateBootstrap()) { @@ -196,7 +204,7 @@ private Boolean checkUpdate() { System.err.println(mle.getMessage()); } - try (Reader in = new InputStreamReader(configUrl.openStream(), StandardCharsets.UTF_8)) { + try ( Reader in = new InputStreamReader(configUrl.openStream(), StandardCharsets.UTF_8)) { updateConfig = Configuration.read(in); System.out.println("Reading the config file"); } catch (IOException e) { @@ -228,13 +236,18 @@ private Boolean checkUpdateBootstrap() { System.out.println(e.getCause().toString()); } - String fullVer = Objects.requireNonNull((String) myProperties.get("proj.ver")); - String filteredVer = fullVer.replace("-SNAPSHOT", ""); + //String fullVer = Objects.requireNonNull((String) myProperties.get("proj.ver")); + //String filteredVer = fullVer.replace("-SNAPSHOT", ""); + String filteredVer = BootstrapModel.getInstance().getBootstrapVer(); + System.out.println("getBootstrapVer in UpdateWallet Check: " + BootstrapModel.getInstance().getBootstrapVer()); if ((getVersionNumber(filteredVer, 0) == getVersionNumber(getLatestVersion(), 0)) - && (getVersionNumber(filteredVer, 2) == getVersionNumber(getLatestVersion(), 2)) + && (getVersionNumber(filteredVer, 2) + == getVersionNumber(getLatestVersion(), 2)) + && (getVersionNumber(filteredVer, 4) + == getVersionNumber(getLatestVersion(), 4)) || getLatestVersion().equals("")) { - bootstrapUpdate = false; + bootstrapModel.setBootstrapUpdate(false); debug.print("VERSION: " + filteredVer, UpdateWallet.class.getSimpleName()); System.out.println("The latest version of the bootstrap is the same as the one we have"); } else { @@ -243,11 +256,13 @@ private Boolean checkUpdateBootstrap() { System.out.println("downloading linux installer"); if (getLinuxIDLike().equals("debian") && !checkTempFolder(getDEBFileName(getLatestVersion()), linuxPath)) { + removeOldInstall(linuxPath); downloadFile(getDownloadURL(getLatestVersion(), getDEBFileName(getLatestVersion())), linuxPath, getDEBFileName(getLatestVersion())); } else { + removeOldInstall(linuxPath); downloadFile(getDownloadURL(getLatestVersion(), getRPMFileName(getLatestVersion())), linuxPath, @@ -256,19 +271,21 @@ private Boolean checkUpdateBootstrap() { System.out.println("Did it start??"); } else if (OS.CURRENT == OS.MAC && !checkTempFolder(getDMGFileName(getLatestVersion()), macPath)) { + removeOldInstall(macPath); downloadFile(getDownloadURL(getLatestVersion(), getDMGFileName(getLatestVersion())), macPath, getDMGFileName(getLatestVersion())); } else if (OS.CURRENT == OS.WINDOWS && !checkTempFolder(getMSIFileName(getLatestVersion()), windowsPath)) { + removeOldInstall(windowsPath); downloadFile(getDownloadURL(getLatestVersion(), getMSIFileName(getLatestVersion())), windowsPath, getMSIFileName(getLatestVersion())); } - bootstrapUpdate = true; + bootstrapModel.setBootstrapUpdate(true); } - System.out.println("are we upadting the bootstrap: " + bootstrapUpdate); - return bootstrapUpdate; + System.out.println("are we upadting the bootstrap: " + bootstrapModel.getBootstrapUpdate()); + return bootstrapModel.getBootstrapUpdate(); } private boolean checkTempFolder(String fileName, String path) { @@ -287,12 +304,11 @@ private void restartWallet() { public void doUpdate() { final Object obj = new Object(); - System.out.println(bootstrapUpdate); + System.out.println(bootstrapModel.getBootstrapUpdate()); Thread t = new Thread(new Runnable() { @Override public void run() { - boolean isBootstrapUpdate = false; - if (false) { //(checkUpdateBootstrap()) { + if (bootstrapModel.getBootstrapUpdate()) { Process process; //TODO: Add RPM install line String linuxDebInstallExec = String.format("pkexec dpkg -i %s%s", linuxPath, @@ -309,7 +325,8 @@ public void run() { try { Process p = Runtime.getRuntime() .exec(linuxDebInstallExec); - p.waitFor(); + exitCode = p.waitFor(); + System.out.println(exitCode); } catch (Exception e) { System.out.println(e.getMessage()); } @@ -317,7 +334,7 @@ public void run() { try { Process p = Runtime.getRuntime() .exec(linuxRpmInstallExec); - p.waitFor(); + exitCode = p.waitFor(); } catch (Exception e) { System.out.println(e.getMessage()); } @@ -327,9 +344,9 @@ public void run() { try { Process p = Runtime.getRuntime() .exec(new String[]{"open", macInstallExec}); - int exitCode = p.waitFor(); + exitCode = p.waitFor(); System.out.println("exitCode " + exitCode); - isBootstrapUpdate = true; + bootstrapModel.setBootstrapUpdate(true); } catch (Exception e) { //TODO: handle exception System.out.println("cant open dmg: " + e.getMessage()); @@ -338,7 +355,10 @@ public void run() { try { System.out.println(windowsInstallExec); Process p = Runtime.getRuntime().exec(windowsInstallExec); - p.waitFor(); + exitCode = p.exitValue(); + if (exitCode == 0) { + System.exit(0); + } } catch (Exception e) { System.out.println(e.getMessage()); } @@ -354,14 +374,15 @@ public void run() { synchronized (obj) { obj.notifyAll(); } - System.out.println("!!!!We got passed the notyfiy"); - if (OS.CURRENT == OS.LINUX) { - System.out.println("run the app agien on linux"); + System.out.println("!!!!We got passed the notify"); + if (OS.CURRENT == OS.LINUX && exitCode == 0) { + System.out.println("run the app again on linux"); Runtime.getRuntime().exec(linuxExec); System.out.println("Did it start??"); - } else if (OS.CURRENT == OS.MAC && !isBootstrapUpdate) { + } else if (OS.CURRENT == OS.MAC && !bootstrapModel.getBootstrapUpdate() + && exitCode == 0) { Runtime.getRuntime().exec(macExec); - } else if (OS.CURRENT == OS.WINDOWS) { + } else if (OS.CURRENT == OS.WINDOWS && exitCode == 0) { Runtime.getRuntime().exec(windowsExec); } } catch (Exception e) { @@ -379,9 +400,47 @@ public void run() { System.out.println(e.getMessage()); } } + if (exitCode != 0) { + failedToInstallNewBootstrap(); + } System.exit(0); } + private void failedToInstallNewBootstrap() { + String link = "https://github.com/unigrid-project/janus-java/releases"; + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Unigrid"); + alert.setHeaderText("Failed to install new launcher."); + alert.setContentText("Please install manually\n " + link); + alert.showAndWait(); + + switch (OS.CURRENT) { + case LINUX: + try { + System.out.println("Hello!!!!!!"); + Runtime.getRuntime().exec("xdg-open " + linuxPath); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + break; + case MAC: + try { + Runtime.getRuntime().exec("open " + macPath); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + break; + + case WINDOWS: + try { + Runtime.getRuntime().exec("explorer " + windowsPath); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + break; + } + } + private static String getFirstKeywordMatch(String s, String keyword) { String[] parts = s.split("="); @@ -396,10 +455,11 @@ private static String getFirstKeywordMatch(String s, String keyword) { private void downloadFile(String url, String path, String fileName) { try { - FileUtils.copyURLToFile(new URL(url), new File(path + fileName)); + FileUtils.copyURLToFile(new URL(url), new File(path + fileName),5000, 5000); } catch (Exception e) { - System.out.println(e.getMessage()); + System.out.println("FILE FAILED TO DOWNLOAD" + e.getMessage()); } + System.out.println("DOWNLOADED: " + url); } private String getDEBFileName(String version) { @@ -434,7 +494,7 @@ private String getLatestVersion() { } private String getDownloadURL(String version, String fileName) { - return String.format("https://github.com/unigrid-project/janus-java/releases/download/v%s/%s", + return String.format(DOWNLOAD_URL.concat("v%s/%s"), version, fileName); } @@ -461,4 +521,14 @@ private int getVersionNumber(String version, int index) { String majorVersion = String.valueOf(c[index]); return Integer.parseInt(majorVersion); } + + private void removeOldInstall(String path) { + File file = new File(path); + if (!file.exists()) { + return; + } + for (File f : file.listFiles()) { + f.delete(); + } + } } diff --git a/fx/src/main/java/org/unigrid/janus/model/Wallet.java b/fx/src/main/java/org/unigrid/janus/model/Wallet.java index 24e2e844..98bd4986 100644 --- a/fx/src/main/java/org/unigrid/janus/model/Wallet.java +++ b/fx/src/main/java/org/unigrid/janus/model/Wallet.java @@ -196,7 +196,7 @@ public int getBlocks() { public void setBlocks(int newValue) { int oldValue = this.blocks; this.blocks = newValue; - System.out.println("setting blocks: " + this.blocks); + //System.out.println("setting blocks: " + this.blocks); this.pcs.firePropertyChange(this.BLOCKS_PROPERTY, oldValue, newValue); } @@ -358,7 +358,7 @@ public int getExplorerHeight() { } } catch (Exception e) { System.out.println(e.getMessage()); - System.out.println(e.getCause().toString()); + //System.out.println(e.getCause().toString()); return 0; } } diff --git a/fx/src/main/java/org/unigrid/janus/model/service/LongPollingTask.java b/fx/src/main/java/org/unigrid/janus/model/service/LongPollingTask.java index 302012c4..2e138e0c 100644 --- a/fx/src/main/java/org/unigrid/janus/model/service/LongPollingTask.java +++ b/fx/src/main/java/org/unigrid/janus/model/service/LongPollingTask.java @@ -16,6 +16,7 @@ of the License (see COPYING and COPYING.addendum). package org.unigrid.janus.model.service; +import jakarta.inject.Inject; import java.util.TimerTask; import javafx.application.Platform; import org.unigrid.janus.model.Wallet; diff --git a/pom.xml b/pom.xml index 62851989..3f39bd13 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.unigrid.janus parent - 1.1.0-SNAPSHOT + 1.0.9-SNAPSHOT pom Unigrid Janus Parent