Skip to content

Commit

Permalink
Merge DesktopBrowser: add support for xdg-open directly, see #5
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2763 3d1905a2-6b24-0410-a738-b14d5a86fcbd
  • Loading branch information
mguessan committed Oct 24, 2018
1 parent b2526d7 commit eabef06
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/java/davmail/ui/browser/DesktopBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static void browse(URI location) {
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_OPEN_LINK"), e2);
}
}
} catch (java.lang.UnsupportedOperationException e) {
if (System.getProperty("os.name").toLowerCase().startsWith("linux")) {
try {
XdgDesktopBrowser.browse(location);
} catch (Exception e2) {
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_OPEN_LINK"), e2);
}
} else {
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_OPEN_LINK"), e);
}
} catch (Exception e) {
DavGatewayTray.error(new BundleMessage("LOG_UNABLE_TO_OPEN_LINK"), e);
}
Expand Down
41 changes: 41 additions & 0 deletions src/java/davmail/ui/browser/XdgDesktopBrowser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2009 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.ui.browser;

import java.io.IOException;
import java.net.URI;

/**
* Failover: Runtime.exec open URL
*/
public final class XdgDesktopBrowser {
private XdgDesktopBrowser() {
}

/**
* Open default browser at location URI.
* Use xdg-open to open browser url
*
* @param location location URI
* @throws IOException on error
*/
public static void browse(URI location) throws IOException {
Runtime.getRuntime().exec("xdg-open " + location.toString());
}
}

0 comments on commit eabef06

Please sign in to comment.