Skip to content

Commit ae7e070

Browse files
authored
Merge pull request #26 from doubleSlashde/feature/alert_if_license_is_missing
Feature/alert if license is missing
2 parents d7276d0 + 48d510a commit ae7e070

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package de.doubleslash.keeptime.common;
1818

19+
import java.util.Arrays;
20+
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
2123

@@ -29,33 +31,33 @@ public static void openURL(final String url) {
2931
final Runtime rt = Runtime.getRuntime();
3032

3133
if (OS.isWindows()) {
32-
executeCommandWindows(rt, url);
34+
openUrlWindows(rt, url);
3335
} else if (OS.isLinux()) {
34-
executeCommandLinux(rt, url);
36+
openUrlLinux(rt, url);
3537
} else {
3638
LOG.warn("OS is not supported");
3739
}
3840
}
3941

40-
private static void executeCommandWindows(final Runtime rt, final String url) {
42+
private static void openUrlWindows(final Runtime rt, final String url) {
43+
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
4144
try {
42-
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
43-
LOG.debug("execute command: {}", command);
44-
45+
LOG.debug("Executing command: {}", command);
4546
rt.exec(command);
4647
} catch (final Exception e) {
47-
LOG.error(e.getMessage());
48+
LOG.error("Could not open url '" + url + "' with command '" + command + "'.", e);
4849
}
4950
}
5051

51-
private static void executeCommandLinux(final Runtime rt, final String url) {
52+
private static void openUrlLinux(final Runtime rt, final String url) {
53+
final String[] command = {
54+
"xdg-open", url
55+
};
5256
try {
53-
final String command = "xdg-open " + url;
54-
LOG.debug("execute command: {}", command);
55-
57+
LOG.debug("Executing command: {}", Arrays.toString(command));
5658
rt.exec(command);
5759
} catch (final Exception e) {
58-
LOG.warn(e.getMessage());
60+
LOG.error("Could not open url '" + url + "' with command '" + Arrays.toString(command) + "'.", e);
5961
}
6062
}
6163
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package de.doubleslash.keeptime.common;
1818

1919
import java.io.File;
20+
import java.util.Arrays;
2021

2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -27,15 +28,15 @@ public class FileOpenHelper {
2728

2829
private FileOpenHelper() {}
2930

30-
public static boolean openFile(final String fileString) {
31-
final File file = new File(fileString);
31+
public static boolean openFile(final String filePath) {
32+
final File file = new File(filePath);
3233
final Runtime rt = Runtime.getRuntime();
3334

3435
if (file.exists() && file.isFile()) {
3536
if (OS.isWindows()) {
36-
executeCommandWindows(rt, file);
37+
openFileWindows(rt, file);
3738
} else if (OS.isLinux()) {
38-
executeCommandLinux(rt, file);
39+
openFileLinux(rt, filePath);
3940
} else {
4041
LOG.warn("OS is not supported");
4142
}
@@ -45,25 +46,25 @@ public static boolean openFile(final String fileString) {
4546
}
4647
}
4748

48-
private static void executeCommandWindows(final Runtime rt, final File file) {
49+
private static void openFileWindows(final Runtime rt, final File file) {
50+
final String command = "rundll32 url.dll,FileProtocolHandler " + file;
4951
try {
50-
final String command = "rundll32 url.dll,FileProtocolHandler " + file;
5152
LOG.debug("executing command: {}", command);
52-
5353
rt.exec(command);
5454
} catch (final Exception e) {
55-
LOG.error(e.getMessage());
55+
LOG.error("Could not open file '" + file + "' with command '" + command + "'.", e);
5656
}
5757
}
5858

59-
private static void executeCommandLinux(final Runtime rt, final File file) {
59+
private static void openFileLinux(final Runtime rt, final String filePath) {
60+
final String[] command = {
61+
"xdg-open", filePath
62+
};
6063
try {
61-
final String command = "xdg-open " + file;
62-
LOG.debug("executing command: {}", command);
63-
64+
LOG.debug("executing command: {}", Arrays.toString(command));
6465
rt.exec(command);
6566
} catch (final Exception e) {
66-
LOG.error(e.getMessage());
67+
LOG.error("Could not open file '" + filePath + "' with command '" + Arrays.toString(command) + "'.", e);
6768
}
6869
}
6970
}

src/main/java/de/doubleslash/keeptime/view/AboutController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javafx.scene.control.TableView;
4040
import javafx.scene.control.cell.PropertyValueFactory;
4141
import javafx.scene.input.MouseButton;
42+
import javafx.scene.layout.Region;
4243
import javafx.scene.paint.Color;
4344

4445
public class AboutController {
@@ -153,6 +154,8 @@ private void showLicense(final Licenses license) {
153154
alert.setContentText(String.format(
154155
"We could not find the license file at \"%s\". Did you remove it?%nPlease redownload or visit \"%s\".",
155156
license.getPath(), license.getUrl()));
157+
158+
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
156159

157160
alert.show();
158161
}

0 commit comments

Comments
 (0)