Reset Selected Resolution if model offline (credit @Gabi_uy)
This commit is contained in:
parent
180bfe72c2
commit
0f8ff720b7
|
@ -38,30 +38,72 @@ public class SwitchStreamResolutionAction {
|
|||
var couldntSwitchHeaderText = "Couldn't switch stream resolution";
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
checkOnlineState();
|
||||
return selectedModel;
|
||||
return Boolean.TRUE; // model is online
|
||||
} catch (ModelOfflineException e) {
|
||||
return Boolean.FALSE; // model is offline
|
||||
}
|
||||
}, GlobalThreadPool.get())
|
||||
.thenAccept(m -> Platform.runLater(() -> {
|
||||
StreamSourceSelectionDialog dialog = new StreamSourceSelectionDialog(source.getScene(), selectedModel);
|
||||
.thenAccept(isOnline -> Platform.runLater(() -> {
|
||||
if (isOnline) {
|
||||
// --- model is online: open selection dialog ---
|
||||
StreamSourceSelectionDialog dialog =
|
||||
new StreamSourceSelectionDialog(source.getScene(), selectedModel);
|
||||
Optional<StreamSource> selectedSource = dialog.showAndWait();
|
||||
if (selectedSource.isPresent()) {
|
||||
StreamSource src = selectedSource.get();
|
||||
if (src != StreamSourceSelectionDialog.LOADING) {
|
||||
int index = dialog.indexOf(selectedSource.get());
|
||||
int index = dialog.indexOf(src);
|
||||
selectedModel.setStreamUrlIndex(index);
|
||||
try {
|
||||
recorder.switchStreamSource(selectedModel);
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) {
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException |
|
||||
IllegalStateException | IOException e) {
|
||||
log.error(couldntSwitchHeaderText, e);
|
||||
Dialogs.showError(source.getScene(), "Couldn't switch stream resolution", "Error while switching stream resolution", e);
|
||||
Dialogs.showError(source.getScene(), couldntSwitchHeaderText,
|
||||
"Error while switching stream resolution", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// --- model is offline: ask if user wants to reset ---
|
||||
boolean confirmed = Dialogs.showConfirmDialog(
|
||||
"Model is offline",
|
||||
"Yes to reset to Default (Best resolution),\nNo to leave existing resolution unchanged.",
|
||||
"",
|
||||
source.getScene()
|
||||
);
|
||||
if (confirmed) {
|
||||
selectedModel.setStreamUrlIndex(-1);
|
||||
try {
|
||||
recorder.switchStreamSource(selectedModel); // persist the change
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException |
|
||||
IllegalStateException | IOException e) {
|
||||
log.error("Couldn't update recorder with reset stream index", e);
|
||||
Dialogs.showError(source.getScene(),
|
||||
"Couldn't reset stream resolution",
|
||||
"Error while updating stream resolution", e);
|
||||
}
|
||||
|
||||
// show confirmation popup
|
||||
Dialogs.showError(
|
||||
source.getScene(),
|
||||
"Stream Resolution Reset",
|
||||
"Stream resolution has been reset to Best (default).",
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
source.setCursor(Cursor.DEFAULT);
|
||||
}))
|
||||
.exceptionally(ex -> {
|
||||
Dialogs.showError(source.getScene(), couldntSwitchHeaderText, "The resolution can only be changed when the model is online", null);
|
||||
Platform.runLater(() -> source.setCursor(Cursor.DEFAULT));
|
||||
log.error("Unexpected error while switching resolution", ex);
|
||||
Platform.runLater(() -> {
|
||||
Dialogs.showError(source.getScene(), couldntSwitchHeaderText,
|
||||
"Unexpected error occurred", ex);
|
||||
source.setCursor(Cursor.DEFAULT);
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue