change the way we present errors on global key event hook reg error

the "Retry" button thing we had previously didn't really seem all that
good in practice, as there's no way (??) to determine if the OS actually
_did_ pop up some kind of prompt for the user (as OS X does).

since hotkeys won't work if hook registration fails, displaying an
error immediately seems to be the best option... and still much better
then what used to happen where the app would just silently fail to start
This commit is contained in:
Gered 2015-12-04 12:39:56 -05:00
parent 3ef68d88e3
commit ea09a5c5f5
4 changed files with 7 additions and 24 deletions

View file

@ -51,8 +51,7 @@ public enum Language {
setting_hotkey_pause,
setting_hotkey_lock,
GLOBAL_HOTKEYS_WARNING,
GLOBAL_HOTKEYS_HOOK_RETRY,
GLOBAL_HOTKEYS_HOOK_ERROR,
GLOBAL_HOTKEYS_STARTUP_WARNING,
// Settings > Header
setting_header_goal,

View file

@ -472,7 +472,7 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
* Attempts to register a hook to capture system-wide (global) key events.
* @return true if the hook was registered, false if not
*/
public static boolean registerNativeKeyHook() {
public boolean registerNativeKeyHook() {
try {
GlobalScreen.registerNativeHook();
return true;
@ -481,6 +481,8 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
// to pop up an OS-specific dialog or other action that allows the user to rectify the
// problem. e.g. on OS X, if an exception is thrown a dialog telling the user that the
// application has requested some accessibility-related access shows up.
JOptionPane.showMessageDialog(this, Language.GLOBAL_HOTKEYS_WARNING, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
return false;
}
}

View file

@ -1,7 +1,6 @@
package org.fenix.llanfair.dialog;
import org.fenix.llanfair.Language;
import org.fenix.llanfair.Llanfair;
import org.fenix.llanfair.config.Settings;
import org.fenix.utils.gui.GBC;
import org.jnativehook.GlobalScreen;
@ -25,7 +24,6 @@ class TabHotkeys extends SettingsTab {
private JCheckBox globalHotKeys;
private JLabel globalHotKeysHookWarning;
private JButton globalHotKeysHookRetryButton;
/**
* List of all key fields customizable by the user.
@ -54,19 +52,6 @@ class TabHotkeys extends SettingsTab {
globalHotKeysHookWarning = new JLabel("" + Language.GLOBAL_HOTKEYS_WARNING);
globalHotKeysHookWarning.setForeground(Color.RED);
globalHotKeysHookRetryButton = new JButton("" + Language.GLOBAL_HOTKEYS_HOOK_RETRY);
globalHotKeysHookRetryButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
boolean isRegistered = Llanfair.registerNativeKeyHook();
if (isRegistered) {
globalHotKeysHookWarning.setVisible(false);
globalHotKeysHookRetryButton.setVisible(false);
} else {
JOptionPane.showMessageDialog(that, Language.GLOBAL_HOTKEYS_HOOK_ERROR, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
}
}
});
keyFields = new ArrayList<KeyField>();
keyLabels = new ArrayList<JLabel>();
@ -113,10 +98,8 @@ class TabHotkeys extends SettingsTab {
add(globalHotKeys, GBC.grid(2, 3).insets(0, 50, 0, 0).anchor(GBC.LS));
if (!GlobalScreen.isNativeHookRegistered()) {
if (GlobalScreen.isNativeHookRegistered())
add(globalHotKeysHookWarning, GBC.grid(0, row + 1, 3, 1).insets(10, 0, 10, 0));
add(globalHotKeysHookRetryButton, GBC.grid(0, row + 2, 3, 1).insets(0, 0, 10, 0));
}
}
// --------------------------------------------------------- INTERNAL TYPES

View file

@ -31,9 +31,8 @@ setting_hotkey_reset = Reset
setting_hotkey_stop = Stop
setting_hotkey_pause = Pause
setting_hotkey_lock = Lock / Unlock
GLOBAL_HOTKEYS_WARNING = <html><div style="width: 300px;">Key event hook registration failed. <strong>You will not be able to set or use any of your hotkeys until this is fixed!</strong> Click 'Retry' below to attempt to register it again.</div></html>
GLOBAL_HOTKEYS_HOOK_RETRY = Retry
GLOBAL_HOTKEYS_HOOK_ERROR = Key event hook registration failed. You will need to grant extra accessibility permissions to Llanfair.
GLOBAL_HOTKEYS_WARNING = <html><div style="width: 300px;">Key event hook registration failed. <strong>You will not be able to set or use any of your hotkeys until this is fixed!</strong> To fix this, you will probably need to grant Llanfair some extended accessibility permissions from your operating system and then restart Llanfair.</div></html>
GLOBAL_HOTKEYS_STARTUP_WARNING = Key event hook registration failed. You will not be able to set or use any of your hotkeys until this is fixed! To fix this, you will probably need to grant Llanfair some extended accessibility permissions from your operating system and then restart Llanfair.
# Settings > Header
setting_header_goal = Display Goal