mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-03 03:01:13 +12:00
More macOS integration fixes
This commit is contained in:
parent
ccce77a648
commit
0a7741cb8c
3 changed files with 28 additions and 10 deletions
|
@ -74,6 +74,15 @@ public class AppWindowHelper {
|
||||||
childStage.setY(stage.getY() + stage.getHeight() / 2 - childStage.getHeight() / 2);
|
childStage.setY(stage.getY() + stage.getHeight() / 2 - childStage.getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showAlert(Alert a, Consumer<Optional<ButtonType>> bt) {
|
||||||
|
ThreadHelper.runAsync(() -> {
|
||||||
|
var r = showBlockingAlert(a);
|
||||||
|
if (bt != null) {
|
||||||
|
bt.accept(r);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static void showAlert(Consumer<Alert> c, Consumer<Optional<ButtonType>> bt) {
|
public static void showAlert(Consumer<Alert> c, Consumer<Optional<ButtonType>> bt) {
|
||||||
ThreadHelper.runAsync(() -> {
|
ThreadHelper.runAsync(() -> {
|
||||||
var r = showBlockingAlert(c);
|
var r = showBlockingAlert(c);
|
||||||
|
|
|
@ -8,20 +8,22 @@ import javafx.application.Platform;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class MacOsPermissions {
|
public class MacOsPermissions {
|
||||||
|
|
||||||
private static Alert createAlert() {
|
private static Alert createAlert() {
|
||||||
var alert = AppWindowHelper.createEmptyAlert();
|
var alert = AppWindowHelper.createEmptyAlert();
|
||||||
alert.setAlertType(Alert.AlertType.CONFIRMATION);
|
alert.setAlertType(Alert.AlertType.INFORMATION);
|
||||||
alert.setTitle(I18n.get("permissionsAlertTitle"));
|
alert.setTitle(I18n.get("permissionsAlertTitle"));
|
||||||
alert.setHeaderText(I18n.get("permissionsAlertTitleHeader"));
|
alert.setHeaderText(I18n.get("permissionsAlertTitleHeader"));
|
||||||
alert.getDialogPane().setContent(AppWindowHelper.alertContentText(I18n.get("permissionsAlertTitleContent")));
|
alert.getDialogPane().setContent(AppWindowHelper.alertContentText(I18n.get("permissionsAlertTitleContent")));
|
||||||
alert.setAlertType(Alert.AlertType.CONFIRMATION);
|
alert.getButtonTypes().clear();
|
||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean waitForAccessibilityPermissions() throws Exception {
|
public static boolean waitForAccessibilityPermissions() throws Exception {
|
||||||
var alert = createAlert();
|
AtomicReference<Alert> alert = new AtomicReference<>();
|
||||||
var state = new SimpleBooleanProperty(true);
|
var state = new SimpleBooleanProperty(true);
|
||||||
try (var pc = ShellStore.local().create().start()) {
|
try (var pc = ShellStore.local().create().start()) {
|
||||||
while (state.get()) {
|
while (state.get()) {
|
||||||
|
@ -29,17 +31,24 @@ public class MacOsPermissions {
|
||||||
"osascript -e 'tell application \"System Events\" to keystroke \"t\"'");
|
"osascript -e 'tell application \"System Events\" to keystroke \"t\"'");
|
||||||
if (success) {
|
if (success) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
alert.close();
|
if (alert.get() != null) {
|
||||||
|
alert.get().close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
var result = AppWindowHelper.showBlockingAlert(alert)
|
if (alert.get() != null) {
|
||||||
.map(buttonType -> buttonType.getButtonData().isDefaultButton())
|
return;
|
||||||
.orElse(false);
|
|
||||||
if (!result) {
|
|
||||||
state.set(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alert.set(createAlert());
|
||||||
|
AppWindowHelper.showAlert(alert.get(), buttonType -> {
|
||||||
|
alert.get().close();
|
||||||
|
if (buttonType.isEmpty() || !buttonType.get().getButtonData().isDefaultButton()) {
|
||||||
|
state.set(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
ThreadHelper.sleep(1000);
|
ThreadHelper.sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,7 +484,7 @@ public class ShellTypes {
|
||||||
var content = "";
|
var content = "";
|
||||||
for (Map.Entry<String, String> e : variables.entrySet()) {
|
for (Map.Entry<String, String> e : variables.entrySet()) {
|
||||||
content += e.getKey() + "=\"" + e.getValue() + "\"";
|
content += e.getKey() + "=\"" + e.getValue() + "\"";
|
||||||
content += getConcatenationOperator();
|
content += " ";
|
||||||
}
|
}
|
||||||
return content + command;
|
return content + command;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue