1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package Launchers;
21
22 import Controllers.MainController;
23 import Utilities.LogToFile;
24 import Utilities.Severity;
25 import com.mchange.v2.log.slf4j.Slf4jMLog;
26 import javafx.application.Application;
27 import javafx.fxml.FXML;
28 import javafx.fxml.FXMLLoader;
29 import javafx.scene.Parent;
30 import javafx.scene.Scene;
31 import javafx.scene.control.Alert;
32 import javafx.scene.control.ButtonBar;
33 import javafx.scene.control.ButtonType;
34 import javafx.scene.control.TreeView;
35 import javafx.stage.Stage;
36 import javafx.stage.StageStyle;
37
38 import java.awt.*;
39 import java.io.BufferedReader;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.io.InputStreamReader;
43 import java.net.URI;
44 import java.net.URISyntaxException;
45 import java.net.URL;
46 import java.net.URLConnection;
47 import java.util.Objects;
48 import java.util.Optional;
49 import java.util.Properties;
50
51
52
53
54 public class Main extends Application {
55 @FXML
56 private TreeView<String> selectNav;
57
58
59 public static void main(String[] args) { launch(args); }
60
61 public Boolean checkUpdates() {
62
63 try {
64 URL url = new URL("https://abos-software.gitlab.io/version-2.html");
65
66
67 URLConnection con = url.openConnection();
68 InputStream is = con.getInputStream();
69
70
71
72
73
74
75
76
77
78
79 BufferedReader br = new BufferedReader(new InputStreamReader(is));
80
81 String line;
82 final Properties properties = new Properties();
83 properties.load(this.getClass().getResourceAsStream("/CompileProps.properties"));
84
85 while ((line = br.readLine()) != null) {
86 if (!Objects.equals(properties.getProperty("Version"), line)) {
87 return true;
88 }
89 }
90 } catch (IOException e) {
91 LogToFile.log(e, Severity.WARNING, "Error checking for updates. If error persists, reinstall and contact developer.");
92 }
93
94
95 return false;
96 }
97
98 @Override
99 public void start(final Stage stage) throws Exception {
100
101
102
103 Slf4jMLog.config("");
104 final FXMLLoader loader = new FXMLLoader(getClass().getResource("/UI/Main.fxml"));
105 final Parent root = loader.load();
106 final MainController controller = loader.getController();
107 if (checkUpdates()) {
108 Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
109 alert.setTitle("Update Available");
110 alert.setHeaderText("An Update is Available");
111 alert.setContentText("If you choose to download, download the latest tag's java Artifacts");
112
113 ButtonType buttonTypeOne = new ButtonType("Download");
114 ButtonType buttonTypeTwo = new ButtonType("Remind Me Later", ButtonBar.ButtonData.CANCEL_CLOSE);
115
116 alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo);
117
118 Optional<ButtonType> result = alert.showAndWait();
119 if (result.get() == buttonTypeOne) {
120 if (Desktop.isDesktopSupported()) {
121 new Thread(() -> {
122 try {
123 Desktop.getDesktop().browse(new URI("https://abos-software.gitlab.io/download/"));
124
125 } catch (URISyntaxException | IOException e) {
126 LogToFile.log(e, Severity.WARNING, "Error opening download window. Please try navigating to https://gitlab.com/RoatingFans/ABOS/tags");
127 }
128 }).start();
129
130 }
131 }
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 stage.setScene(new Scene(root));
154 stage.getScene().getStylesheets().add("UI/Main.css");
155 stage.initStyle(StageStyle.UNIFIED);
156 stage.setMinWidth(700);
157 stage.setMinHeight(600);
158 stage.setOnCloseRequest(windowEvent -> {
159 if (windowEvent.getSource() != stage.getOwner()) {
160 stage.close();
161 } else {
162 windowEvent.consume();
163 }
164 });
165 stage.setMaximized(true);
166 Stage masterStage = stage;
167
168 controller.initialize(stage, getParameters());
169
170 stage.show();
171 }
172
173 private void updateSelectedItem(Object newValue) {
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 }