mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Rework unlock alert
This commit is contained in:
parent
21b7e063aa
commit
99adb0866f
1 changed files with 3 additions and 46 deletions
|
@ -1,20 +1,8 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.core.AppStyle;
|
||||
import io.xpipe.app.core.AppTheme;
|
||||
import io.xpipe.app.core.window.AppWindowHelper;
|
||||
import io.xpipe.app.fxcomps.impl.SecretFieldComp;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.core.util.InPlaceSecretValue;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class UnlockAlert {
|
||||
|
||||
|
@ -28,40 +16,9 @@ public class UnlockAlert {
|
|||
return;
|
||||
}
|
||||
|
||||
PlatformState.initPlatformOrThrow();
|
||||
AppI18n.init();
|
||||
AppStyle.init();
|
||||
AppTheme.init();
|
||||
|
||||
while (true) {
|
||||
var pw = new SimpleObjectProperty<InPlaceSecretValue>();
|
||||
var canceled = new SimpleBooleanProperty();
|
||||
AppWindowHelper.showBlockingAlert(alert -> {
|
||||
alert.setTitle(AppI18n.get("unlockAlertTitle"));
|
||||
alert.setHeaderText(AppI18n.get("unlockAlertHeader"));
|
||||
alert.setAlertType(Alert.AlertType.CONFIRMATION);
|
||||
|
||||
var text = new SecretFieldComp(pw, false).createRegion();
|
||||
text.setStyle("-fx-border-width: 1px");
|
||||
|
||||
var content = new VBox(text);
|
||||
content.setSpacing(5);
|
||||
alert.getDialogPane().setContent(content);
|
||||
|
||||
var stage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||
stage.setAlwaysOnTop(true);
|
||||
|
||||
alert.setOnShown(event -> {
|
||||
stage.requestFocus();
|
||||
// Wait 1 pulse before focus so that the scene can be assigned to text
|
||||
Platform.runLater(text::requestFocus);
|
||||
event.consume();
|
||||
});
|
||||
})
|
||||
.filter(b -> b.getButtonData().isDefaultButton())
|
||||
.ifPresentOrElse(t -> {}, () -> canceled.set(true));
|
||||
|
||||
if (canceled.get()) {
|
||||
var r = AskpassAlert.queryRaw(AppI18n.get("unlockAlertHeader"), null);
|
||||
if (r.getState() == SecretQueryState.CANCELLED) {
|
||||
ErrorEvent.fromMessage("Unlock cancelled")
|
||||
.expected()
|
||||
.term()
|
||||
|
@ -70,7 +27,7 @@ public class UnlockAlert {
|
|||
return;
|
||||
}
|
||||
|
||||
if (AppPrefs.get().unlock(pw.get())) {
|
||||
if (AppPrefs.get().unlock(r.getSecret().inPlace())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue