Skip to content

Commit 4bfb364

Browse files
Merge pull request #3291 from HenrikJannsen/Show-alert-only-if-not-on-required-version
Improve update version handling
2 parents 970fece + 1c6e167 commit 4bfb364

File tree

12 files changed

+305
-124
lines changed

12 files changed

+305
-124
lines changed

apps/desktop/desktop-app/src/main/java/bisq/desktop_app/DesktopApplicationService.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import bisq.desktop.webcam.WebcamAppService;
3535
import bisq.evolution.updater.UpdaterService;
3636
import bisq.http_api.HttpApiService;
37-
import bisq.http_api.web_socket.domain.OpenTradeItemsService;
3837
import bisq.http_api.rest_api.RestApiService;
3938
import bisq.http_api.web_socket.WebSocketService;
39+
import bisq.http_api.web_socket.domain.OpenTradeItemsService;
4040
import bisq.identity.IdentityService;
4141
import bisq.java_se.application.JavaSeApplicationService;
4242
import bisq.network.NetworkService;
@@ -176,7 +176,10 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)
176176
tradeService = new TradeService(networkService, identityService, persistenceService, offerService,
177177
contractService, supportService, chatService, bondedRolesService, userService, settingsService);
178178

179-
updaterService = new UpdaterService(getConfig(), settingsService, bondedRolesService.getReleaseNotificationsService());
179+
updaterService = new UpdaterService(getConfig(),
180+
settingsService,
181+
bondedRolesService.getReleaseNotificationsService(),
182+
bondedRolesService.getAlertService());
180183

181184
bisqEasyService = new BisqEasyService(persistenceService,
182185
securityService,
@@ -225,7 +228,7 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)
225228
dontShowAgainService,
226229
webcamAppService);
227230

228-
openTradeItemsService = new OpenTradeItemsService( chatService, tradeService, userService);
231+
openTradeItemsService = new OpenTradeItemsService(chatService, tradeService, userService);
229232

230233
var restApiConfig = RestApiService.Config.from(getConfig("restApi"));
231234
var websocketConfig = WebSocketService.Config.from(getConfig("websocket"));

apps/desktop/desktop/src/main/java/bisq/desktop/main/MainController.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import bisq.application.ApplicationService;
2121
import bisq.bisq_easy.NavigationTarget;
22+
import bisq.bonded_roles.release.ReleaseNotification;
2223
import bisq.common.application.ApplicationVersion;
24+
import bisq.common.observable.Observable;
2325
import bisq.common.platform.Version;
2426
import bisq.desktop.ServiceProvider;
2527
import bisq.desktop.common.threading.UIThread;
@@ -91,12 +93,8 @@ public void onActivate() {
9193
}
9294
}
9395

94-
updaterService.getReleaseNotification().addObserver(releaseNotification -> {
95-
if (releaseNotification == null) {
96-
return;
97-
}
98-
UIThread.run(() -> Navigation.navigateTo(NavigationTarget.UPDATER));
99-
});
96+
updaterService.getIsNewReleaseAvailable().addObserver(isNewReleaseAvailable -> UIThread.run(this::maybeShowUpdatePopup));
97+
updaterService.getIgnoreNewRelease().addObserver(isNewReleaseAvailable -> UIThread.run(this::maybeShowUpdatePopup));
10098
}
10199

102100
@Override
@@ -116,4 +114,18 @@ protected Optional<? extends Controller> createController(NavigationTarget navig
116114
public void onStartProcessNavigationTarget(NavigationTarget navigationTarget, Optional<Object> data) {
117115
leftNavController.setNavigationTarget(navigationTarget);
118116
}
117+
118+
private void maybeShowUpdatePopup() {
119+
Boolean isNewReleaseAvailable = updaterService.getIsNewReleaseAvailable().get();
120+
Observable<Boolean> ignoreNewRelease = updaterService.getIgnoreNewRelease();
121+
ReleaseNotification releaseNotification = updaterService.getReleaseNotification().get();
122+
if (isNewReleaseAvailable == null ||
123+
!isNewReleaseAvailable ||
124+
releaseNotification == null ||
125+
ignoreNewRelease == null ||
126+
ignoreNewRelease.get()) {
127+
return;
128+
}
129+
Navigation.navigateTo(NavigationTarget.UPDATER);
130+
}
119131
}

