Skip to content

Commit

Permalink
Get command path dynamically for restarting
Browse files Browse the repository at this point in the history
The previous version assumes certain installation location. This version
works regardless of where the jar file was installed or if it's just a
development build that wasn't really installed at all.
  • Loading branch information
Ape committed Jan 5, 2025
1 parent ba76594 commit 4c699a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
requires ch.qos.logback.classic;
requires org.freedesktop.dbus;
requires jdk.incubator.vector;
requires java.management;

opens org.dpsoftware to javafx.fxml, javafx.web;
opens org.dpsoftware.gui to javafx.fxml, javafx.web;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/dpsoftware/NativeExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@

import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -169,9 +171,15 @@ private static void restartCmd(List<String> execCommand) {
execCommand.addAll(Arrays.stream(Constants.FLATPAK_RUN).toList());
} else if (NativeExecutor.isSnap()) {
execCommand.addAll(Arrays.stream(Constants.SNAP_RUN).toList());
} else if (System.getProperty(Constants.JPACKAGE_APP_PATH) != null) {
execCommand.add(System.getProperty(Constants.JPACKAGE_APP_PATH));
} else {
execCommand.add(getInstallationPath());
execCommand.add(System.getProperty(Constants.JAVA_HOME) + Constants.JAVA_BIN);
execCommand.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
execCommand.add(Constants.JAR_PARAM);
execCommand.add(System.getProperty(Constants.JAVA_COMMAND).split("\\s+")[0]);
}

if (NativeExecutor.isRunningOnSandbox()) {
execCommand.add(Constants.RESTART_DELAY);
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/dpsoftware/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,9 @@ public class Constants {
public static final ArrayList<String> HTTP_TOPIC_TO_SKIP_FOR_SATELLITES = new ArrayList<>(Arrays
.asList(TOPIC_GLOW_WORM_FIRM_CONFIG, HTTP_SETTING, HTTP_SET_LDR));
public static int GROUP_BY_LEDS = 1;

public static final String JPACKAGE_APP_PATH = "jpackage.app-path";
public static final String JAVA_HOME = "java.home";
public static final String JAVA_COMMAND = "sun.java.command";
public static final String JAVA_BIN = "/bin/java";
public static final String JAR_PARAM = "-jar";
}

0 comments on commit 4c699a9

Please sign in to comment.