Changeset 14389 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-10-30T23:07:31+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java
r14146 r14389 22 22 } 23 23 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 30 24 /** 31 25 * Displays an external URI using platform associated software. … … 41 35 Logging.info(tr("Opening URL: {0}", uri)); 42 36 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); 66 47 } 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(); 75 51 } 76 52 return null; -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r14368 r14389 31 31 import static org.openstreetmap.josm.tools.WinRegistry.HKEY_LOCAL_MACHINE; 32 32 33 import java.awt.Desktop; 33 34 import java.awt.GraphicsEnvironment; 34 35 import java.io.BufferedWriter; … … 40 41 import java.io.Writer; 41 42 import java.lang.reflect.InvocationTargetException; 43 import java.net.URI; 44 import java.net.URISyntaxException; 42 45 import java.nio.charset.StandardCharsets; 43 46 import java.nio.file.DirectoryIteratorException; … … 188 191 @Override 189 192 public void openUrl(String url) throws IOException { 190 Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); 193 final String customBrowser = Config.getPref().get("browser.windows", null); 194 if (customBrowser != null) { 195 Runtime.getRuntime().exec(new String[]{customBrowser, url}); 196 return; 197 } 198 try { 199 // Desktop API works fine under Windows 200 Desktop.getDesktop().browse(new URI(url)); 201 } catch (IOException | URISyntaxException e) { 202 Logging.log(Logging.LEVEL_WARN, "Desktop class failed. Platform dependent fall back for open url in browser.", e); 203 Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); 204 } 191 205 } 192 206
Note:
See TracChangeset
for help on using the changeset viewer.