Skip to content

Commit 10a18f8

Browse files
committed
implemented autochecking new versions of the editor.
1 parent b5e67b7 commit 10a18f8

File tree

9 files changed

+127
-6
lines changed

9 files changed

+127
-6
lines changed

app.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.6
1+
v.0.9.6

build-native.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project name="jME SpaceShift Editor" default="do-deploy" basedir="build"
33
xmlns:fx="javafx:com.sun.javafx.tools.ant">
44

5-
<property name="editor.version" value="0.9.5" />
5+
<property name="editor.version" value="0.9.6" />
66

77
<target name="init-fx-tasks">
88
<path id="fxant">

resources/messages/messages.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,8 @@ ModelConverterDialogMaterialsFolder=Folder to store materials
541541
ModelConverterDialogOverwriteMaterials=Overwrite materials
542542
ModelConverterDialogButtonOk=Convert
543543
544-
FileDeleteHandlerDeleteMaterials=Do you want to remove all materials which used from %file_name%?
544+
FileDeleteHandlerDeleteMaterials=Do you want to remove all materials which used from %file_name%?
545+
546+
CheckNewVersionDialogTitle=Information
547+
CheckNewVersionDialogHyperText=You can download the new version from:
548+
CheckNewVersionDialogHeaderText=Available the new version:

resources/messages/messages_de.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,8 @@ ModelConverterDialogMaterialsFolder=Materialien Ablageverzeichnis
541541
ModelConverterDialogOverwriteMaterials=Materialien Überschreiben
542542
ModelConverterDialogButtonOk=Konvertieren
543543

544-
FileDeleteHandlerDeleteMaterials=Wollen Sie alle von Model %file_name% benutzten Materialien entfernen?
544+
FileDeleteHandlerDeleteMaterials=Wollen Sie alle von Model %file_name% benutzten Materialien entfernen?
545+
546+
CheckNewVersionDialogTitle=Informationen
547+
CheckNewVersionDialogHyperText=Sie können die neue version aus:
548+
CheckNewVersionDialogHeaderText=Verfügbar ist die neue version:

resources/messages/messages_ru.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,8 @@ ModelConverterDialogMaterialsFolder=Папка для сохр. материал
541541
ModelConverterDialogOverwriteMaterials=Перезаписывать ли материалы
542542
ModelConverterDialogButtonOk=Конвертировать
543543
544-
FileDeleteHandlerDeleteMaterials=Хотите ли вы удалить все материалы которые использовались моделью %file_name%?
544+
FileDeleteHandlerDeleteMaterials=Хотите ли вы удалить все материалы которые использовались моделью %file_name%?
545+
546+
CheckNewVersionDialogTitle=Информация
547+
CheckNewVersionDialogHyperText=Вы можете скачать новую версию по ссылке:
548+
CheckNewVersionDialogHeaderText=Доступна новая версия:

