Skip to content

Commit

Permalink
Clean up and clarify MapTool.showDocument()
Browse files Browse the repository at this point in the history
- Mention the threading requirements in the docs
- Check that the browse action is supported before we try to use it
- Avoid needlessly reparsing the URI
  • Loading branch information
kwvanderlinde committed Dec 1, 2024
1 parent 8582628 commit 9850eda
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,24 @@ public static BackupManager getBackupManager() {
* be called from any uncontrolled macros as there are both security and denial-of-service attacks
* possible.
*
* <p>This should not be called from any uncontrolled macros as there are both security and
* denial-of-service attacks possible.
*
* <p>This must be called on the AWT thread.
*
* @param url the URL to pass to the browser.
*/
public static void showDocument(String url) {
if (Desktop.isDesktopSupported()) {
String lowerCaseUrl = url.toLowerCase();
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
String urlToBrowse = url;
Desktop desktop = Desktop.getDesktop();
URI uri = null;
try {
uri = new URI(urlToBrowse);
if (uri.getScheme() == null) {
urlToBrowse = "https://" + urlToBrowse;
uri = new URI(urlToBrowse);
}
uri = new URI(urlToBrowse);
desktop.browse(uri);
} catch (Exception e) {
MapTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e);
Expand Down

0 comments on commit 9850eda

Please sign in to comment.