From e58706d212092f95d354c8b16fd68c4ac8cf6c96 Mon Sep 17 00:00:00 2001 From: Carl Andersson Date: Sun, 26 Dec 2021 06:05:27 +0100 Subject: [PATCH 1/3] Keybindings: Catch even more errors, and manually check that operating system is Windows --- build.gradle | 2 +- src/main/java/dev/slimevr/gui/Keybinding.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 8d4a29483..9b7a687ae 100644 --- a/build.gradle +++ b/build.gradle @@ -75,5 +75,5 @@ shadowJar { archiveVersion.set('') } application { - mainClassName = 'io.eiren.vr.Main' + mainClassName = 'dev.slimevr.Main' } diff --git a/src/main/java/dev/slimevr/gui/Keybinding.java b/src/main/java/dev/slimevr/gui/Keybinding.java index e80882eff..45c019f95 100644 --- a/src/main/java/dev/slimevr/gui/Keybinding.java +++ b/src/main/java/dev/slimevr/gui/Keybinding.java @@ -1,11 +1,12 @@ package dev.slimevr.gui; +import java.util.Locale; + +import com.melloware.jintellitype.HotkeyListener; import com.melloware.jintellitype.JIntellitype; import com.melloware.jintellitype.JIntellitypeException; import dev.slimevr.VRServer; - -import com.melloware.jintellitype.HotkeyListener; import io.eiren.util.ann.AWTThread; import io.eiren.util.logging.LogManager; @@ -18,6 +19,17 @@ public class Keybinding implements HotkeyListener { public Keybinding(VRServer server) { this.server = server; + try { + String osName = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); + if(!osName.contains("windows")) { + LogManager.log.info("[Keybinding] Currently only supported on Windows. Keybindings will be disabled."); + return; + } + } catch (SecurityException e) { + LogManager.log.info("[Keybinding] Can't check operating system name. Keybindings will be disabled."); + return; + } + try { if(JIntellitype.getInstance() instanceof JIntellitype) { JIntellitype.getInstance().addHotKeyListener(this); @@ -38,9 +50,7 @@ public class Keybinding implements HotkeyListener { JIntellitype.getInstance().registerHotKey(QUICK_RESET, quickResetBinding); LogManager.log.info("[Keybinding] Bound quick reset to " + quickResetBinding); } - } catch(JIntellitypeException je) { - LogManager.log.info("[Keybinding] JIntellitype initialization failed. Keybindings will be disabled. Try restarting your computer."); - } catch(ExceptionInInitializerError e) { + } catch(JIntellitypeException | ExceptionInInitializerError | UnsatisfiedLinkError e) { LogManager.log.info("[Keybinding] JIntellitype initialization failed. Keybindings will be disabled. Try restarting your computer."); } } From cee400a4c654e3ae377dec6cc50b9eadee92855f Mon Sep 17 00:00:00 2001 From: Carl Andersson Date: Sun, 26 Dec 2021 21:48:52 +0100 Subject: [PATCH 2/3] Simplify OS & error checks --- src/main/java/dev/slimevr/gui/Keybinding.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/slimevr/gui/Keybinding.java b/src/main/java/dev/slimevr/gui/Keybinding.java index 45c019f95..7d5e3aea5 100644 --- a/src/main/java/dev/slimevr/gui/Keybinding.java +++ b/src/main/java/dev/slimevr/gui/Keybinding.java @@ -1,12 +1,10 @@ package dev.slimevr.gui; -import java.util.Locale; - import com.melloware.jintellitype.HotkeyListener; import com.melloware.jintellitype.JIntellitype; -import com.melloware.jintellitype.JIntellitypeException; import dev.slimevr.VRServer; +import io.eiren.util.OperatingSystem; import io.eiren.util.ann.AWTThread; import io.eiren.util.logging.LogManager; @@ -19,14 +17,8 @@ public class Keybinding implements HotkeyListener { public Keybinding(VRServer server) { this.server = server; - try { - String osName = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); - if(!osName.contains("windows")) { - LogManager.log.info("[Keybinding] Currently only supported on Windows. Keybindings will be disabled."); - return; - } - } catch (SecurityException e) { - LogManager.log.info("[Keybinding] Can't check operating system name. Keybindings will be disabled."); + if (OperatingSystem.getCurrentPlatform() == OperatingSystem.WINDOWS) { + LogManager.log.info("[Keybinding] Currently only supported on Windows. Keybindings will be disabled."); return; } @@ -50,7 +42,7 @@ public class Keybinding implements HotkeyListener { JIntellitype.getInstance().registerHotKey(QUICK_RESET, quickResetBinding); LogManager.log.info("[Keybinding] Bound quick reset to " + quickResetBinding); } - } catch(JIntellitypeException | ExceptionInInitializerError | UnsatisfiedLinkError e) { + } catch(Throwable e) { LogManager.log.info("[Keybinding] JIntellitype initialization failed. Keybindings will be disabled. Try restarting your computer."); } } From bdc3b1971c35269b167d7d687132048498a458cd Mon Sep 17 00:00:00 2001 From: Carl Andersson Date: Sun, 26 Dec 2021 21:49:46 +0100 Subject: [PATCH 3/3] Fix accidental inversion of check --- src/main/java/dev/slimevr/gui/Keybinding.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/slimevr/gui/Keybinding.java b/src/main/java/dev/slimevr/gui/Keybinding.java index 7d5e3aea5..0bc5afe0c 100644 --- a/src/main/java/dev/slimevr/gui/Keybinding.java +++ b/src/main/java/dev/slimevr/gui/Keybinding.java @@ -17,7 +17,7 @@ public class Keybinding implements HotkeyListener { public Keybinding(VRServer server) { this.server = server; - if (OperatingSystem.getCurrentPlatform() == OperatingSystem.WINDOWS) { + if (OperatingSystem.getCurrentPlatform() != OperatingSystem.WINDOWS) { LogManager.log.info("[Keybinding] Currently only supported on Windows. Keybindings will be disabled."); return; }