let the permissions dialog retry the hook

This commit is contained in:
bea
2026-09-29 12:15:47 +02:00
parent fc526bfed5
commit ca99bc0533
2 changed files with 32 additions and 17 deletions
@@ -38,7 +38,7 @@ public class Main {
} }
} }
private static boolean registerJNativeHook() { public static boolean registerJNativeHook() {
LOGGER.info("Registering jnativehook library..."); LOGGER.info("Registering jnativehook library...");
try { try {
GlobalScreen.registerNativeHook(); GlobalScreen.registerNativeHook();
@@ -177,26 +177,41 @@ public class MainWindow
/** /**
* Explains that the app cannot work without its permissions, and offers * Explains that the app cannot work without its permissions, and offers
* a shortcut to the right system settings pane. Must be called on the * a shortcut to the right system settings pane. the hook is retried on
* EDT, after the window is visible. * demand, so the app can start working without a restart. must be called
* on the EDT, after the window is visible.
*/ */
public void showPermissionsHelp() { public void showPermissionsHelp() {
Object[] options = {"Open System Settings", "Close"}; Object[] options = {"Open System Settings", "Try Again", "Close"};
int choice = JOptionPane.showOptionDialog(frame, while (true) {
"autosqueal needs the accessibility permission to move the mouse and to\n" int choice = JOptionPane.showOptionDialog(frame,
+ "listen for the ctrl+alt hotkey, and the screen recording one to\n" "autosqueal needs the accessibility permission to move the mouse and to\n"
+ "show the screen preview. they cannot be granted while it is running.\n\n" + "listen for the ctrl+alt hotkey, and the screen recording one to\n"
+ "grant them in privacy & security, then restart autosqueal.", + "show the screen preview.\n\n"
"permissions needed", + "grant them in privacy & security, then press \"try again\".\n"
JOptionPane.DEFAULT_OPTION, + "if autosqueal already appears in the list, remove it with the\n"
JOptionPane.WARNING_MESSAGE, + "minus button and allow it again: every rebuild looks like a\n"
null, + "different app to the system.",
options, "permissions needed",
options[0]); JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
options,
options[0]);
if (choice == 0) { if (choice == 0) {
openPrivacySettings(); openPrivacySettings();
} else if (choice == 1) {
if (Main.registerJNativeHook()) {
LOGGER.info("The native hook was registered on a later attempt!");
return;
}
} else {
// closed or gave up: leave the app running, the window and the
// tray icon still work
return;
}
} }
} }