mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-01 17:47:30 +13:00
Initial split for pref categories
This commit is contained in:
parent
1553ca95f4
commit
245ba1a238
3 changed files with 107 additions and 47 deletions
|
@ -1,6 +1,5 @@
|
|||
package io.xpipe.app.prefs;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import com.dlsc.formsfx.model.structure.*;
|
||||
import com.dlsc.preferencesfx.formsfx.view.controls.SimpleComboBoxControl;
|
||||
import com.dlsc.preferencesfx.formsfx.view.controls.SimpleControl;
|
||||
|
@ -17,15 +16,11 @@ import io.xpipe.app.core.AppTheme;
|
|||
import io.xpipe.app.ext.PrefsChoiceValue;
|
||||
import io.xpipe.app.ext.PrefsHandler;
|
||||
import io.xpipe.app.ext.PrefsProvider;
|
||||
import io.xpipe.app.fxcomps.impl.HorizontalComp;
|
||||
import io.xpipe.app.fxcomps.impl.StackComp;
|
||||
import io.xpipe.app.fxcomps.impl.TextFieldComp;
|
||||
import io.xpipe.app.fxcomps.util.SimpleChangeListener;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.util.*;
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.process.CommandControl;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
import io.xpipe.core.util.ModuleHelper;
|
||||
import io.xpipe.core.util.SecretValue;
|
||||
import javafx.beans.binding.Bindings;
|
||||
|
@ -167,7 +162,7 @@ public class AppPrefs {
|
|||
|
||||
// Password manager
|
||||
// ================
|
||||
private final StringProperty passwordManagerCommand = typed(new SimpleStringProperty(""), String.class);
|
||||
final StringProperty passwordManagerCommand = typed(new SimpleStringProperty(""), String.class);
|
||||
|
||||
// Start behaviour
|
||||
// ===============
|
||||
|
@ -552,6 +547,7 @@ public class AppPrefs {
|
|||
null,
|
||||
new LazyNodeElement<>(() -> new StackComp(
|
||||
List.of(new ButtonComp(AppI18n.observable("test"), new FontIcon("mdi2p-play"), () -> {
|
||||
save();
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
var term = AppPrefs.get().terminalType().getValue();
|
||||
if (term != null) {
|
||||
|
@ -569,6 +565,7 @@ public class AppPrefs {
|
|||
null,
|
||||
new LazyNodeElement<>(() -> new StackComp(
|
||||
List.of(new ButtonComp(AppI18n.observable("test"), new FontIcon("mdi2p-play"), () -> {
|
||||
save();
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
var editor =
|
||||
AppPrefs.get().externalEditor().getValue();
|
||||
|
@ -585,44 +582,6 @@ public class AppPrefs {
|
|||
var troubleshoot =
|
||||
ctr.newInstance(null, new LazyNodeElement<>(() -> new TroubleshootComp().createRegion()), null);
|
||||
|
||||
var testPasswordManagerValue = new SimpleStringProperty();
|
||||
var testPasswordManager = ctr.newInstance(
|
||||
"passwordManagerCommandTest",
|
||||
new LazyNodeElement<>(() -> new HorizontalComp(List.of(
|
||||
new TextFieldComp(testPasswordManagerValue)
|
||||
.apply(struc -> struc.get().setPromptText("Test password key"))
|
||||
.styleClass(Styles.LEFT_PILL)
|
||||
.grow(false, true),
|
||||
new ButtonComp(null, new FontIcon("mdi2p-play"), () -> {
|
||||
var cmd = passwordManagerString(testPasswordManagerValue.get());
|
||||
if (cmd == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
TerminalHelper.open(
|
||||
"Password test",
|
||||
new LocalStore()
|
||||
.control()
|
||||
.command(cmd
|
||||
+ "\n" + ShellDialects.getPlatformDefault()
|
||||
.getEchoCommand(
|
||||
"Is this your password?", false))
|
||||
.terminalExitMode(
|
||||
CommandControl.TerminalExitMode
|
||||
.KEEP_OPEN));
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
}
|
||||
})
|
||||
.styleClass(Styles.RIGHT_PILL)
|
||||
.grow(false, true)))
|
||||
.padding(new Insets(15, 0, 0, 0))
|
||||
.apply(struc -> struc.get().setAlignment(Pos.CENTER_LEFT))
|
||||
.apply(struc -> struc.get().setFillHeight(true))
|
||||
.createRegion()),
|
||||
null);
|
||||
|
||||
var categories = new ArrayList<>(List.of(
|
||||
Category.of("about", Group.of(about)),
|
||||
Category.of(
|
||||
|
@ -655,9 +614,7 @@ public class AppPrefs {
|
|||
Setting.of("tooltipDelay", tooltipDelayInternal, tooltipDelayMin, tooltipDelayMax),
|
||||
Setting.of("language", languageControl, languageInternal)),
|
||||
Group.of("windowOptions", Setting.of("saveWindowLocation", saveWindowLocationInternal))),
|
||||
Category.of(
|
||||
"passwordManager",
|
||||
Group.of(Setting.of("passwordManagerCommand", passwordManagerCommand), testPasswordManager)),
|
||||
new PasswordCategory(this).create(),
|
||||
Category.of(
|
||||
"editor",
|
||||
Group.of(
|
||||
|
|
26
app/src/main/java/io/xpipe/app/prefs/AppPrefsCategory.java
Normal file
26
app/src/main/java/io/xpipe/app/prefs/AppPrefsCategory.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package io.xpipe.app.prefs;
|
||||
|
||||
import com.dlsc.formsfx.model.structure.Element;
|
||||
import com.dlsc.preferencesfx.model.Category;
|
||||
import com.dlsc.preferencesfx.model.Setting;
|
||||
import io.xpipe.app.fxcomps.Comp;
|
||||
import javafx.beans.property.Property;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
public abstract class AppPrefsCategory {
|
||||
|
||||
@SneakyThrows
|
||||
public static Setting<?,?> lazyNode(String name, Comp<?> comp, Property<?> property) {
|
||||
var ctr = Setting.class.getDeclaredConstructor(String.class, Element.class, Property.class);
|
||||
ctr.setAccessible(true);
|
||||
return ctr.newInstance(name, new LazyNodeElement<>(() -> comp.createRegion()), property);
|
||||
}
|
||||
|
||||
protected final AppPrefs prefs;
|
||||
|
||||
public AppPrefsCategory(AppPrefs prefs) {
|
||||
this.prefs = prefs;
|
||||
}
|
||||
|
||||
protected abstract Category create();
|
||||
}
|
77
app/src/main/java/io/xpipe/app/prefs/PasswordCategory.java
Normal file
77
app/src/main/java/io/xpipe/app/prefs/PasswordCategory.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package io.xpipe.app.prefs;
|
||||
|
||||
import atlantafx.base.theme.Styles;
|
||||
import com.dlsc.formsfx.model.structure.Element;
|
||||
import com.dlsc.preferencesfx.model.Category;
|
||||
import com.dlsc.preferencesfx.model.Group;
|
||||
import com.dlsc.preferencesfx.model.Setting;
|
||||
import io.xpipe.app.comp.base.ButtonComp;
|
||||
import io.xpipe.app.fxcomps.impl.HorizontalComp;
|
||||
import io.xpipe.app.fxcomps.impl.TextFieldComp;
|
||||
import io.xpipe.app.util.TerminalHelper;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.process.CommandControl;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import lombok.SneakyThrows;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PasswordCategory extends AppPrefsCategory {
|
||||
|
||||
public PasswordCategory(AppPrefs prefs) {
|
||||
super(prefs);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Category create() {
|
||||
var ctr = Setting.class.getDeclaredConstructor(String.class, Element.class, Property.class);
|
||||
ctr.setAccessible(true);
|
||||
|
||||
var testPasswordManagerValue = new SimpleStringProperty();
|
||||
Runnable test = () -> {
|
||||
prefs.save();
|
||||
var cmd = prefs.passwordManagerString(testPasswordManagerValue.get());
|
||||
if (cmd == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
TerminalHelper.open(
|
||||
"Password test",
|
||||
new LocalStore()
|
||||
.control()
|
||||
.command(cmd
|
||||
+ "\n"
|
||||
+ ShellDialects.getPlatformDefault()
|
||||
.getEchoCommand("Is this your password?", false))
|
||||
.terminalExitMode(CommandControl.TerminalExitMode.KEEP_OPEN));
|
||||
});
|
||||
};
|
||||
|
||||
var testPasswordManager = lazyNode(
|
||||
"passwordManagerCommandTest",
|
||||
new HorizontalComp(List.of(
|
||||
new TextFieldComp(testPasswordManagerValue)
|
||||
.apply(struc -> struc.get().setPromptText("Test password key"))
|
||||
.styleClass(Styles.LEFT_PILL)
|
||||
.grow(false, true),
|
||||
new ButtonComp(null, new FontIcon("mdi2p-play"), test)
|
||||
.styleClass(Styles.RIGHT_PILL)
|
||||
.grow(false, true)))
|
||||
.padding(new Insets(15, 0, 0, 0))
|
||||
.apply(struc -> struc.get().setAlignment(Pos.CENTER_LEFT))
|
||||
.apply(struc -> struc.get().setFillHeight(true)),
|
||||
null);
|
||||
return Category.of(
|
||||
"passwordManager",
|
||||
Group.of(
|
||||
Setting.of("passwordManagerCommand", prefs.passwordManagerCommand),
|
||||
testPasswordManager));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue