1
1
package cc .cc1234 ;
2
2
3
+ import cc .cc1234 .app .context .HostServiceContext ;
3
4
import cc .cc1234 .app .context .PrimaryStageContext ;
5
+ import cc .cc1234 .app .controller .MainViewController ;
6
+ import cc .cc1234 .app .dialog .Dialog ;
4
7
import cc .cc1234 .app .facade .PrettyZooFacade ;
5
8
import cc .cc1234 .app .util .FXMLs ;
9
+ import cc .cc1234 .version .Version ;
10
+ import cc .cc1234 .version .VersionChecker ;
6
11
import javafx .application .Application ;
7
- import javafx .fxml .FXMLLoader ;
8
12
import javafx .scene .Scene ;
9
13
import javafx .scene .image .Image ;
10
14
import javafx .scene .layout .StackPane ;
@@ -21,7 +25,7 @@ public class PrettyZooApplication extends Application {
21
25
private PrettyZooFacade facade = new PrettyZooFacade ();
22
26
23
27
@ Override
24
- public void start (Stage primaryStage ) throws Exception {
28
+ public void start (Stage primaryStage ) {
25
29
v2 (primaryStage );
26
30
}
27
31
@@ -36,14 +40,23 @@ public static void main(String[] args) {
36
40
Application .launch (args );
37
41
}
38
42
39
- private void v2 (Stage primaryStage ) throws IOException {
43
+ private void v2 (Stage primaryStage ) {
40
44
PrimaryStageContext .set (primaryStage );
41
- final FXMLLoader loader = new FXMLLoader ();
42
- loader .setLocation (FXMLs .loadFXML ("fxml/MainView.fxml" ));
43
- final StackPane anchorPane = loader .load ();
44
- primaryStage .setScene (new Scene (anchorPane ));
45
+ HostServiceContext .set (getHostServices ());
46
+ MainViewController controller = FXMLs .getController ("fxml/MainView.fxml" );
47
+ final StackPane stackPane = controller .getRootStackPane ();
48
+
49
+ primaryStage .setScene (new Scene (stackPane ));
45
50
primaryStage .setTitle ("PrettyZoo" );
46
51
getIconStream ().ifPresent (stream -> primaryStage .getIcons ().add (new Image (stream )));
52
+ primaryStage .setOnShown (e -> {
53
+ VersionChecker .hasNewVersion (latestVersion -> {
54
+ final String content = String .format ("你当前使用的是 %s, 目前最新版本为 %s, 请前往 Github 下载" ,
55
+ Version .VERSION , latestVersion );
56
+ controller .showNewVersionLabel (latestVersion );
57
+ Dialog .confirm ("升级提醒" , content , HostServiceContext ::jumpToReleases );
58
+ });
59
+ });
47
60
primaryStage .show ();
48
61
}
49
62
0 commit comments