Ignore:
Timestamp:
2018-10-30T23:07:31+01:00 (5 years ago)
Author:
simon04
Message:

fix #16891 - Allow to override default web browser on Windows

Set the advanced preference key browser.windows to the browser executable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java

    r14146 r14389  
    2222    }
    2323
    24     private static void displayUrlFallback(URI uri) throws IOException {
    25         if (PlatformManager.getPlatform() == null)
    26             throw new IllegalStateException(tr("Failed to open URL. There is currently no platform set. Please set a platform first."));
    27         PlatformManager.getPlatform().openUrl(uri.toString());
    28     }
    29 
    3024    /**
    3125     * Displays an external URI using platform associated software.
     
    4135        Logging.info(tr("Opening URL: {0}", uri));
    4236
    43         if (Desktop.isDesktopSupported()) {
    44             try {
    45                 if (PlatformManager.isPlatformWindows()) {
    46                     // Desktop API works fine under Windows, so we don't try any fallback in case of I/O exceptions because it's not API's fault
    47                     Desktop.getDesktop().browse(uri);
    48                 } else if (PlatformManager.isPlatformUnixoid() || PlatformManager.isPlatformOsx()) {
    49                     // see #5629 #5108 #9568
    50                     PlatformManager.getPlatform().openUrl(uri.toString());
    51                 } else {
    52                     // This is not the case with some Linux environments (see below),
    53                     // and not sure about Mac OS X, so we need to handle API failure
    54                     try {
    55                         Desktop.getDesktop().browse(uri);
    56                     } catch (IOException e) {
    57                         // Workaround for KDE (Desktop API is severely flawed)
    58                         // see https://bugs.openjdk.java.net/browse/JDK-6486393
    59                         Logging.log(Logging.LEVEL_WARN, "Desktop class failed. Platform dependent fall back for open url in browser.", e);
    60                         displayUrlFallback(uri);
    61                     }
    62                 }
    63             } catch (IOException e) {
    64                 Logging.warn(e);
    65                 return e.getMessage();
     37        try {
     38            if (PlatformManager.getPlatform() != null) {
     39                // see #5629 #5108 #9568
     40                PlatformManager.getPlatform().openUrl(uri.toString());
     41            } else if (Desktop.isDesktopSupported()) {
     42                // This is not the case with some Linux environments (see below),
     43                // and not sure about Mac OS X, so we need to handle API failure
     44                Desktop.getDesktop().browse(uri);
     45            } else {
     46                Logging.warn("Neither Platform nor Desktop class is not supported. Cannot open " + uri);
    6647            }
    67         } else {
    68             try {
    69                 Logging.warn("Desktop class is not supported. Platform dependent fall back for open url in browser.");
    70                 displayUrlFallback(uri);
    71             } catch (IOException e) {
    72                 Logging.debug(e);
    73                 return e.getMessage();
    74             }
     48        } catch (IOException e) {
     49            Logging.warn(e);
     50            return e.getMessage();
    7551        }
    7652        return null;
Note: See TracChangeset for help on using the changeset viewer.