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";
|
var couldntSwitchHeaderText = "Couldn't switch stream resolution";
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
checkOnlineState();
|
checkOnlineState();
|
||||||
return selectedModel;
|
return Boolean.TRUE; // model is online
|
||||||
|
} catch (ModelOfflineException e) {
|
||||||
|
return Boolean.FALSE; // model is offline
|
||||||
|
}
|
||||||
}, GlobalThreadPool.get())
|
}, GlobalThreadPool.get())
|
||||||
.thenAccept(m -> Platform.runLater(() -> {
|
.thenAccept(isOnline -> Platform.runLater(() -> {
|
||||||
StreamSourceSelectionDialog dialog = new StreamSourceSelectionDialog(source.getScene(), selectedModel);
|
if (isOnline) {
|
||||||
|
// --- model is online: open selection dialog ---
|
||||||
|
StreamSourceSelectionDialog dialog =
|
||||||
|
new StreamSourceSelectionDialog(source.getScene(), selectedModel);
|
||||||
Optional<StreamSource> selectedSource = dialog.showAndWait();
|
Optional<StreamSource> selectedSource = dialog.showAndWait();
|
||||||
if (selectedSource.isPresent()) {
|
if (selectedSource.isPresent()) {
|
||||||
StreamSource src = selectedSource.get();
|
StreamSource src = selectedSource.get();
|
||||||
if (src != StreamSourceSelectionDialog.LOADING) {
|
if (src != StreamSourceSelectionDialog.LOADING) {
|
||||||
int index = dialog.indexOf(selectedSource.get());
|
int index = dialog.indexOf(src);
|
||||||
selectedModel.setStreamUrlIndex(index);
|
selectedModel.setStreamUrlIndex(index);
|
||||||
try {
|
try {
|
||||||
recorder.switchStreamSource(selectedModel);
|
recorder.switchStreamSource(selectedModel);
|
||||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) {
|
} catch (InvalidKeyException | NoSuchAlgorithmException |
|
||||||
|
IllegalStateException | IOException e) {
|
||||||
log.error(couldntSwitchHeaderText, 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);
|
source.setCursor(Cursor.DEFAULT);
|
||||||
}))
|
}))
|
||||||
.exceptionally(ex -> {
|
.exceptionally(ex -> {
|
||||||
Dialogs.showError(source.getScene(), couldntSwitchHeaderText, "The resolution can only be changed when the model is online", null);
|
log.error("Unexpected error while switching resolution", ex);
|
||||||
Platform.runLater(() -> source.setCursor(Cursor.DEFAULT));
|
Platform.runLater(() -> {
|
||||||
|
Dialogs.showError(source.getScene(), couldntSwitchHeaderText,
|
||||||
|
"Unexpected error occurred", ex);
|
||||||
|
source.setCursor(Cursor.DEFAULT);
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue