1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Allow Microsoft authentication to use xdg-open on Linux

This commit is contained in:
Henry Le Grys 2022-01-04 00:41:53 +00:00
parent 28017e8103
commit 291f62a4dc
2 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package com.skcraft.launcher.auth.microsoft; package com.skcraft.launcher.auth.microsoft;
import com.skcraft.launcher.auth.AuthenticationException; import com.skcraft.launcher.auth.AuthenticationException;
import com.skcraft.launcher.swing.SwingHelper;
import com.skcraft.launcher.util.HttpRequest; import com.skcraft.launcher.util.HttpRequest;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -30,7 +31,7 @@ public class MicrosoftWebAuthorizer {
private OauthResult authorizeInteractive() throws IOException, AuthenticationException, InterruptedException { private OauthResult authorizeInteractive() throws IOException, AuthenticationException, InterruptedException {
OauthHttpHandler httpHandler = new OauthHttpHandler(); OauthHttpHandler httpHandler = new OauthHttpHandler();
Desktop.getDesktop().browse(generateInteractiveUrl(httpHandler.getPort())); SwingHelper.openURL(generateInteractiveUrl(httpHandler.getPort()));
return httpHandler.await(); return httpHandler.await();
} }

View File

@ -35,6 +35,7 @@ import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
@ -104,16 +105,7 @@ public final class SwingHelper {
*/ */
public static void openURL(URL url, Component parentComponent) { public static void openURL(URL url, Component parentComponent) {
try { try {
Desktop.getDesktop().browse(url.toURI()); openURL(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);
}
}
} catch (IOException e) { } catch (IOException e) {
showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), SharedLocale.tr("errorTitle")); showErrorDialog(parentComponent, tr("errors.openUrlError", url.toString()), SharedLocale.tr("errorTitle"));
} catch (URISyntaxException e) { } 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 * Shows an popup error dialog, with potential extra details shown either immediately
* or available on the dialog. * or available on the dialog.