Code cleanup
This commit is contained in:
parent
f4b990366b
commit
f7276778f4
|
@ -22,6 +22,7 @@ import ctbrec.ui.tabs.TabSelectionListener;
|
|||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.Transition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.BooleanExpression;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
@ -48,6 +49,7 @@ import java.io.*;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -239,18 +241,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
.ifPresent(configPanel -> siteCategories.add(Category.of(site.getName(), configPanel)));
|
||||
}
|
||||
|
||||
Button openPacButton = new Button("View PAC File");
|
||||
openPacButton.setOnAction(e -> {
|
||||
String url = pacUrl.get();
|
||||
if (url != null && !url.isEmpty()) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(new URI(url));
|
||||
} catch (Exception ex) {
|
||||
log.error("Could not open PAC file in browser", ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var storage = new CtbrecPreferencesStorage(config);
|
||||
var prefs = Preferences.of(storage,
|
||||
Category.of("General",
|
||||
|
@ -347,7 +337,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
Setting.of("Username", proxyUser).needsRestart(),
|
||||
Setting.of("Password", proxyPassword).needsRestart(),
|
||||
Setting.of("PAC URL", pacUrl, "URL to your Proxy Auto-Config (PAC) file (e.g. http://example.com/pac.js or file:///G:/path/to/pac.js)").needsRestart(),
|
||||
Setting.of("", openPacButton))),
|
||||
Setting.of("", createPacButton()))),
|
||||
Category.of("Advanced / Devtools",
|
||||
Group.of("Networking",
|
||||
Setting.of("Playlist request timeout (ms)", playlistRequestTimeout, "Timeout in ms for playlist requests")),
|
||||
|
@ -441,6 +431,42 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
return postProcessingHelpButton;
|
||||
}
|
||||
|
||||
private Button createPacButton() {
|
||||
Button openPacButton = new Button("View PAC File");
|
||||
openPacButton.setOnAction(e -> {
|
||||
String url = pacUrl.get();
|
||||
if (url == null || url.trim().isEmpty()) {
|
||||
Dialogs.showToast(this.getTabPane().getScene(), "Invalid PAC URL: Please enter a valid PAC URL in the settings.");
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if (!uri.getScheme().equalsIgnoreCase("http") && !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file")) {
|
||||
Platform.runLater(() -> Dialogs.showToast(this.getTabPane().getScene(), "Invalid PAC URL: Must use http, https, or file scheme."));
|
||||
return;
|
||||
}
|
||||
log.info("Opening PAC file in browser: {}", url);
|
||||
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
||||
Desktop.getDesktop().browse(uri);
|
||||
} else {
|
||||
log.info("Desktop.browse not supported, trying xdg-open");
|
||||
ProcessBuilder pb = new ProcessBuilder("xdg-open", url);
|
||||
pb.start();
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
log.error("Invalid PAC URL format: {}", url, ex);
|
||||
Platform.runLater(() -> Dialogs.showToast(this.getTabPane().getScene(), "Invalid PAC URL: " + ex.getMessage()));
|
||||
} catch (IOException ex) {
|
||||
log.error("Failed to open PAC file in browser: {}", url, ex);
|
||||
Platform.runLater(() -> Dialogs.showToast(this.getTabPane().getScene(), "Failed to open PAC file: " + ex.getMessage()));
|
||||
}
|
||||
}, "PAC-Browser-Thread").start();
|
||||
});
|
||||
openPacButton.disableProperty().bind(pacUrl.isNull().or(pacUrl.isEqualTo("")));
|
||||
return openPacButton;
|
||||
}
|
||||
|
||||
private Button createBackupConfigButton() {
|
||||
var button = new Button("Backup Config");
|
||||
button.setTooltip(new Tooltip("Excludes recordings, cache, and backup configs."));
|
||||
|
@ -671,39 +697,6 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void showToast(String message) {
|
||||
Label toast = new Label(message);
|
||||
toast.setStyle("-fx-background-color: #323232; -fx-text-fill: white; -fx-padding: 10px; -fx-border-radius: 5px; -fx-background-radius: 5px;");
|
||||
toast.setOpacity(0);
|
||||
|
||||
StackPane parent = (StackPane) getContent();
|
||||
toast.setMaxWidth(Double.MAX_VALUE);
|
||||
toast.setAlignment(Pos.CENTER);
|
||||
|
||||
parent.getChildren().add(toast);
|
||||
StackPane.setAlignment(toast, Pos.BOTTOM_CENTER);
|
||||
StackPane.setMargin(toast, new Insets(0, 0, 40, 0));
|
||||
|
||||
FadeTransition fadeIn = new FadeTransition(Duration.millis(500), toast);
|
||||
fadeIn.setFromValue(0);
|
||||
fadeIn.setToValue(1);
|
||||
|
||||
FadeTransition fadeOut = new FadeTransition(Duration.millis(500), toast);
|
||||
fadeOut.setFromValue(1);
|
||||
fadeOut.setToValue(0);
|
||||
|
||||
fadeIn.setOnFinished(e -> {
|
||||
PauseTransition pause = new PauseTransition(Duration.seconds(3));
|
||||
pause.setOnFinished(ev -> fadeOut.play());
|
||||
pause.play();
|
||||
});
|
||||
|
||||
fadeOut.setOnFinished(e -> parent.getChildren().remove(toast));
|
||||
|
||||
fadeIn.play();
|
||||
}
|
||||
|
||||
|
||||
public record SplitBiggerThanOption(String label, @Getter long value) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -98,28 +98,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="modal fade" id="contactsheetModal" tabindex="-1" aria-labelledby="contactsheetModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" style="max-width: 80vw;">
|
||||
<div class="modal-content modal-content-contactsheet">
|
||||
<div class="modal-header">
|
||||
<h6 class="modal-title title-truncate" id="contactsheetModalLabel">Image Title</h6>
|
||||
<button type="button" class="btn btn-danger fas fa-times-circle" data-dismiss="modal" aria-label="Close">
|
||||
<span class="sr-only">Close</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body text-center">
|
||||
<img id="imageModalImage" src="placeholder.jpg" alt="Contact Sheet" class="img-fluid" style="max-width: 100%; height: auto;" />
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger fas fa-trash"
|
||||
data-bind="enable: (ko_status() === 'FINISHED' && ko_contactSheet() !== null), click: show, attr: { title: (ko_status() === 'FINISHED' && ko_contactSheet() !== null) ? 'Show contact sheet' : 'No contact sheet' }">
|
||||
<span class="sr-only">Show contact sheet</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<section id="models" class="tab-pane fade active show" role="tabpanel" aria-labelledby="models-tab">
|
||||
<div class="container">
|
||||
|
@ -630,54 +608,6 @@
|
|||
if (console) console.log('Unexpected error', e);
|
||||
}
|
||||
},
|
||||
|
||||
/* rerunProcessing: function(recording) {
|
||||
let name = recording.model.name + ' ' + recording.ko_date();
|
||||
try {
|
||||
let action = '{"action": "rerunPostProcessing", "recording": ' + JSON.stringify(recording) + '}';
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '../rec',
|
||||
dataType: 'json',
|
||||
async: true,
|
||||
timeout: 60000,
|
||||
headers: {'CTBREC-HMAC': CryptoJS.HmacSHA256(action, hmac)},
|
||||
data: action
|
||||
});
|
||||
} catch (e) {
|
||||
if (console) console.log('Unexpected error', e);
|
||||
}
|
||||
},
|
||||
|
||||
deleteRecording: function(recording) {
|
||||
let name = recording.model.name + ' ' + recording.ko_date();
|
||||
try {
|
||||
let action = '{"action": "delete", "recording": ' + JSON.stringify(recording) + '}';
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '../rec',
|
||||
dataType: 'json',
|
||||
async: true,
|
||||
timeout: 60000,
|
||||
headers: {'CTBREC-HMAC': CryptoJS.HmacSHA256(action, hmac)},
|
||||
data: action
|
||||
})
|
||||
.done(function(data) {
|
||||
if (data.status === 'success') {
|
||||
$.notify('Removed recording ' + name, 'info');
|
||||
observableRecordingsArray.remove(recording);
|
||||
} else {
|
||||
$.notify('Removing recording ' + name + ' failed', 'error');
|
||||
}
|
||||
})
|
||||
.fail(function(jqXHR, textStatus, errorThrown) {
|
||||
if (console) console.log(textStatus, errorThrown);
|
||||
$.notify('Removing recording ' + name + ' failed', 'error');
|
||||
});
|
||||
} catch (e) {
|
||||
if (console) console.log('Unexpected error', e);
|
||||
}
|
||||
} */
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
|
|
|
@ -287,7 +287,6 @@ function updateDiskSpace() {
|
|||
}
|
||||
|
||||
function getImageUrl(localFilePath) {
|
||||
// if (!localFilePath) return null; // Can be removed since button is disabled if no valid content
|
||||
if (console) console.log("getImageUrl: " + localFilePath);
|
||||
// Find recordingsDir from observableSettingsArray
|
||||
let recordingsDirEntry = ko.utils.arrayFirst(observableSettingsArray(), item => item.key === 'recordingsDir');
|
||||
|
|
Loading…
Reference in New Issue