diff --git a/src/main/java/mpo/dayon/assistant/network/NetworkAssistantEngine.java b/src/main/java/mpo/dayon/assistant/network/NetworkAssistantEngine.java index f31fb159..f5417d59 100644 --- a/src/main/java/mpo/dayon/assistant/network/NetworkAssistantEngine.java +++ b/src/main/java/mpo/dayon/assistant/network/NetworkAssistantEngine.java @@ -80,7 +80,7 @@ public boolean selfTest(String publicIp) { } Log.info("Port " + configuration.getPort() + " is reachable from the outside"); } catch (IOException e) { - Log.error("Port " + configuration.getPort() + " is not reachable from the outside"); + Log.warn("Port " + configuration.getPort() + " is not reachable from the outside"); return false; } } diff --git a/src/main/java/mpo/dayon/assisted/gui/Assisted.java b/src/main/java/mpo/dayon/assisted/gui/Assisted.java index 3ae016ec..843326bb 100644 --- a/src/main/java/mpo/dayon/assisted/gui/Assisted.java +++ b/src/main/java/mpo/dayon/assisted/gui/Assisted.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; +import static java.awt.event.KeyEvent.VK_CAPS_LOCK; import static java.lang.String.format; import static java.lang.String.valueOf; import static mpo.dayon.common.babylon.Babylon.translate; @@ -332,6 +333,25 @@ private static NetworkAssistedEngineConfiguration extractConfiguration(String co return null; } + private void capsOff() { + if (Toolkit.getDefaultToolkit().getLockingKeyState(VK_CAPS_LOCK)) { + Log.info("Caps Lock is on, turning it off"); + try { + Toolkit.getDefaultToolkit().setLockingKeyState(VK_CAPS_LOCK, false); + } catch (UnsupportedOperationException e) { + final Robot robot; + try { + robot = new Robot(); + } catch (AWTException ex) { + throw new IllegalStateException("Could not initialize the AWT robot!", ex); + } + robot.keyPress(VK_CAPS_LOCK); + robot.delay(10); + robot.keyRelease(VK_CAPS_LOCK); + } + } + } + @Override public void lostOwnership(Clipboard clipboard, Transferable transferable) { Log.debug("Lost clipboard ownership"); @@ -422,6 +442,7 @@ private class MyNetworkAssistedEngineListener implements NetworkAssistedEngineLi @Override public void onConnecting(String serverName, int serverPort) { + capsOff(); frame.onConnecting(serverName, serverPort); } diff --git a/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java b/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java index c416cfd3..4e73ba6b 100644 --- a/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java +++ b/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java @@ -27,6 +27,7 @@ import mpo.dayon.common.version.Version; import static java.awt.GridBagConstraints.HORIZONTAL; +import static java.awt.event.KeyEvent.VK_CAPS_LOCK; import static java.lang.String.format; import static mpo.dayon.common.babylon.Babylon.translate; import static mpo.dayon.common.configuration.Configuration.DEFAULT_TOKEN_SERVER_URL; @@ -138,7 +139,11 @@ protected void setupStatusBar(StatusBar statusBar) { add(statusBar, BorderLayout.SOUTH); this.statusBar = statusBar; updateInputLocale(); - new Timer(5000, e -> updateInputLocale()).start(); + updateCapsLockState(); + new Timer(3000, e -> { + updateInputLocale(); + updateCapsLockState(); + }).start(); } private void updateInputLocale() { @@ -148,6 +153,13 @@ private void updateInputLocale() { } } + private void updateCapsLockState() { + boolean currentCapsLockState = Toolkit.getDefaultToolkit().getLockingKeyState(VK_CAPS_LOCK); + if (currentCapsLockState != statusBar.isCapsLockOn()) { + statusBar.setCapsLockIndicator(currentCapsLockState); + } + } + protected static JButton createButton(Action action) { return createButton(action, true); } diff --git a/src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java b/src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java index 983f7a4f..97f94bce 100644 --- a/src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java +++ b/src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java @@ -19,6 +19,7 @@ public class StatusBar extends JPanel { private final JLabel message = new JLabel(); private final JLabel sessionDuration = new JLabel("00:00:00"); private final JLabel keyboardLayout = new JLabel(); + private final JLabel capsLockIndicator = new JLabel(); public StatusBar() { setLayout(new BoxLayout(this, LINE_AXIS)); @@ -27,6 +28,7 @@ public StatusBar() { add(Box.createHorizontalGlue()); addSeparator(); addKeyboardLayout(); + addCapsLockIndicator(); } public void clearMessage() { @@ -54,6 +56,19 @@ private void addKeyboardLayout() { add(keyboardLayout); } + private void addCapsLockIndicator() { + add(capsLockIndicator); + } + + public boolean isCapsLockOn() { + return !capsLockIndicator.getText().isBlank(); + } + + public void setCapsLockIndicator(boolean isCapsLockOn) { + capsLockIndicator.setText(isCapsLockOn ? " ⛰ " : ""); + capsLockIndicator.setToolTipText("Caps Lock"); + } + public void addCounter(Counter counter, int width) { JLabel label = createLabel(counter.getUid(), width); label.setToolTipText(counter.getShortDescription());