Skip to content

Commit

Permalink
Eg bootstrap update (#123)
Browse files Browse the repository at this point in the history
* Bootstrap: pass proj.ver to javafx.

* bootstrap: set version to match fx

* MS: added remove temp file when a new one has been found
!

* updater: fixed issues with fx not starting based on older bootstraps. Resolved handling boostrap version passed in via bootstrap.

* MS: Change launcher update message to make it clearer. added a boolean to bootstrap model that is used to determin if its an bootstrap update that is happening. Using this boolean to force an bootstrap update on exit click if its avilable.

* added a download URL to test bootstrap update.

* force windows app to close once the bootstrap installer opens

* close app on exec and dont wait for it

* catch explorer blocking users IP address

* disable FXTrayIcon from pom for now as bootstrap needs swing for this to work

* MS: added a dialog that tells the user when the install faild and opens the temp folder.

Co-authored-by: Fim-84 <[email protected]>
  • Loading branch information
dekm and Fim-84 authored Sep 27, 2022
1 parent 4729a19 commit 691cb5f
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 53 deletions.
2 changes: 1 addition & 1 deletion bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.unigrid.janus</groupId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>
</parent>
<groupId>org.unigrid</groupId>
<artifactId>bootstrap</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/src/main/java/org/unigrid/bootstrap/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}
Expand Down
17 changes: 15 additions & 2 deletions bootstrap/src/main/java/org/unigrid/bootstrap/UpdateView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -98,11 +98,24 @@ public Stage getStage() {
public void setConfig(Configuration config, Stage primaryStage, Map<String, String> 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<String, String> inputArgs = input;
@InjectSource
HostServices hostService = hostServices;
@InjectSource
String bootstrapVer = bootstrapVersion;
};

System.out.println(input.get("URL"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proj.ver=${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")) {
Expand All @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions desktop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.unigrid.janus</groupId>
<artifactId>parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>
</parent>
<properties>
<mainClass>org.unigrid.janus.Janus</mainClass>
Expand Down Expand Up @@ -99,7 +99,7 @@
<goal>jpackage</goal>
</goals>
<configuration>
<appVersion>1.1.0</appVersion>
<appVersion>1.0.9</appVersion>
<vendor>org.unigrid</vendor>
<module>org.unigrid.bootstrap/org.unigrid.bootstrap.App</module>
<modulePaths>
Expand All @@ -122,7 +122,7 @@
<goal>jpackage</goal>
</goals>
<configuration>
<appVersion>1.1.0</appVersion>
<appVersion>1.0.9</appVersion>
<appImage>target/dist/Unigrid</appImage>
</configuration>
</execution>
Expand Down
6 changes: 3 additions & 3 deletions fx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.unigrid.janus</groupId>
<artifactId>parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>
</parent>
<properties>
<mainClass>org.unigrid.janus.Janus</mainClass>
Expand Down Expand Up @@ -213,11 +213,11 @@
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha7</version>
</dependency>
<dependency>
<!--<dependency>
<groupId>com.dustinredmond.fxtrayicon</groupId>
<artifactId>FXTrayIcon</artifactId>
<version>3.3.0</version>
</dependency>
</dependency>-->
</dependencies>
<build>
<plugins>
Expand Down
2 changes: 2 additions & 0 deletions fx/src/main/java/org/unigrid/janus/Janus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
27 changes: 25 additions & 2 deletions fx/src/main/java/org/unigrid/janus/JanusLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,9 +38,16 @@ public class JanusLauncher implements Launcher {
@InjectTarget
private Map<String, String> inputArgs = new HashMap<String, String>();

@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");
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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"));
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions fx/src/main/java/org/unigrid/janus/model/BootstrapModel.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/> and <https://github.com/unigrid-project/janus-java>.
*/

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;
}
}
1 change: 1 addition & 0 deletions fx/src/main/java/org/unigrid/janus/model/UpdateURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public class UpdateURL {

@Getter @Setter
private static String bootstrapUrl = "https://github.com/unigrid-project/janus-java/releases.atom";

}
Loading

0 comments on commit 691cb5f

Please sign in to comment.