src/com/ss/editor/JFXApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import com.ss.editor.config.Config;
1414
import com.ss.editor.config.EditorConfig;
1515
import com.ss.editor.executor.impl.EditorThreadExecutor;
16+
import com.ss.editor.manager.ExecutorManager;
1617
import com.ss.editor.manager.JMEFilePreviewManager;
18+
import com.ss.editor.task.CheckNewVersionTask;
1719
import com.ss.editor.ui.builder.EditorFXSceneBuilder;
1820
import com.ss.editor.ui.component.log.LogView;
1921
import com.ss.editor.ui.dialog.ConfirmDialog;
@@ -213,6 +215,9 @@ private void buildScene() {
213215
GAnalytics.sendEvent(GAEvent.Category.APPLICATION,
214216
GAEvent.Action.LAUNCHED, GAEvent.Label.THE_EDITOR_APP_WAS_LAUNCHED);
215217

218+
final ExecutorManager executorManager = ExecutorManager.getInstance();
219+
executorManager.addBackgroundTask(new CheckNewVersionTask());
220+
216221
final EditorConfig editorConfig = EditorConfig.getInstance();
217222
if (editorConfig.isAnalyticsQuestion()) return;
218223

src/com/ss/editor/Messages.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ public class Messages {
564564

565565
public static final String FILE_DELETE_HANDLER_DELETE_MATERIALS;
566566

567+
public static final String CHECK_NEW_VERSION_DIALOG_TITLE;
568+
public static final String CHECK_NEW_VERSION_DIALOG_HYPERLINK;
569+
public static final String CHECK_NEW_VERSION_DIALOG_HEADER_TEXT;
570+
567571
static {
568572

569573
final Locale locale = Locale.getDefault();
@@ -1129,5 +1133,9 @@ public class Messages {
11291133
MODEL_CONVERTER_DIALOG_BUTTON_OK = bundle.getString("ModelConverterDialogButtonOk");
11301134

11311135
FILE_DELETE_HANDLER_DELETE_MATERIALS = bundle.getString("FileDeleteHandlerDeleteMaterials");
1136+
1137+
CHECK_NEW_VERSION_DIALOG_TITLE = bundle.getString("CheckNewVersionDialogTitle");
1138+
CHECK_NEW_VERSION_DIALOG_HYPERLINK = bundle.getString("CheckNewVersionDialogHyperText");
1139+
CHECK_NEW_VERSION_DIALOG_HEADER_TEXT = bundle.getString("CheckNewVersionDialogHeaderText");
11321140
}
11331141
}

src/com/ss/editor/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class Config {
2222
private static final String CONFIG_RESOURCE_PATH = "/com/ss/editor/config/config.xml";
2323

2424
public static final String TITLE = "jME3 SpaceShift Editor";
25-
public static final String VERSION = "v.0.9.5";
25+
public static final String VERSION = "v.0.9.6";
2626

2727
private static final String SS_FOLDER_IN_USER_HOME = ".jme3-spaceshift-editor";
2828

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.ss.editor.task;
2+
3+
import static org.apache.http.impl.client.HttpClients.createMinimal;
4+
import com.ss.editor.JFXApplication;
5+
import com.ss.editor.Messages;
6+
import com.ss.editor.config.Config;
7+
import javafx.application.HostServices;
8+
import javafx.application.Platform;
9+
import javafx.scene.control.Alert;
10+
import javafx.scene.control.DialogPane;
11+
import javafx.scene.control.Hyperlink;
12+
import org.apache.commons.io.IOUtils;
13+
import org.apache.http.Header;
14+
import org.apache.http.HttpEntity;
15+
import org.apache.http.StatusLine;
16+
import org.apache.http.client.methods.CloseableHttpResponse;
17+
import org.apache.http.client.methods.HttpGet;
18+
import org.apache.http.impl.client.CloseableHttpClient;
19+
import rlib.logging.Logger;
20+
import rlib.logging.LoggerManager;
21+
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
25+
/**
26+
* The task to check new versions of the Editor.
27+
*
28+
* @author JavaSaBr
29+
*/
30+
public class CheckNewVersionTask implements Runnable {
31+
32+
private static final Logger LOGGER = LoggerManager.getLogger(CheckNewVersionTask.class);
33+
34+
private static final String APP_VERSION_URL = "https://api.bitbucket.org/1.0/repositories/javasabr/jme3-spaceshift-editor/raw/master/app.version";
35+
private static final String DOWNLOAD_APP_PATH_URL = "https://api.bitbucket.org/1.0/repositories/javasabr/jme3-spaceshift-editor/raw/master/download.app.path";
36+
37+
@Override
38+
public void run() {
39+
40+
try (final CloseableHttpClient httpClient = createMinimal()) {
41+
42+
CloseableHttpResponse response = httpClient.execute(new HttpGet(APP_VERSION_URL));
43+
StatusLine statusLine = response.getStatusLine();
44+
45+
if (statusLine.getStatusCode() != 200) {
46+
return;
47+
}
48+
49+
HttpEntity entity = response.getEntity();
50+
InputStream content = entity.getContent();
51+
Header encoding = entity.getContentEncoding();
52+
String enc = encoding == null ? "UTF-8" : encoding.getValue();
53+
54+
final String targetVersion = IOUtils.toString(content, enc).trim();
55+
56+
if (Config.VERSION.equals(targetVersion)) {
57+
return;
58+
}
59+
60+
response = httpClient.execute(new HttpGet(DOWNLOAD_APP_PATH_URL));
61+
statusLine = response.getStatusLine();
62+
63+
if (statusLine.getStatusCode() != 200) {
64+
return;
65+
}
66+
67+
entity = response.getEntity();
68+
content = entity.getContent();
69+
encoding = entity.getContentEncoding();
70+
enc = encoding == null ? "UTF-8" : encoding.getValue();
71+
72+
final String targetLink = IOUtils.toString(content, enc).trim();
73+
74+
Platform.runLater(() -> {
75+
76+
final JFXApplication jfxApplication = JFXApplication.getInstance();
77+
final HostServices hostServices = jfxApplication.getHostServices();
78+
79+
final Hyperlink hyperlink = new Hyperlink(Messages.CHECK_NEW_VERSION_DIALOG_HYPERLINK + targetLink);
80+
hyperlink.setOnAction(event -> hostServices.showDocument(targetLink));
81+
82+
final Alert alert = new Alert(Alert.AlertType.INFORMATION);
83+
alert.setTitle(Messages.CHECK_NEW_VERSION_DIALOG_TITLE);
84+
alert.setHeaderText(Messages.CHECK_NEW_VERSION_DIALOG_HEADER_TEXT + targetVersion);
85+
86+
final DialogPane dialogPane = alert.getDialogPane();
87+
dialogPane.setContent(hyperlink);
88+
89+
alert.show();
90+
});
91+
92+
} catch (final IOException e) {
93+
LOGGER.warning(e);
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)