diff --git a/app/src/main/java/io/xpipe/app/util/UnlockAlert.java b/app/src/main/java/io/xpipe/app/util/UnlockAlert.java index e1342778..3f69f527 100644 --- a/app/src/main/java/io/xpipe/app/util/UnlockAlert.java +++ b/app/src/main/java/io/xpipe/app/util/UnlockAlert.java @@ -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(); - 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; } }