Ticket #16891: 16891v2.patch
| File 16891v2.patch, 5.2 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/tools/OpenBrowser.java
diff --git a/src/org/openstreetmap/josm/tools/OpenBrowser.java b/src/org/openstreetmap/josm/tools/OpenBrowser.java index 083de23d1..311f52d50 100644
a b private OpenBrowser() { 21 21 // Hide default constructor for utils classes 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. 32 26 * A web resource will launch platform's browser, an audio file URI will launch audio player, etc. … … public static String displayUrl(URI uri) { 40 34 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(); 66 } 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(); 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); 74 47 } 48 } catch (IOException e) { 49 Logging.warn(e); 50 return e.getMessage(); 75 51 } 76 52 return null; 77 53 } -
src/org/openstreetmap/josm/tools/PlatformHookWindows.java
diff --git a/src/org/openstreetmap/josm/tools/PlatformHookWindows.java b/src/org/openstreetmap/josm/tools/PlatformHookWindows.java index 2a9d46f35..aff4869f4 100644
a b 30 30 import static org.openstreetmap.josm.tools.Utils.getSystemProperty; 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; 35 36 import java.io.File; … … 39 40 import java.io.OutputStreamWriter; 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; 44 47 import java.nio.file.DirectoryStream; … … public void startupHook(JavaExpirationCallback callback) { 187 190 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 193 207 @Override
