From 1c60bf383ca9e8df1498af062f3703bb3d24d762 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 16 Apr 2016 13:03:41 +0200 Subject: [PATCH] Fix bug on linux when using mailto --- .../io/bitsquare/common/util/Utilities.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/io/bitsquare/common/util/Utilities.java b/common/src/main/java/io/bitsquare/common/util/Utilities.java index 156ca66f14..649099c33a 100644 --- a/common/src/main/java/io/bitsquare/common/util/Utilities.java +++ b/common/src/main/java/io/bitsquare/common/util/Utilities.java @@ -135,15 +135,6 @@ public class Utilities { } } - public static void openWebPage(String target) { - try { - openURI(new URI(target)); - } catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - } - } - public static void openDirectory(File directory) throws IOException { if (!isLinux() && Desktop.isDesktopSupported() @@ -160,6 +151,26 @@ public class Utilities { throw new IOException("Failed to open directory: " + directory.toString()); } } + + public static void openWebPage(String target) { + try { + openURI(new URI(target)); + } catch (Exception e) { + e.printStackTrace(); + log.error(e.getMessage()); + } + } + + public static void openMail(String to, String subject, String body) { + try { + subject = URLEncoder.encode(subject, "UTF-8").replace("+", "%20"); + body = URLEncoder.encode(body, "UTF-8").replace("+", "%20"); + openURI(new URI("mailto:" + to + "?subject=" + subject + "&body=" + body)); + } catch (IOException | URISyntaxException e) { + log.error("openMail failed " + e.getMessage()); + e.printStackTrace(); + } + } public static void printSystemLoad() { Runtime runtime = Runtime.getRuntime(); @@ -169,22 +180,17 @@ public class Utilities { log.info("System load (nr. threads/used memory (MB)): " + Thread.activeCount() + "/" + used); } - public static void openMail(String to, String subject, String body) { - try { - subject = URLEncoder.encode(subject, "UTF-8").replace("+", "%20"); - body = URLEncoder.encode(body, "UTF-8").replace("+", "%20"); - Desktop.getDesktop().mail(new URI("mailto:" + to + "?subject=" + subject + "&body=" + body)); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } - } - public static void copyToClipboard(String content) { - if (content != null && content.length() > 0) { - Clipboard clipboard = Clipboard.getSystemClipboard(); - ClipboardContent clipboardContent = new ClipboardContent(); - clipboardContent.putString(content); - clipboard.setContent(clipboardContent); + try { + if (content != null && content.length() > 0) { + Clipboard clipboard = Clipboard.getSystemClipboard(); + ClipboardContent clipboardContent = new ClipboardContent(); + clipboardContent.putString(content); + clipboard.setContent(clipboardContent); + } + } catch (Throwable e) { + log.error("copyToClipboard failed " + e.getMessage()); + e.printStackTrace(); } }