1. Add 'check for new versions' feature.
2. Fixed broken (was it broken?) error pop-up window.
This commit is contained in:
Dmitry Isaenko 2019-03-23 20:05:48 +03:00
parent 4c1fc36f9d
commit cc00294b06
15 changed files with 229 additions and 21 deletions

View file

@ -35,8 +35,6 @@ Double-click on downloaded .jar file. Follow instructions. Or see 'Linux' sectio
Set 'Security & Privacy' settings if needed.
If you use different MacOS (not Mojave) - check release section for another JAR file.
##### Windows:
* Download Zadig: [https://zadig.akeo.ie/](https://zadig.akeo.ie/)
@ -104,6 +102,8 @@ usb4java since NS-USBloader-v0.2.3 switched to 1.2.0 instead of 1.3.0. This shou
If you want to see this app translated to your language, go grab [this file](https://github.com/developersu/ns-usbloader/blob/master/src/main/resources/locale.properties) and translate it.
Upload somewhere (pastebin? google drive? whatever else). [Create new issue](https://github.com/developersu/ns-usbloader/issues) and post a link. I'll grab it and add.
NOTE: actually it's not gonna work in real, because we should stay in touch and I'll need you when add something that should be translated =(
#### Thanks for great work done by our translater~~s team~~!
Français by [Stephane Meden (JackFromNice)](https://github.com/JackFromNice)
@ -113,7 +113,7 @@ Français by [Stephane Meden (JackFromNice)](https://github.com/JackFromNice)
- [x] macOS QA v0.1 (Mojave)
- [x] macOS QA v0.2.2 (Mojave)
- [x] macOS QA v0.2.3-DEV (High Sierra)
- [ ] macOS QA v0.3 (Mojave, High Sierra)
- [x] macOS QA v0.3 (all)
- [x] Windows support
- [x] code refactoring
- [x] GoldLeaf support
@ -121,6 +121,8 @@ Français by [Stephane Meden (JackFromNice)](https://github.com/JackFromNice)
- [ ] File order sort (non-critical)
- [ ] More deep file analyze before uploading.
- [x] Network mode support for TinFoil
- [x] 'Check for application updates' functionality
#### Thanks
Appreciate assistance and support of both Vitaliy and Konstantin. Without you all this magic would not have happened.

View file

@ -8,7 +8,7 @@
<name>NS-USBloader</name>
<artifactId>ns-usbloader</artifactId>
<version>0.3-SNAPSHOT</version>
<version>0.3.1-SNAPSHOT</version>
<url>https://github.com/developersu/ns-usbloader/</url>
<description>

View file

@ -22,7 +22,8 @@ public class AppPreferences {
boolean NotServe,
String HostIp,
String HostPort,
String HostExtra
String HostExtra,
boolean autoCheck4Updates
){
setProtocol(Protocol);
setRecent(PreviouslyOpened);
@ -36,6 +37,7 @@ public class AppPreferences {
setHostIp(HostIp);
setHostPort(HostPort);
setHostExtra(HostExtra);
setAutoCheckUpdates(autoCheck4Updates);
}
public String getTheme(){
String theme = preferences.get("THEME", "/res/app_dark.css"); // Don't let user to change settings manually
@ -95,4 +97,7 @@ public class AppPreferences {
public String getHostExtra(){ return preferences.get("HOSTEXTRA", "").replaceAll("(\\s)|(\t)", "");} // oh just shut up...
public void setHostExtra(String postfix){preferences.put("HOSTEXTRA", postfix);}
public boolean getAutoCheckUpdates(){return preferences.getBoolean("AUTOCHECK4UPDATES", false); }
public void setAutoCheckUpdates(boolean prop){preferences.putBoolean("AUTOCHECK4UPDATES", prop); }
}

View file

@ -1,5 +1,6 @@
package nsusbloader.Controllers;
import javafx.application.HostServices;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
@ -11,11 +12,9 @@ import javafx.scene.input.TransferMode;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.stage.FileChooser;
import nsusbloader.AppPreferences;
import nsusbloader.MediatorControl;
import nsusbloader.*;
import nsusbloader.ModelControllers.UpdatesChecker;
import nsusbloader.NET.NETCommunications;
import nsusbloader.NSLMain;
import nsusbloader.ServiceWindow;
import nsusbloader.USB.UsbCommunications;
import java.io.File;
@ -140,7 +139,28 @@ public class NSLMainController implements Initializable {
this.switchThemeBtn.setOnAction(e->switchTheme());
previouslyOpenedPath = AppPreferences.getInstance().getRecent();
if (AppPreferences.getInstance().getAutoCheckUpdates()){
Task<List<String>> updTask = new UpdatesChecker();
updTask.setOnSucceeded(event->{
List<String> result = updTask.getValue();
if (result != null){
if (!result.get(0).isEmpty())
SettingsTabController.setNewVersionLink(result.get(0));
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionAval"), resourceBundle.getString("windowTitleNewVersionAval")+": "+result.get(0) + "\n\n" + result.get(1));
}
else
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionUnknown"), resourceBundle.getString("windowBodyNewVersionUnknown"));
});
Thread updates = new Thread(updTask);
updates.setDaemon(true);
updates.start();
}
}
/**
* Provide hostServices to Settings tab
* */
public void setHostServices(HostServices hs ){ SettingsTabController.registerHostServices(hs);}
/**
* Changes UI theme on the go
* */
@ -329,7 +349,8 @@ public class NSLMainController implements Initializable {
SettingsTabController.getNotServeSelected(),
SettingsTabController.getHostIp(),
SettingsTabController.getHostPort(),
SettingsTabController.getHostExtra()
SettingsTabController.getHostExtra(),
SettingsTabController.getAutoCheckForUpdates()
);
}
}

View file

@ -1,15 +1,18 @@
package nsusbloader.Controllers;
import javafx.application.HostServices;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.*;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import nsusbloader.AppPreferences;
import nsusbloader.ServiceWindow;
import nsusbloader.ModelControllers.UpdatesChecker;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
public class SettingsController implements Initializable {
@ -36,6 +39,15 @@ public class SettingsController implements Initializable {
@FXML
private VBox expertSettingsVBox;
@FXML
private CheckBox autoCheckUpdCb;
@FXML
private Hyperlink newVersionLink;
@FXML
private Button checkForUpdBtn;
private HostServices hs;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
validateNSHostNameCb.setSelected(AppPreferences.getInstance().getNsIpValidationNeeded());
@ -131,6 +143,39 @@ public class SettingsController implements Initializable {
else
return change;
}));
newVersionLink.setVisible(false);
newVersionLink.setOnAction(e->{
hs.showDocument(newVersionLink.getText());
});
autoCheckUpdCb.setSelected(AppPreferences.getInstance().getAutoCheckUpdates());
Region btnSwitchImage = new Region();
btnSwitchImage.getStyleClass().add("regionUpdatesCheck");
checkForUpdBtn.setGraphic(btnSwitchImage);
checkForUpdBtn.setOnAction(e->{
Task<List<String>> updTask = new UpdatesChecker();
updTask.setOnSucceeded(event->{
List<String> result = updTask.getValue();
if (result != null){
if (result.get(0).isEmpty()){
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionNOTAval"), resourceBundle.getString("windowBodyNewVersionNOTAval"));
}
else {
setNewVersionLink(result.get(0));
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionAval"), resourceBundle.getString("windowTitleNewVersionAval")+": "+result.get(0) + "\n\n" + result.get(1));
}
}
else {
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionUnknown"), resourceBundle.getString("windowBodyNewVersionUnknown"));
}
});
Thread updates = new Thread(updTask);
updates.setDaemon(true);
updates.start();
});
}
public boolean getExpertModeSelected(){ return expertModeCb.isSelected(); }
@ -143,4 +188,12 @@ public class SettingsController implements Initializable {
public String getHostIp(){ return pcIpTextField.getText(); }
public String getHostPort(){ return pcPortTextField.getText(); }
public String getHostExtra(){ return pcExtraTextField.getText(); }
public boolean getAutoCheckForUpdates(){ return autoCheckUpdCb.isSelected(); }
public void registerHostServices(HostServices hostServices){this.hs = hostServices;}
public void setNewVersionLink(String newVer){
newVersionLink.setVisible(true);
newVersionLink.setText("https://github.com/developersu/ns-usbloader/releases/tag/"+newVer);
}
}

View file

@ -0,0 +1,63 @@
package nsusbloader.ModelControllers;
import javafx.concurrent.Task;
import nsusbloader.NSLMain;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class UpdatesChecker extends Task<List<String>> {
@Override
protected List<String> call() {
String respondedJson;
try {
URL gitHubUrl = new URL("https://api.github.com/repos/developersu/ns-usbloader/releases/latest");
HttpsURLConnection connection = (HttpsURLConnection) gitHubUrl.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/vnd.github.v3+json");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
int status = connection.getResponseCode();
if (status != 200) {
return null;
}
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
respondedJson = br.readLine();
br.close();
connection.disconnect();
if (respondedJson == null)
return null;
}
catch (IOException mue){
return null;
}
String newVersion = respondedJson.replaceAll("(^.*\"tag_name\":\")(.?|.+?)(\".+$)", "$2");
String changeLog = respondedJson.replaceAll("(^.*\"body\":\")(.?|.+?)(\".+$)", "$2")
.replaceAll("\\\\r\\\\n","\n")
.replaceAll("#+?\\s", ""); // replace #### dsds | # dsds
if (newVersion.matches("^v(([0-9])+?\\.)+[0-9]+(-.+)$")) // if new version have postfix like v0.1-Experimental
newVersion = newVersion.replaceAll("(-.*$)", ""); // cut postfix
if ( ! newVersion.matches("^v(([0-9])+?\\.)+[0-9]+$")) { // check if new version structure valid
return null;
}
List<String> returningValue = new ArrayList<>();
if (!newVersion.equals(NSLMain.appVersion)) { // if latest noted version in GitHub is different to this version
returningValue.add(newVersion);
returningValue.add(changeLog);
return returningValue;
}
returningValue.add("");
returningValue.add("");
return returningValue;
}
}

View file

@ -12,7 +12,7 @@ import java.util.Locale;
import java.util.ResourceBundle;
public class NSLMain extends Application {
public static final String appVersion = "v0.3";
public static final String appVersion = "v0.3.1";
@Override
public void start(Stage primaryStage) throws Exception{
@ -48,6 +48,7 @@ public class NSLMain extends Application {
});
NSLMainController controller = loader.getController();
controller.setHostServices(getHostServices());
primaryStage.setOnHidden(e-> controller.exit());
}

View file

@ -2,24 +2,36 @@ package nsusbloader;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import java.util.Optional;
public class ServiceWindow {
/**
* Create window with notification
* */
/** Create window with error notification */
public static void getErrorNotification(String title, String body){
Alert alertBox = new Alert(Alert.AlertType.ERROR);
getNotification(title, body, Alert.AlertType.ERROR);
}
/** Create window with information notification */
public static void getInfoNotification(String title, String body){
getNotification(title, body, Alert.AlertType.INFORMATION);
}
/** Real window creator */
private static void getNotification(String title, String body, Alert.AlertType type){
Alert alertBox = new Alert(type);
alertBox.setTitle(title);
alertBox.setHeaderText(null);
alertBox.setContentText(body);
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
alertBox.setResizable(false);
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
dialogStage.setAlwaysOnTop(true);
dialogStage.toFront();
alertBox.show();
}
/**

View file

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.SettingsController">
@ -69,6 +72,18 @@
<Insets left="10.0" />
</padding>
</VBox>
<HBox>
<children>
<VBox>
<children>
<CheckBox fx:id="autoCheckUpdCb" mnemonicParsing="false" text="%netTabAutoCheckForUpdates" />
<Hyperlink fx:id="newVersionLink" />
</children>
</VBox>
<Pane HBox.hgrow="ALWAYS" />
<Button fx:id="checkForUpdBtn" mnemonicParsing="false" />
</children>
</HBox>
</children>
<padding>
<Insets left="5.0" right="5.0" top="5.0" />

View file

@ -35,3 +35,9 @@ netTabDontServeRequestsDescription=If selected, this computer won't reply to NSP
netTabHostExtraLbl=extra
windowTitleErrorPort=Port set incorrectly!
windowBodyErrorPort=Port can't be 0 or greater than 65535.
netTabAutoCheckForUpdates=Auto check for updates
windowTitleNewVersionAval=New version available
windowTitleNewVersionNOTAval=No new versions available
windowTitleNewVersionUnknown=Unable to check for new versions
windowBodyNewVersionUnknown=Something went wrong\nMaybe internet unavailable, or GitHub is down
windowBodyNewVersionNOTAval=You're using the latest version

View file

@ -34,4 +34,10 @@ netTabDontServeRequestsDescription=Si cette option est s\u00E9lectionn\u00E9e, c
netTabHostExtraLbl=extra
windowTitleErrorPort=Port mal configur\u00E9!
windowBodyErrorPort=V\u00E9rifiez que le port est sup\u00E9rieur \u00E0 0 et inf\u00E9rieur ou \u00E9gal \u00E0 65535.
netTabAutoCheckForUpdates=V\u00E9rifier automatiquement les mises \u00E0 jour
windowTitleNewVersionAval=Nouvelle version disponible
windowTitleNewVersionNOTAval=Aucune nouvelle version disponible
windowTitleNewVersionUnknown=Impossible de v\u00E9rifier les nouvelles versions
windowBodyNewVersionNOTAval=Vous utilisez la derni\u00E8re version
windowBodyNewVersionUnknown=Une erreur s'est produite\nPeut-\u00EAtre des probl\u00E8mes de connexion Internet ou GitHub est en panne

View file

@ -36,4 +36,10 @@ netTabDontServeRequestsDescription=\u0415\u0441\u043B\u0438 \u0432\u044B\u0431\u
netTabHostExtraLbl=\u044D\u043A\u0441\u0442\u0440\u0430
windowTitleErrorPort=\u041F\u043E\u0440\u0442 \u0443\u043A\u0430\u0437\u0430\u043D \u043D\u0435\u0432\u0435\u0440\u043D\u043E!
windowBodyErrorPort=\u041F\u043E\u0440\u0442 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C 0 \u0438\u043B\u0438 \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0442\u044C 65535.
netTabAutoCheckForUpdates=\u0410\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0442\u044C \u043D\u0430\u043B\u0438\u0447\u0438\u0435 \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0439
windowTitleNewVersionAval=\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u0430 \u043D\u043E\u0432\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F
windowTitleNewVersionNOTAval=\u041D\u0435\u0442 \u043D\u043E\u0432\u044B\u0445 \u0432\u0435\u0440\u0441\u0438\u0439
windowTitleNewVersionUnknown=\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043D\u0430\u043B\u0438\u0447\u0438\u0435 \u043D\u043E\u0432\u044B\u0445 \u0432\u0435\u0440\u0441\u0438\u0439
windowBodyNewVersionNOTAval=\u0412\u044B \u0443\u0436\u0435 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442\u0435 \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u044E\u044E \u0432\u0435\u0440\u0441\u0438\u044E
windowBodyNewVersionUnknown=\u0427\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A.\n\u041C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043D\u0435\u0442 \u0438\u043D\u0442\u0435\u0440\u043D\u0435\u0442\u0430 \u0438\u043B\u0438 GitHub \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D.

View file

@ -35,3 +35,9 @@ netTabDontServeRequestsDescription=\u042F\u043A\u0449\u043E \u0432\u0438\u0431\u
netTabHostExtraLbl=\u0435\u043A\u0441\u0442\u0440\u0430
windowTitleErrorPort=\u041D\u0435\u0432\u0456\u0440\u043D\u043E \u0432\u0438\u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0439 \u043F\u043E\u0440\u0442!
windowBodyErrorPort=\u041F\u043E\u0440\u0442 \u043D\u0435 \u043C\u043E\u0436\u0435 \u0431\u0443\u0442\u0438 0 \u0430\u0431\u043E \u043F\u0440\u0438\u0432\u0438\u0449\u0443\u0432\u0430\u0442\u0438 65535.
netTabAutoCheckForUpdates=\u0410\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u043D\u043E \u043F\u0435\u0440\u0435\u0432\u0456\u0440\u044F\u0442\u0438 \u043D\u0430\u044F\u0432\u043D\u0456\u0441\u0442\u044C \u043E\u043D\u043E\u0432\u043B\u0435\u043D\u044C
windowTitleNewVersionAval=\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u0430 \u043D\u043E\u0432\u0430 \u0432\u0435\u0440\u0441\u0456\u044F
windowTitleNewVersionNOTAval=\u041D\u0435\u043C\u0430\u0454 \u043D\u043E\u0432\u0438\u0445 \u0432\u0435\u0440\u0441\u0456\u0439
windowTitleNewVersionUnknown=\u041D\u0435\u043C\u043E\u0436\u043B\u0438\u0432\u043E \u043F\u0435\u0440\u0435\u0432\u0456\u0440\u0438\u0442\u0438 \u043D\u0430\u044F\u0432\u043D\u0456\u0441\u0442\u044C \u043D\u043E\u0432\u0438\u0445 \u0432\u0435\u0440\u0441\u0456\u0439
windowBodyNewVersionNOTAval=\u0412\u0438 \u0432\u0436\u0435 \u0432\u0438\u043A\u043E\u0440\u0438\u0441\u0442\u043E\u0432\u0443\u0454\u0442\u0435 \u043E\u0441\u0442\u0430\u043D\u043D\u044E \u0432\u0435\u0440\u0441\u0456\u044E
windowBodyNewVersionUnknown=\u0429\u043E\u0441\u044C \u043F\u0456\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A.\n\u041C\u043E\u0436\u043B\u0438\u0432\u043E, \u0456\u043D\u0442\u0435\u0440\u043D\u0435\u0442 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0438\u0439, \u0430\u0431\u043E GitHub \u043D\u0435 \u043F\u0440\u0430\u0446\u044E\u0454.

View file

@ -269,3 +269,9 @@
-fx-min-height: -size;
-fx-min-width: 12.5;
}
.regionUpdatesCheck {
-fx-shape: "M19,8L15,12H18A6,6 0 0,1 12,18C11,18 10.03,17.75 9.2,17.3L7.74,18.76C8.97,19.54 10.43,20 12,20A8,8 0 0,0 20,12H23M6,12A6,6 0 0,1 12,6C13,6 13.97,6.25 14.8,6.7L16.26,5.24C15.03,4.46 13.57,4 12,4A8,8 0 0,0 4,12H1L5,16L9,12";
-fx-background-color: #f7fafa;
-size: 17.5;
-fx-min-width: -size;
}

View file

@ -271,3 +271,9 @@
-fx-min-height: -size;
-fx-min-width: 12.5;
}
.regionUpdatesCheck {
-fx-shape: "M19,8L15,12H18A6,6 0 0,1 12,18C11,18 10.03,17.75 9.2,17.3L7.74,18.76C8.97,19.54 10.43,20 12,20A8,8 0 0,0 20,12H23M6,12A6,6 0 0,1 12,6C13,6 13.97,6.25 14.8,6.7L16.26,5.24C15.03,4.46 13.57,4 12,4A8,8 0 0,0 4,12H1L5,16L9,12";
-fx-background-color: #2c2c2c;
-size: 17.5;
-fx-min-width: -size;
}