apps/desktop/desktop/src/main/java/bisq/desktop/main/left/LeftNavController.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import bisq.desktop.common.threading.UIThread;
3131
import bisq.desktop.common.view.Controller;
3232
import bisq.desktop.common.view.Navigation;
33+
import bisq.evolution.updater.UpdaterService;
3334
import bisq.settings.CookieKey;
3435
import bisq.settings.SettingsService;
35-
import bisq.evolution.updater.UpdaterService;
3636
import bisq.user.identity.UserIdentity;
3737
import bisq.user.identity.UserIdentityService;
3838
import lombok.Getter;
@@ -53,7 +53,7 @@ public class LeftNavController implements Controller {
5353
private final UpdaterService updaterService;
5454
private final BisqEasyNotificationsService bisqEasyNotificationsService;
5555
private final SettingsService settingsService;
56-
private Pin bondedRolesPin, selectedUserIdentityPin, releaseNotificationPin;
56+
private Pin bondedRolesPin, selectedUserIdentityPin, isNewReleaseAvailablePin;
5757
private Pin changedChatNotificationPin;
5858

5959
public LeftNavController(ServiceProvider serviceProvider) {
@@ -75,8 +75,14 @@ public void onActivate() {
7575
bondedRolesPin = authorizedBondedRolesService.getBondedRoles().addObserver(this::onBondedRolesChanged);
7676
selectedUserIdentityPin = userIdentityService.getSelectedUserIdentityObservable().addObserver(e -> onBondedRolesChanged());
7777

78-
releaseNotificationPin = updaterService.getReleaseNotification().addObserver(releaseNotification ->
79-
UIThread.run(() -> model.getNewVersionAvailable().set(releaseNotification != null)));
78+
isNewReleaseAvailablePin = updaterService.getIsNewReleaseAvailable().addObserver(isNewReleaseAvailable -> {
79+
UIThread.run(() -> {
80+
if (isNewReleaseAvailable == null) {
81+
return;
82+
}
83+
model.getIsNewReleaseAvailable().set(isNewReleaseAvailable && updaterService.getReleaseNotification().get() != null);
84+
});
85+
});
8086

8187
model.getMenuHorizontalExpanded().set(settingsService.getCookie().asBoolean(CookieKey.MENU_HORIZONTAL_EXPANDED).orElse(true));
8288
}
@@ -85,7 +91,7 @@ public void onActivate() {
8591
public void onDeactivate() {
8692
bondedRolesPin.unbind();
8793
selectedUserIdentityPin.unbind();
88-
releaseNotificationPin.unbind();
94+
isNewReleaseAvailablePin.unbind();
8995
changedChatNotificationPin.unbind();
9096
}
9197

apps/desktop/desktop/src/main/java/bisq/desktop/main/left/LeftNavModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LeftNavModel implements Model {
4747
private final ObjectProperty<LeftNavButton> selectedNavigationButton = new SimpleObjectProperty<>();
4848
private final BooleanProperty menuHorizontalExpanded = new SimpleBooleanProperty();
4949
private final BooleanProperty authorizedRoleVisible = new SimpleBooleanProperty(false);
50-
private final BooleanProperty newVersionAvailable = new SimpleBooleanProperty(false);
50+
private final BooleanProperty isNewReleaseAvailable = new SimpleBooleanProperty(false);
5151

5252
public LeftNavModel(boolean isWalletEnabled) {
5353
this.isWalletEnabled = isWalletEnabled;

apps/desktop/desktop/src/main/java/bisq/desktop/main/left/LeftNavView.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected void onViewAttached() {
266266
}
267267
});
268268

269-
newVersionAvailablePin = EasyBind.subscribe(model.getNewVersionAvailable(),
269+
newVersionAvailablePin = EasyBind.subscribe(model.getIsNewReleaseAvailable(),
270270
newVersionAvailable -> {
271271
if (newVersionAvailable) {
272272
version.getStyleClass().remove("bisq-smaller-dimmed-label");

apps/desktop/desktop/src/main/java/bisq/desktop/overlay/update/UpdaterController.java

+87-15
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@
1717

1818
package bisq.desktop.overlay.update;
1919

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;
2025
import bisq.common.observable.Pin;
26+
import bisq.common.observable.collection.CollectionObserver;
2127
import bisq.common.platform.PlatformUtils;
28+
import bisq.common.platform.Version;
2229
import bisq.desktop.ServiceProvider;
2330
import bisq.desktop.common.Browser;
2431
import bisq.desktop.common.observable.FxBindings;
2532
import bisq.desktop.common.threading.UIThread;
2633
import bisq.desktop.common.view.Controller;
2734
import bisq.desktop.components.overlay.Popup;
2835
import bisq.desktop.overlay.OverlayController;
29-
import bisq.i18n.Res;
30-
import bisq.settings.CookieKey;
31-
import bisq.settings.SettingsService;
3236
import bisq.evolution.updater.DownloadItem;
3337
import bisq.evolution.updater.UpdaterService;
3438
import bisq.evolution.updater.UpdaterUtils;
39+
import bisq.i18n.Res;
40+
import bisq.settings.CookieKey;
41+
import bisq.settings.SettingsService;
3542
import lombok.Getter;
3643
import lombok.extern.slf4j.Slf4j;
3744

3845
import java.io.IOException;
46+
import java.util.Optional;
3947
import java.util.concurrent.CancellationException;
4048

4149
import static bisq.evolution.updater.UpdaterUtils.RELEASES_URL;
@@ -48,27 +56,34 @@ public class UpdaterController implements Controller {
4856
private final ServiceProvider serviceProvider;
4957
private final SettingsService settingsService;
5058
private final UpdaterService updaterService;
51-
private Pin getDownloadInfoListPin, releaseNotificationPin;
59+
private final AlertService alertService;
60+
private Pin getDownloadInfoListPin, isNewReleaseAvailablePin, authorizedAlertDataSetPin;
5261

5362
public UpdaterController(ServiceProvider serviceProvider) {
5463
this.serviceProvider = serviceProvider;
5564
settingsService = serviceProvider.getSettingsService();
5665
updaterService = serviceProvider.getUpdaterService();
66+
alertService = serviceProvider.getBondedRolesService().getAlertService();
5767
model = new UpdaterModel();
5868
view = new UpdaterView(model, this);
5969
}
6070

6171
@Override
6272
public void onActivate() {
73+
model.setRequireVersionForTrading(false);
74+
model.setMinRequiredVersionForTrading(Optional.empty());
75+
6376
getDownloadInfoListPin = FxBindings.<DownloadItem, UpdaterView.ListItem>bind(model.getListItems())
6477
.map(UpdaterView.ListItem::new)
6578
.to(updaterService.getDownloadItemList());
6679

67-
releaseNotificationPin = updaterService.getReleaseNotification().addObserver(releaseNotification -> {
68-
if (releaseNotification == null) {
69-
return;
70-
}
80+
isNewReleaseAvailablePin = updaterService.getIsNewReleaseAvailable().addObserver(isNewReleaseAvailable -> {
7181
UIThread.run(() -> {
82+
ReleaseNotification releaseNotification = updaterService.getReleaseNotification().get();
83+
if (isNewReleaseAvailable == null || !isNewReleaseAvailable || releaseNotification == null) {
84+
return;
85+
}
86+
7287
String version = releaseNotification.getVersionString();
7388
model.getVersion().set(version);
7489
model.getReleaseNotes().set(releaseNotification.getReleaseNotes());
@@ -89,20 +104,54 @@ public void onActivate() {
89104
model.getShutDownButtonText().set(isLauncherUpdate ?
90105
Res.get("updater.shutDown.isLauncherUpdate") :
91106
Res.get("updater.shutDown"));
107+
108+
updateIgnoreVersionState();
92109
});
93110
});
94111

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();
95142
model.getFilteredList().setPredicate(e -> !e.getDownloadItem().getDestinationFile().getName().startsWith(UpdaterUtils.FROM_BISQ_WEBPAGE_PREFIX));
96143
}
97144

98145
@Override
99146
public void onDeactivate() {
100147
getDownloadInfoListPin.unbind();
101-
releaseNotificationPin.unbind();
148+
isNewReleaseAvailablePin.unbind();
149+
authorizedAlertDataSetPin.unbind();
102150
}
103151

104152
void onDownload() {
105-
model.getTableVisible().set(true);
153+
model.getDownloadStarted().set(true);
154+
updateIgnoreVersionState();
106155
model.getHeadline().set(Res.get("updater.downloadAndVerify.headline"));
107156
try {
108157
updaterService.downloadAndVerify()
@@ -122,16 +171,20 @@ void onDownloadLater() {
122171
OverlayController.hide();
123172
}
124173

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+
}
128180
}
129181

130182
void onShutdown() {
131-
if (updaterService.getReleaseNotification().get().isLauncherUpdate()) {
183+
ReleaseNotification releaseNotification = updaterService.getReleaseNotification().get();
184+
if (releaseNotification != null && releaseNotification.isLauncherUpdate()) {
132185
PlatformUtils.open(PlatformUtils.getDownloadOfHomeDir());
133186
}
134-
serviceProvider.getShutDownHandler().shutdown();
187+
serviceProvider.getShutDownHandler().shutdown();
135188
}
136189

137190
void onClose() {
@@ -141,4 +194,23 @@ void onClose() {
141194
void onOpenUrl() {
142195
Browser.open(model.getDownloadUrl().get());
143196
}
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+
}
144216
}

apps/desktop/desktop/src/main/java/bisq/desktop/overlay/update/UpdaterModel.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
import javafx.collections.transformation.FilteredList;
2828
import javafx.collections.transformation.SortedList;
2929
import lombok.Getter;
30+
import lombok.Setter;
31+
32+
import java.util.Optional;
3033

3134
@Getter
3235
public class UpdaterModel implements Model {
33-
private final BooleanProperty tableVisible = new SimpleBooleanProperty();
36+
private final BooleanProperty downloadStarted = new SimpleBooleanProperty();
3437
private final BooleanProperty isLauncherUpdate = new SimpleBooleanProperty();
3538
private final BooleanProperty downloadAndVerifyCompleted = new SimpleBooleanProperty();
39+
private final BooleanProperty ignoreVersion = new SimpleBooleanProperty();
40+
private final BooleanProperty ignoreVersionSwitchVisible = new SimpleBooleanProperty();
3641
private final StringProperty headline = new SimpleStringProperty();
3742
private final StringProperty version = new SimpleStringProperty();
3843
private final StringProperty releaseNotes = new SimpleStringProperty();
@@ -44,4 +49,9 @@ public class UpdaterModel implements Model {
4449
private final ObservableList<UpdaterView.ListItem> listItems = FXCollections.observableArrayList();
4550
private final FilteredList<UpdaterView.ListItem> filteredList = new FilteredList<>(listItems);
4651
private final SortedList<UpdaterView.ListItem> sortedList = new SortedList<>(filteredList);
52+
53+
@Setter
54+
private boolean requireVersionForTrading;
55+
@Setter
56+
private Optional<String> minRequiredVersionForTrading = Optional.empty();
4757
}

0 commit comments

Comments
 (0)