diff --git a/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MicrosoftWebAuthorizer.java b/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MicrosoftWebAuthorizer.java index eb07245..a4d7953 100644 --- a/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MicrosoftWebAuthorizer.java +++ b/launcher/src/main/java/com/skcraft/launcher/auth/microsoft/MicrosoftWebAuthorizer.java @@ -1,6 +1,7 @@ package com.skcraft.launcher.auth.microsoft; import com.skcraft.launcher.auth.AuthenticationException; +import com.skcraft.launcher.swing.SwingHelper; import com.skcraft.launcher.util.HttpRequest; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -30,7 +31,7 @@ public class MicrosoftWebAuthorizer { private OauthResult authorizeInteractive() throws IOException, AuthenticationException, InterruptedException { OauthHttpHandler httpHandler = new OauthHttpHandler(); - Desktop.getDesktop().browse(generateInteractiveUrl(httpHandler.getPort())); + SwingHelper.openURL(generateInteractiveUrl(httpHandler.getPort())); return httpHandler.await(); } diff --git a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java index 8024e0b..b8239df 100644 --- a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java +++ b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java @@ -35,6 +35,7 @@ import java.awt.image.BufferedImage; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.List; @@ -104,16 +105,7 @@ public final class SwingHelper { */ public static void openURL(URL url, Component parentComponent) { try { - Desktop.getDesktop().browse(url.toURI()); - } catch (UnsupportedOperationException e) { - if (Environment.detectPlatform() == Platform.LINUX) { - // Try xdg-open instead - try { - Runtime.getRuntime().exec(new String[]{"xdg-open", url.toString()}); - } catch (IOException ex) { - showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), tr("errorTitle"), ex); - } - } + openURL(url.toURI()); } catch (IOException e) { showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), SharedLocale.tr("errorTitle")); } catch (URISyntaxException e) { @@ -121,6 +113,17 @@ public final class SwingHelper { } } + public static void openURL(URI url) throws IOException { + try { + Desktop.getDesktop().browse(url); + } catch (UnsupportedOperationException e) { + if (Environment.detectPlatform() == Platform.LINUX) { + // Try xdg-open instead + Runtime.getRuntime().exec(new String[]{"xdg-open", url.toString()}); + } + } + } + /** * Shows an popup error dialog, with potential extra details shown either immediately * or available on the dialog.