|
10 | 10 |
|
11 | 11 | package tibetiroka.esmanager.ui; |
12 | 12 |
|
| 13 | +import javafx.animation.KeyFrame; |
| 14 | +import javafx.animation.Timeline; |
13 | 15 | import javafx.application.Application; |
14 | 16 | import javafx.application.Platform; |
15 | 17 | import javafx.collections.ObservableList; |
16 | 18 | import javafx.css.PseudoClass; |
| 19 | +import javafx.event.ActionEvent; |
17 | 20 | import javafx.event.EventHandler; |
18 | 21 | import javafx.fxml.FXMLLoader; |
19 | 22 | import javafx.scene.Node; |
|
29 | 32 | import javafx.scene.input.MouseEvent; |
30 | 33 | import javafx.stage.Modality; |
31 | 34 | import javafx.stage.Stage; |
32 | | -import javafx.stage.WindowEvent; |
| 35 | +import javafx.util.Duration; |
33 | 36 | import org.slf4j.Logger; |
34 | 37 | import org.slf4j.LoggerFactory; |
35 | 38 | import tibetiroka.esmanager.Main; |
@@ -244,25 +247,19 @@ public void start(Stage primaryStage) throws Exception { |
244 | 247 | primaryStage.setMaximized(true); |
245 | 248 | primaryStage.setMinHeight(200); |
246 | 249 | primaryStage.setMinWidth(200); |
247 | | - primaryStage.setOnCloseRequest(new EventHandler<>() { |
248 | | - private final Instant launcherLoaded = Instant.now(); |
249 | | - |
250 | | - @Override |
251 | | - public void handle(WindowEvent event) { |
252 | | - event.consume(); |
253 | | - //prevent exiting if updates are in progress |
254 | | - if(PluginManager.updateInProgressProperty().get()) { |
| 250 | + primaryStage.setOnCloseRequest(event -> { |
| 251 | + event.consume(); |
| 252 | + //prevent exiting if updates are in progress |
| 253 | + if(PluginManager.updateInProgressProperty().get()) { |
| 254 | + return; |
| 255 | + } |
| 256 | + for(Instance instance : Instance.getInstances()) { |
| 257 | + if(instance.getTracker().isWorkingProperty().get()) { |
255 | 258 | return; |
256 | 259 | } |
257 | | - for(Instance instance : Instance.getInstances()) { |
258 | | - if(instance.getTracker().isWorkingProperty().get()) { |
259 | | - return; |
260 | | - } |
261 | | - } |
262 | | - GlobalStatistics.getGlobalStatistics().advanceActiveTimeCounter(Instant.now().toEpochMilli() - launcherLoaded.toEpochMilli()); |
263 | | - AppConfiguration.saveAll(); |
264 | | - primaryStage.close(); |
265 | 260 | } |
| 261 | + AppConfiguration.saveAll(); |
| 262 | + primaryStage.close(); |
266 | 263 | }); |
267 | 264 | MAIN_WINDOW_STYLESHEETS = scene.getRoot().getStylesheets(); |
268 | 265 | STYLE_SHEET_LISTS.add(MAIN_WINDOW_STYLESHEETS); |
@@ -332,6 +329,18 @@ public void handle(WindowEvent event) { |
332 | 329 | } |
333 | 330 | Platform.runLater(() -> MainController.getController().getPluginListBox().setDisable(false)); |
334 | 331 | }, "Plugin Query Thread").start(); |
| 332 | + Timeline timer = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler<>() { |
| 333 | + Instant last = Instant.now(); |
| 334 | + |
| 335 | + @Override |
| 336 | + public void handle(ActionEvent event) { |
| 337 | + Instant now = Instant.now(); |
| 338 | + GlobalStatistics.getGlobalStatistics().advanceActiveTimeCounter(now.toEpochMilli() - last.toEpochMilli()); |
| 339 | + last = now; |
| 340 | + } |
| 341 | + }), new KeyFrame(new Duration(100))); |
| 342 | + timer.setCycleCount(Timeline.INDEFINITE); |
| 343 | + timer.play(); |
335 | 344 | } catch(Exception e) { |
336 | 345 | e.printStackTrace(); |
337 | 346 | throw new Error(e); |
|
0 commit comments