Skip to content

Commit 2209928

Browse files
committed
Implement support for opening URLs on macOS in BrowserHelper; add isMacOS method in OS class
1 parent a40c11f commit 2209928

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/main/java/de/doubleslash/keeptime/common/BrowserHelper.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,29 @@ public static void openURL(final String url) {
3434
openUrlWindows(rt, url);
3535
} else if (OS.isLinux()) {
3636
openUrlLinux(rt, url);
37+
} else if (OS.isMacOS()) {
38+
openUrlMac(rt, url);
3739
} else {
38-
// TODO implement for MAC
3940
LOG.warn("OS '{}' is not supported", OS.getOSName());
4041
}
4142
}
4243

4344
private static void openUrlWindows(final Runtime rt, final String url) {
4445
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
46+
executeCommand(rt, command, url);
47+
}
48+
49+
private static void openUrlLinux(final Runtime rt, final String url) {
50+
final String[] command = {"xdg-open", url};
51+
executeCommand(rt, command, url);
52+
}
53+
54+
private static void openUrlMac(final Runtime rt, final String url) {
55+
final String[] command = {"open", url};
56+
executeCommand(rt, command, url);
57+
}
58+
59+
private static void executeCommand(final Runtime rt, final String command, final String url) {
4560
try {
4661
LOG.debug("Executing command: {}", command);
4762
rt.exec(command);
@@ -50,13 +65,10 @@ private static void openUrlWindows(final Runtime rt, final String url) {
5065
}
5166
}
5267

53-
private static void openUrlLinux(final Runtime rt, final String url) {
54-
final String[] command = {
55-
"xdg-open", url
56-
};
68+
private static void executeCommand(final Runtime rt, final String[] command, final String url) {
5769
try {
5870
LOG.debug("Executing command: {}", Arrays.toString(command));
59-
rt.exec(command);
71+
rt.exec(command);
6072
} catch (final Exception e) {
6173
LOG.error("Could not open url '{}' with command '{}'.", url, Arrays.toString(command), e);
6274
}

src/main/java/de/doubleslash/keeptime/common/OS.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ public static String getOSName() {
3636
return System.getProperty(OS_PROPERTY);
3737
}
3838

39+
public static boolean isMacOS() {
40+
return getOSName().toLowerCase().contains("mac os x");
41+
}
42+
3943
}

0 commit comments

Comments
 (0)