From 71f1b3c1304f1f8ce180bc4e6cee2ea87be03db0 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 26 Apr 2018 12:45:02 -0400 Subject: [PATCH] Better exception logging to avoid hiding class initialization exceptions. --- .../java/com/lyndir/masterpassword/gui/GUI.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java index 89fc71d5..6c034fc0 100644 --- a/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java +++ b/platform-independent/gui-java/src/main/java/com/lyndir/masterpassword/gui/GUI.java @@ -19,7 +19,7 @@ package com.lyndir.masterpassword.gui; -import com.google.common.base.Charsets; +import com.google.common.base.*; import com.google.common.io.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.TypeUtils; @@ -27,6 +27,7 @@ import com.lyndir.lhunath.opal.system.util.TypeUtils; import com.lyndir.masterpassword.gui.view.PasswordFrame; import com.lyndir.masterpassword.gui.view.UnlockFrame; import java.io.*; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URL; import java.util.Enumeration; @@ -48,17 +49,27 @@ public class GUI implements UnlockFrame.SignInCallback { private PasswordFrame passwordFrame; public static void main(final String... args) { - if (Config.get().checkForUpdates()) checkUpdate(); + // Try and set the system look & feel, if available. try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) { } - TypeUtils.newInstance( "com.lyndir.masterpassword.gui.platform.mac.AppleGUI" ).or( new GUI() ).open(); + try { + // AppleGUI adds support for macOS features. + Optional> appleGUI = TypeUtils.loadClass( "com.lyndir.masterpassword.gui.platform.mac.AppleGUI" ); + if (appleGUI.isPresent()) + appleGUI.get().getConstructor().newInstance().open(); + + else // No special platform handling. + new GUI().open(); + } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { + throw logger.bug( e ); + } } private static void checkUpdate() {