Skip to content

Commit e51e458

Browse files
author
Martin Plieske
committed
expand OS an use it in SettingsController
1 parent 5708806 commit e51e458

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ public class FileOpenHelper {
1111

1212
private static final Logger LOG = LoggerFactory.getLogger(FileOpenHelper.class);
1313

14-
private File fileToOpen;
15-
16-
public FileOpenHelper() {}
14+
private final File fileToOpen;
1715

1816
public FileOpenHelper(final File file) {
1917
this.fileToOpen = file;
@@ -27,24 +25,16 @@ public void openFile() {
2725
executeCommand();
2826
}
2927

30-
public void openFile(final File file) {
28+
public static void openFile(final File file) {
3129
executeCommand(file);
3230
}
3331

34-
public void openFile(final String fileString) {
32+
public static void openFile(final String fileString) {
3533
final File file = new File(fileString);
3634

3735
executeCommand(file);
3836
}
3937

40-
public void setFile(final File file) {
41-
this.fileToOpen = file;
42-
}
43-
44-
public void setFile(final String fileString) {
45-
this.fileToOpen = new File(fileString);
46-
}
47-
4838
private void executeCommand() {
4939
final Runtime rt = Runtime.getRuntime();
5040

@@ -57,7 +47,7 @@ private void executeCommand() {
5747
}
5848
}
5949

60-
private void executeCommand(final File file) {
50+
private static void executeCommand(final File file) {
6151
final Runtime rt = Runtime.getRuntime();
6252

6353
if (OS.isWindows()) {
@@ -77,7 +67,7 @@ private void executeCommandWindows(final Runtime rt) {
7767
}
7868
}
7969

80-
private void executeCommandWindows(final Runtime rt, final File file) {
70+
private static void executeCommandWindows(final Runtime rt, final File file) {
8171
try {
8272
rt.exec("rundll32 url.dll,FileProtocolHandler " + file);
8373
} catch (final Exception e) {
@@ -93,7 +83,7 @@ private void executeCommandLinux(final Runtime rt) {
9383
}
9484
}
9585

96-
private void executeCommandLinux(final Runtime rt, final File file) {
86+
private static void executeCommandLinux(final Runtime rt, final File file) {
9787
try {
9888
rt.exec("xdg-open " + file);
9989
} catch (final Exception e) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44

55
public class OS {
66

7+
private static final String OS_PROPERTY = "os.name";
8+
79
private OS() {
810

911
}
1012

1113
public static boolean isWindows() {
12-
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
14+
if (System.getProperty(OS_PROPERTY).toLowerCase().contains("windows")) {
1315
return true;
1416
}
1517

1618
return false;
1719
}
1820

1921
public static boolean isLinux() {
20-
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
22+
if (System.getProperty(OS_PROPERTY).toLowerCase().contains("linux")) {
2123
return true;
2224
}
2325

2426
return false;
2527
}
2628

29+
public static String getOSname() {
30+
return System.getProperty(OS_PROPERTY);
31+
}
32+
2733
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.slf4j.LoggerFactory;
1010

1111
import de.doubleslash.keeptime.common.ConfigParser;
12+
import de.doubleslash.keeptime.common.OS;
1213
import de.doubleslash.keeptime.common.Resources;
1314
import de.doubleslash.keeptime.common.Resources.RESOURCE;
1415
import de.doubleslash.keeptime.controller.Controller;
@@ -91,13 +92,13 @@ public class SettingsController {
9192
@FXML
9293
private void initialize() {
9394
LOG.debug("start init");
94-
LOG.info("OS: {}", System.getProperty(OS_NAME));
95+
LOG.info("OS: {}", OS.getOSname());
9596
LOG.debug("set versionLabel text");
9697
LOG.debug("load substages");
9798
loadSubStages();
9899
LOG.debug("set version label text");
99100

100-
if (System.getProperty(OS_NAME).contains("Linux")) {
101+
if (OS.isLinux()) {
101102
if (useHotkeyCheckBox != null) {
102103
LOG.debug("useHotkeyCheckBox is initialized");
103104
useHotkeyCheckBox.setDisable(true);
@@ -124,7 +125,7 @@ private void initialize() {
124125
saveButton.setOnAction(ae -> {
125126
LOG.info("Save clicked");
126127

127-
if (System.getProperty(OS_NAME).contains("Linux")) {
128+
if (OS.isLinux()) {
128129
if (hoverBackgroundColor.getValue().getOpacity() < 0.5) {
129130
hoverBackgroundColor.setValue(Color.rgb((int) (hoverBackgroundColor.getValue().getRed() * 255),
130131
(int) (hoverBackgroundColor.getValue().getGreen() * 255),

0 commit comments

Comments
 (0)