Reset Selected Resolution if model offline (credit @Gabi_uy)

This commit is contained in:
Jafea7 2025-09-10 21:28:20 +10:00
parent 180bfe72c2
commit 0f8ff720b7
1 changed files with 65 additions and 23 deletions

View File

@ -38,32 +38,74 @@ public class SwitchStreamResolutionAction {
var couldntSwitchHeaderText = "Couldn't switch stream resolution"; var couldntSwitchHeaderText = "Couldn't switch stream resolution";
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
checkOnlineState(); try {
return selectedModel; checkOnlineState();
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) {
Optional<StreamSource> selectedSource = dialog.showAndWait(); // --- model is online: open selection dialog ---
if (selectedSource.isPresent()) { StreamSourceSelectionDialog dialog =
StreamSource src = selectedSource.get(); new StreamSourceSelectionDialog(source.getScene(), selectedModel);
if (src != StreamSourceSelectionDialog.LOADING) { Optional<StreamSource> selectedSource = dialog.showAndWait();
int index = dialog.indexOf(selectedSource.get()); if (selectedSource.isPresent()) {
selectedModel.setStreamUrlIndex(index); StreamSource src = selectedSource.get();
try { if (src != StreamSourceSelectionDialog.LOADING) {
recorder.switchStreamSource(selectedModel); int index = dialog.indexOf(src);
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) { selectedModel.setStreamUrlIndex(index);
log.error(couldntSwitchHeaderText, e); try {
Dialogs.showError(source.getScene(), "Couldn't switch stream resolution", "Error while switching stream resolution", e); recorder.switchStreamSource(selectedModel);
} } catch (InvalidKeyException | NoSuchAlgorithmException |
IllegalStateException | IOException e) {
log.error(couldntSwitchHeaderText, e);
Dialogs.showError(source.getScene(), couldntSwitchHeaderText,
"Error while switching stream resolution", e);
} }
} }
source.setCursor(Cursor.DEFAULT); }
})) } else {
.exceptionally(ex -> { // --- model is offline: ask if user wants to reset ---
Dialogs.showError(source.getScene(), couldntSwitchHeaderText, "The resolution can only be changed when the model is online", null); boolean confirmed = Dialogs.showConfirmDialog(
Platform.runLater(() -> source.setCursor(Cursor.DEFAULT)); "Model is offline",
return null; "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 -> {
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;
});
} }
private void checkOnlineState() { private void checkOnlineState() {