16
16
17
17
package com .google .classyshark .updater ;
18
18
19
- import com .google .classyshark .updater .models .Release ;
20
- import com .google .classyshark .updater .networking .AbstractReleaseCallback ;
21
- import com .google .classyshark .updater .networking .MessageRunnable ;
22
- import com .google .classyshark .updater .networking .NetworkManager ;
23
- import com .google .classyshark .updater .utils .FileUtils ;
24
- import retrofit2 .Call ;
25
-
26
- import javax .swing .*;
27
- import java .io .IOException ;
28
-
19
+ import com .google .classyshark .updater .networking .AbstractDownloader ;
20
+ import com .google .classyshark .updater .networking .CliDownloader ;
21
+ import com .google .classyshark .updater .networking .GuiDownloader ;
29
22
30
23
/**
31
24
* This class is the core point for the update process: based on the response
35
28
*/
36
29
public class UpdateManager {
37
30
private static final UpdateManager instance = new UpdateManager ();
38
- private final AbstractReleaseCallback releaseCallback ;
39
- private final Release currentRelease = new Release ();
40
- private boolean isGui = false ;
41
31
42
32
private UpdateManager () {
43
- releaseCallback = new AbstractReleaseCallback () {
44
- @ Override
45
- public void onReleaseReceived (Release release ) {
46
- onReleaseResponse (release );
47
- }
48
- };
33
+
49
34
}
50
35
51
36
public static UpdateManager getInstance () {
@@ -61,29 +46,14 @@ public void checkVersionGui() {
61
46
}
62
47
63
48
private void checkVersion (boolean isGui ) {
64
- this .isGui = isGui ;
65
- Call <Release > call = NetworkManager .getGitHubApi ().getLatestRelease ();
66
- call .enqueue (releaseCallback );
67
- }
68
-
69
- private void onReleaseResponse (final Release release ) {
70
- if (release .isNewerThan (currentRelease )) {
71
- new Thread (new Runnable () {
72
- @ Override
73
- public void run () {
74
- obtainNew (release );
75
- SwingUtilities .invokeLater (new MessageRunnable (release .getReleaseName (), release .getChangelog (), isGui ));
76
- }
77
- }).start ();
78
-
79
- }
49
+ getDownloaderFrom (isGui ).checkNewVersion ();
80
50
}
81
51
82
- private void obtainNew ( Release release ) {
83
- try {
84
- FileUtils . downloadFileFrom ( release );
85
- } catch ( IOException e ) {
86
- System . err . println ( "ERROR: " + e . getMessage () );
52
+ private AbstractDownloader getDownloaderFrom ( boolean isGui ) {
53
+ if ( isGui ) {
54
+ return GuiDownloader . getInstance ( );
55
+ } else {
56
+ return CliDownloader . getInstance ( );
87
57
}
88
58
}
89
59
}
0 commit comments