17
17
18
18
package bisq .desktop .overlay .update ;
19
19
20
+ import bisq .bonded_roles .release .ReleaseNotification ;
21
+ import bisq .bonded_roles .security_manager .alert .AlertService ;
22
+ import bisq .bonded_roles .security_manager .alert .AlertType ;
23
+ import bisq .bonded_roles .security_manager .alert .AuthorizedAlertData ;
24
+ import bisq .common .application .ApplicationVersion ;
20
25
import bisq .common .observable .Pin ;
26
+ import bisq .common .observable .collection .CollectionObserver ;
21
27
import bisq .common .platform .PlatformUtils ;
28
+ import bisq .common .platform .Version ;
22
29
import bisq .desktop .ServiceProvider ;
23
30
import bisq .desktop .common .Browser ;
24
31
import bisq .desktop .common .observable .FxBindings ;
25
32
import bisq .desktop .common .threading .UIThread ;
26
33
import bisq .desktop .common .view .Controller ;
27
34
import bisq .desktop .components .overlay .Popup ;
28
35
import bisq .desktop .overlay .OverlayController ;
29
- import bisq .i18n .Res ;
30
- import bisq .settings .CookieKey ;
31
- import bisq .settings .SettingsService ;
32
36
import bisq .evolution .updater .DownloadItem ;
33
37
import bisq .evolution .updater .UpdaterService ;
34
38
import bisq .evolution .updater .UpdaterUtils ;
39
+ import bisq .i18n .Res ;
40
+ import bisq .settings .CookieKey ;
41
+ import bisq .settings .SettingsService ;
35
42
import lombok .Getter ;
36
43
import lombok .extern .slf4j .Slf4j ;
37
44
38
45
import java .io .IOException ;
46
+ import java .util .Optional ;
39
47
import java .util .concurrent .CancellationException ;
40
48
41
49
import static bisq .evolution .updater .UpdaterUtils .RELEASES_URL ;
@@ -48,27 +56,34 @@ public class UpdaterController implements Controller {
48
56
private final ServiceProvider serviceProvider ;
49
57
private final SettingsService settingsService ;
50
58
private final UpdaterService updaterService ;
51
- private Pin getDownloadInfoListPin , releaseNotificationPin ;
59
+ private final AlertService alertService ;
60
+ private Pin getDownloadInfoListPin , isNewReleaseAvailablePin , authorizedAlertDataSetPin ;
52
61
53
62
public UpdaterController (ServiceProvider serviceProvider ) {
54
63
this .serviceProvider = serviceProvider ;
55
64
settingsService = serviceProvider .getSettingsService ();
56
65
updaterService = serviceProvider .getUpdaterService ();
66
+ alertService = serviceProvider .getBondedRolesService ().getAlertService ();
57
67
model = new UpdaterModel ();
58
68
view = new UpdaterView (model , this );
59
69
}
60
70
61
71
@ Override
62
72
public void onActivate () {
73
+ model .setRequireVersionForTrading (false );
74
+ model .setMinRequiredVersionForTrading (Optional .empty ());
75
+
63
76
getDownloadInfoListPin = FxBindings .<DownloadItem , UpdaterView .ListItem >bind (model .getListItems ())
64
77
.map (UpdaterView .ListItem ::new )
65
78
.to (updaterService .getDownloadItemList ());
66
79
67
- releaseNotificationPin = updaterService .getReleaseNotification ().addObserver (releaseNotification -> {
68
- if (releaseNotification == null ) {
69
- return ;
70
- }
80
+ isNewReleaseAvailablePin = updaterService .getIsNewReleaseAvailable ().addObserver (isNewReleaseAvailable -> {
71
81
UIThread .run (() -> {
82
+ ReleaseNotification releaseNotification = updaterService .getReleaseNotification ().get ();
83
+ if (isNewReleaseAvailable == null || !isNewReleaseAvailable || releaseNotification == null ) {
84
+ return ;
85
+ }
86
+
72
87
String version = releaseNotification .getVersionString ();
73
88
model .getVersion ().set (version );
74
89
model .getReleaseNotes ().set (releaseNotification .getReleaseNotes ());
@@ -89,20 +104,54 @@ public void onActivate() {
89
104
model .getShutDownButtonText ().set (isLauncherUpdate ?
90
105
Res .get ("updater.shutDown.isLauncherUpdate" ) :
91
106
Res .get ("updater.shutDown" ));
107
+
108
+ updateIgnoreVersionState ();
92
109
});
93
110
});
94
111
112
+ authorizedAlertDataSetPin = alertService .getAuthorizedAlertDataSet ().addObserver (new CollectionObserver <>() {
113
+ @ Override
114
+ public void add (AuthorizedAlertData authorizedAlertData ) {
115
+ if (authorizedAlertData .getAlertType () == AlertType .EMERGENCY && authorizedAlertData .isRequireVersionForTrading ()) {
116
+ model .setRequireVersionForTrading (true );
117
+ model .setMinRequiredVersionForTrading (authorizedAlertData .getMinVersion ());
118
+ updateIgnoreVersionState ();
119
+ }
120
+ }
121
+
122
+ @ Override
123
+ public void remove (Object element ) {
124
+ if (element instanceof AuthorizedAlertData authorizedAlertData ) {
125
+ if (authorizedAlertData .getAlertType () == AlertType .EMERGENCY && authorizedAlertData .isRequireVersionForTrading ()) {
126
+ model .setRequireVersionForTrading (false );
127
+ model .setMinRequiredVersionForTrading (Optional .empty ());
128
+ updateIgnoreVersionState ();
129
+ }
130
+ }
131
+ }
132
+
133
+ @ Override
134
+ public void clear () {
135
+ model .setRequireVersionForTrading (false );
136
+ model .setMinRequiredVersionForTrading (Optional .empty ());
137
+ updateIgnoreVersionState ();
138
+ }
139
+ });
140
+
141
+ updateIgnoreVersionState ();
95
142
model .getFilteredList ().setPredicate (e -> !e .getDownloadItem ().getDestinationFile ().getName ().startsWith (UpdaterUtils .FROM_BISQ_WEBPAGE_PREFIX ));
96
143
}
97
144
98
145
@ Override
99
146
public void onDeactivate () {
100
147
getDownloadInfoListPin .unbind ();
101
- releaseNotificationPin .unbind ();
148
+ isNewReleaseAvailablePin .unbind ();
149
+ authorizedAlertDataSetPin .unbind ();
102
150
}
103
151
104
152
void onDownload () {
105
- model .getTableVisible ().set (true );
153
+ model .getDownloadStarted ().set (true );
154
+ updateIgnoreVersionState ();
106
155
model .getHeadline ().set (Res .get ("updater.downloadAndVerify.headline" ));
107
156
try {
108
157
updaterService .downloadAndVerify ()
@@ -122,16 +171,20 @@ void onDownloadLater() {
122
171
OverlayController .hide ();
123
172
}
124
173
125
- void onIgnore () {
126
- settingsService .setCookie (CookieKey .IGNORE_VERSION , model .getVersion ().get (), true );
127
- OverlayController .hide ();
174
+ void onIgnoreVersionSelected (boolean selected ) {
175
+ settingsService .setCookie (CookieKey .IGNORE_VERSION , model .getVersion ().get (), selected );
176
+ updateIgnoreVersionState ();
177
+ if (selected ) {
178
+ OverlayController .hide ();
179
+ }
128
180
}
129
181
130
182
void onShutdown () {
131
- if (updaterService .getReleaseNotification ().get ().isLauncherUpdate ()) {
183
+ ReleaseNotification releaseNotification = updaterService .getReleaseNotification ().get ();
184
+ if (releaseNotification != null && releaseNotification .isLauncherUpdate ()) {
132
185
PlatformUtils .open (PlatformUtils .getDownloadOfHomeDir ());
133
186
}
134
- serviceProvider .getShutDownHandler ().shutdown ();
187
+ serviceProvider .getShutDownHandler ().shutdown ();
135
188
}
136
189
137
190
void onClose () {
@@ -141,4 +194,23 @@ void onClose() {
141
194
void onOpenUrl () {
142
195
Browser .open (model .getDownloadUrl ().get ());
143
196
}
197
+
198
+ private boolean isRequireVersionForTradingAboveAppVersion () {
199
+ Optional <String > minRequiredVersionForTrading = model .getMinRequiredVersionForTrading ();
200
+ return model .isRequireVersionForTrading () &&
201
+ minRequiredVersionForTrading .isPresent () &&
202
+ new Version (minRequiredVersionForTrading .get ()).above (ApplicationVersion .getVersion ());
203
+ }
204
+
205
+ private void updateIgnoreVersionState () {
206
+ boolean requireVersionForTradingAboveAppVersion = isRequireVersionForTradingAboveAppVersion ();
207
+ model .getIgnoreVersion ().set (getIgnoreVersionFromCookie () &&
208
+ !model .getDownloadStarted ().get () && !requireVersionForTradingAboveAppVersion );
209
+
210
+ model .getIgnoreVersionSwitchVisible ().set (!requireVersionForTradingAboveAppVersion );
211
+ }
212
+
213
+ private Boolean getIgnoreVersionFromCookie () {
214
+ return settingsService .getCookie ().asBoolean (CookieKey .IGNORE_VERSION , model .getVersion ().get ()).orElse (false );
215
+ }
144
216
}
0 commit comments