mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-02 18:51:01 +12:00
Improve macos permission prompt
This commit is contained in:
parent
b851c1da11
commit
ccce77a648
3 changed files with 50 additions and 18 deletions
|
@ -99,15 +99,11 @@ public class AppWindowHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<ButtonType> showBlockingAlert(Consumer<Alert> c) {
|
public static Optional<ButtonType> showBlockingAlert(Alert a) {
|
||||||
AtomicReference<Optional<ButtonType>> result = new AtomicReference<>();
|
AtomicReference<Optional<ButtonType>> result = new AtomicReference<>();
|
||||||
if (!Platform.isFxApplicationThread()) {
|
if (!Platform.isFxApplicationThread()) {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert a = AppWindowHelper.createEmptyAlert();
|
|
||||||
AppFont.normal(a.getDialogPane());
|
|
||||||
|
|
||||||
c.accept(a);
|
|
||||||
result.set(a.showAndWait());
|
result.set(a.showAndWait());
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
});
|
});
|
||||||
|
@ -116,10 +112,6 @@ public class AppWindowHelper {
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Alert a = createEmptyAlert();
|
|
||||||
AppFont.normal(a.getDialogPane());
|
|
||||||
c.accept(a);
|
|
||||||
|
|
||||||
Button button = (Button) a.getDialogPane().lookupButton(ButtonType.OK);
|
Button button = (Button) a.getDialogPane().lookupButton(ButtonType.OK);
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.getStyleClass().add("ok-button");
|
button.getStyleClass().add("ok-button");
|
||||||
|
@ -130,6 +122,13 @@ public class AppWindowHelper {
|
||||||
return result.get();
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Optional<ButtonType> showBlockingAlert(Consumer<Alert> c) {
|
||||||
|
Alert a = AppWindowHelper.createEmptyAlert();
|
||||||
|
AppFont.normal(a.getDialogPane());
|
||||||
|
c.accept(a);
|
||||||
|
return showBlockingAlert(a);
|
||||||
|
}
|
||||||
|
|
||||||
public static Alert createEmptyAlert() {
|
public static Alert createEmptyAlert() {
|
||||||
Alert alert = new Alert(Alert.AlertType.NONE);
|
Alert alert = new Alert(Alert.AlertType.NONE);
|
||||||
setIcon(alert);
|
setIcon(alert);
|
||||||
|
|
|
@ -1,20 +1,51 @@
|
||||||
package io.xpipe.app.util;
|
package io.xpipe.app.util;
|
||||||
|
|
||||||
|
import io.xpipe.app.core.AppWindowHelper;
|
||||||
import io.xpipe.core.store.ShellStore;
|
import io.xpipe.core.store.ShellStore;
|
||||||
|
import io.xpipe.extension.I18n;
|
||||||
import io.xpipe.extension.util.ThreadHelper;
|
import io.xpipe.extension.util.ThreadHelper;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
|
||||||
public class MacOsPermissions {
|
public class MacOsPermissions {
|
||||||
|
|
||||||
public static boolean waitForAccessibilityPermissions() throws Exception {
|
private static Alert createAlert() {
|
||||||
try (var pc = ShellStore.local().create().start()) {
|
var alert = AppWindowHelper.createEmptyAlert();
|
||||||
while (true) {
|
alert.setAlertType(Alert.AlertType.CONFIRMATION);
|
||||||
var success = pc.executeBooleanSimpleCommand("osascript -e 'tell application \"System Events\" to keystroke \"t\"'");
|
alert.setTitle(I18n.get("permissionsAlertTitle"));
|
||||||
if (success) {
|
alert.setHeaderText(I18n.get("permissionsAlertTitleHeader"));
|
||||||
return true;
|
alert.getDialogPane().setContent(AppWindowHelper.alertContentText(I18n.get("permissionsAlertTitleContent")));
|
||||||
}
|
alert.setAlertType(Alert.AlertType.CONFIRMATION);
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
ThreadHelper.sleep(1000);
|
public static boolean waitForAccessibilityPermissions() throws Exception {
|
||||||
|
var alert = createAlert();
|
||||||
|
var state = new SimpleBooleanProperty(true);
|
||||||
|
try (var pc = ShellStore.local().create().start()) {
|
||||||
|
while (state.get()) {
|
||||||
|
var success = pc.executeBooleanSimpleCommand(
|
||||||
|
"osascript -e 'tell application \"System Events\" to keystroke \"t\"'");
|
||||||
|
if (success) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
alert.close();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
var result = AppWindowHelper.showBlockingAlert(alert)
|
||||||
|
.map(buttonType -> buttonType.getButtonData().isDefaultButton())
|
||||||
|
.orElse(false);
|
||||||
|
if (!result) {
|
||||||
|
state.set(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ThreadHelper.sleep(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,9 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String command) throws Exception {
|
||||||
MacOsPermissions.waitForAccessibilityPermissions();
|
if (!MacOsPermissions.waitForAccessibilityPermissions()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try (ShellProcessControl pc = ShellStore.local().create().start()) {
|
try (ShellProcessControl pc = ShellStore.local().create().start()) {
|
||||||
var cmd = String.format(
|
var cmd = String.format(
|
||||||
|
|
Loading…
Reference in a new issue