immediately close app if registration fails. resolves #10

This commit is contained in:
Gered 2016-01-03 13:26:49 -05:00
parent 1bd79efe32
commit 234f899020
4 changed files with 23 additions and 21 deletions

View file

@ -50,8 +50,7 @@ public enum Language {
setting_hotkey_stop,
setting_hotkey_pause,
setting_hotkey_lock,
GLOBAL_HOTKEYS_WARNING,
GLOBAL_HOTKEYS_STARTUP_WARNING,
GLOBAL_HOTKEYS_STARTUP_ERROR,
// Settings > Header
setting_header_goal,

View file

@ -82,7 +82,11 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
actions = new Actions( this );
setMenu();
setBehavior();
boolean behaviourSucceed = setBehavior();
if (!behaviourSucceed)
return;
setRun( run );
setVisible( true );
@ -450,13 +454,27 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
*
* @throws IllegalStateException if JNativeHook cannot be registered.
*/
private void setBehavior() {
registerNativeKeyHook();
private boolean setBehavior() {
boolean registered = registerNativeKeyHook();
if (!registered) {
// NOTE: in the event of a failure, JNativeHook now has some ability (on some OS's at least)
// 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_STARTUP_ERROR, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
this.dispose();
return false;
}
setAlwaysOnTop(Settings.alwaysOnTop.get());
addWindowListener(this);
addMouseWheelListener(this);
Settings.addPropertyChangeListener(this);
GlobalScreen.addNativeKeyListener(this);
return true;
}
/**
@ -477,12 +495,6 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
GlobalScreen.registerNativeHook();
return true;
} catch (NativeHookException e) {
// NOTE: in the event of a failure, JNativeHook now has some ability (on some OS's at least)
// 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

@ -23,8 +23,6 @@ class TabHotkeys extends SettingsTab {
private JCheckBox globalHotKeys;
private JLabel globalHotKeysHookWarning;
/**
* List of all key fields customizable by the user.
*/
@ -50,9 +48,6 @@ class TabHotkeys extends SettingsTab {
public void actionPerformed(ActionEvent e) { Settings.useGlobalHotkeys.set(globalHotKeys.isSelected()); }
});
globalHotKeysHookWarning = new JLabel("" + Language.GLOBAL_HOTKEYS_WARNING);
globalHotKeysHookWarning.setForeground(Color.RED);
keyFields = new ArrayList<KeyField>();
keyLabels = new ArrayList<JLabel>();
@ -97,9 +92,6 @@ class TabHotkeys extends SettingsTab {
}
add(globalHotKeys, GBC.grid(2, 3).insets(0, 50, 0, 0).anchor(GBC.LS));
if (GlobalScreen.isNativeHookRegistered())
add(globalHotKeysHookWarning, GBC.grid(0, row + 1, 3, 1).insets(10, 0, 10, 0));
}
// --------------------------------------------------------- INTERNAL TYPES

View file

@ -31,8 +31,7 @@ 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> 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.
GLOBAL_HOTKEYS_STARTUP_ERROR = <html><div style="width: 300px;">Key event hook registration failed.<br /><br />Llanfair requires global access to key events which (depending on your OS) might require some extra security or accessibility permissions. Click the "OK" button to close Llanfair. You will need to grant the required permissions before you will be able to use Llanfair.<br /><br />Your OS might have just now popped up some sort of notification which will allow you to quickly grant Llanfair the required permissions.</div></html>
# Settings > Header
setting_header_goal = Display Goal