Skip to content

Commit

Permalink
- fixes #752
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed Oct 18, 2024
1 parent 07e9078 commit d652501
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ShowOnlineHelpAction() {

private void openUrl() {
try {
UrlHyperlinkAction.openURL(null, Konstanten.ADRESSE_ONLINE_HELP);
UrlHyperlinkAction.openURL(Konstanten.ADRESSE_ONLINE_HELP);
} catch (URISyntaxException ex) {
logger.warn(ex);
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/mediathek/gui/actions/UrlHyperlinkAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mediathek.config.MVConfig;
import mediathek.gui.dialog.DialogProgrammOrdnerOeffnen;
import mediathek.gui.messages.ProgramLocationChangedEvent;
import mediathek.mainwindow.MediathekGui;
import mediathek.tool.MessageBus;
import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.LogManager;
Expand All @@ -18,20 +19,17 @@

public class UrlHyperlinkAction extends AbstractAction {

private final JFrame jFrameParent;

public UrlHyperlinkAction(JFrame jjFrameParent, String url) {
jFrameParent = jjFrameParent;
public UrlHyperlinkAction(String url) {
super.putValue(Action.NAME, url);
super.putValue(SHORT_DESCRIPTION, url);
}

private static void configureAndStartCustomWebBrowser(JFrame paFrame, String url) {
private static void configureAndStartCustomWebBrowser(String url) {
try {
String programm = "";
if (MVConfig.get(MVConfig.Configs.SYSTEM_URL_OEFFNEN).isEmpty()) {
String text = "\n Der Browser zum Anzeigen der URL wird nicht gefunden.\n Browser selbst auswählen.";
DialogProgrammOrdnerOeffnen dialog = new DialogProgrammOrdnerOeffnen(paFrame, true, "", "Browser suchen", text);
DialogProgrammOrdnerOeffnen dialog = new DialogProgrammOrdnerOeffnen(MediathekGui.ui(), true, "", "Browser suchen", text);
dialog.setVisible(true);
if (dialog.ok) {
programm = dialog.ziel;
Expand Down Expand Up @@ -66,17 +64,16 @@ private static void launchMacDefaultBrowser(String url) throws IOException {

private static final Logger logger = LogManager.getLogger(UrlHyperlinkAction.class);

public static void openURI(@NotNull JFrame parent, @NotNull URI uri) throws URISyntaxException {
openURL(parent, uri.toString());
public static void openURI(@NotNull URI uri) throws URISyntaxException {
openURL(uri.toString());
}
/**
* Try to open a browser window.
*
* @param paFrame the parent window.
* @param url URL to be opened. Here in string format.
* @throws URISyntaxException when URL is malformed.
*/
public static void openURL(JFrame paFrame, String url) throws URISyntaxException {
public static void openURL(String url) throws URISyntaxException {
boolean launchFailed = false;

if (SystemUtils.IS_OS_MAC_OSX) {
Expand Down Expand Up @@ -110,18 +107,18 @@ public static void openURL(JFrame paFrame, String url) throws URISyntaxException
} else {
logger.trace("trying to launch custom web browser");
//Desktop not supported, we need to work custom
configureAndStartCustomWebBrowser(paFrame, url);
configureAndStartCustomWebBrowser(url);
}
}

if (launchFailed)
configureAndStartCustomWebBrowser(paFrame,url);
configureAndStartCustomWebBrowser(url);
}

@Override
public void actionPerformed(ActionEvent e) {
try {
openURL(jFrameParent, e.getActionCommand());
openURL(e.getActionCommand());
} catch (URISyntaxException ignored) {
}
}
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/mediathek/gui/dialog/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package mediathek.gui.dialog;

import mediathek.config.Konstanten;
import mediathek.gui.actions.UrlHyperlinkAction;
import net.miginfocom.layout.AC;
import net.miginfocom.layout.CC;
import net.miginfocom.layout.LC;
Expand All @@ -15,7 +16,7 @@

import javax.swing.*;
import java.awt.*;
import java.net.URI;
import java.net.URISyntaxException;

/**
* @author Christian Franzke
Expand Down Expand Up @@ -48,20 +49,9 @@ private void showError() {
}

private void browseToUrl(@NotNull String url) {
if (Desktop.isDesktopSupported()) {
var desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URI(url));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
else {
showError();
}
}
else {
try {
UrlHyperlinkAction.openURL(url);
} catch (URISyntaxException e) {
showError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void saveLocation() {

private void openUrl(String url) {
try {
UrlHyperlinkAction.openURL(null, url);
UrlHyperlinkAction.openURL(url);
} catch (URISyntaxException ex) {
logger.warn(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void setAllFieldsEmpty() {

private void openUrl(String url) {
try {
UrlHyperlinkAction.openURL(null, url);
UrlHyperlinkAction.openURL(url);
} catch (URISyntaxException ex) {
logger.warn(ex);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mediathek/gui/tabs/tab_film/GuiFilme.java
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ private void setupSearchEntries(@NotNull JPopupMenu popupMenu, @NotNull DatenFil
miThema.addActionListener(l -> {
var url = item.getQueryUrl() + URLEncoder.encode(film.getThema(), StandardCharsets.UTF_8);
try {
UrlHyperlinkAction.openURL(MediathekGui.ui(), url);
UrlHyperlinkAction.openURL(url);
} catch (URISyntaxException ex) {
logger.error("Failed to launch online search for url {}", url);
}
Expand All @@ -1566,7 +1566,7 @@ private void setupSearchEntries(@NotNull JPopupMenu popupMenu, @NotNull DatenFil
miTitel.addActionListener(l -> {
var url = item.getQueryUrl() + URLEncoder.encode(film.getTitle(), StandardCharsets.UTF_8);
try {
UrlHyperlinkAction.openURL(MediathekGui.ui(), url);
UrlHyperlinkAction.openURL(url);
} catch (URISyntaxException ex) {
logger.error("Failed to launch online search for url {}", url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void hyperLinkSelected(Event e) {
String url = tbBookmarks.getSelectionModel().getSelectedItem().getWebUrl();
try {
if (url != null) {
UrlHyperlinkAction.openURL(null,url);
UrlHyperlinkAction.openURL(url);
}
}
catch (URISyntaxException ex) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mediathek/update/DialogHinweisUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public DialogHinweisUpdate(JFrame parent, String ttext) {

hyperLink.addActionListener(l -> {
try {
UrlHyperlinkAction.openURL(parent, Konstanten.ADRESSE_DOWNLOAD);
UrlHyperlinkAction.openURL(Konstanten.ADRESSE_DOWNLOAD);
} catch (URISyntaxException ex) {
logger.error(ex);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mediathek/update/UpdateNotificationDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import mediathek.gui.actions.DisposeDialogAction
import mediathek.gui.actions.UrlHyperlinkAction
import mediathek.gui.dialog.ButtonFlowPanel
import mediathek.gui.dialog.ButtonPanel
import mediathek.mainwindow.MediathekGui
import mediathek.tool.EscapeKeyHandler
import mediathek.tool.GuiFunktionen
import mediathek.tool.Version
Expand All @@ -26,7 +25,7 @@ class UpdateNotificationDialog(owner: Frame?, title: String?, private val versio
val dlBtn = JButton("Zur Download-Seite")
dlBtn.addActionListener {
try {
UrlHyperlinkAction.openURI(MediathekGui.ui(), URI(Konstanten.ADRESSE_DOWNLOAD))
UrlHyperlinkAction.openURI(URI(Konstanten.ADRESSE_DOWNLOAD))
dispose()
} catch (e: URISyntaxException) {
logger.error(e)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/mediathek/mainwindow/AustrianVlcCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AustrianVlcCheck(val owner: JFrame) {
if (e.eventType == HyperlinkEvent.EventType.ACTIVATED) {
try {
ApplicationConfiguration.getConfiguration().setProperty(ApplicationConfiguration.APPLICATION_SHOW_ORF_CONFIG_HELP, false)
UrlHyperlinkAction.openURL(MediathekGui.ui(), Konstanten.ORF_TUTORIAL_LINK)
UrlHyperlinkAction.openURL(Konstanten.ORF_TUTORIAL_LINK)
} catch (ex: Exception) {
logger.error("Failed to display ORF tutorial", ex)
}
Expand Down

0 comments on commit d652501

Please sign in to comment.