add restart in different home folder to tools menu

This commit is contained in:
Craig Raw 2024-03-26 11:37:46 +02:00
parent c108741b6f
commit 2e8112cba0
2 changed files with 32 additions and 2 deletions

View file

@ -381,6 +381,9 @@ public class AppController implements Initializable {
preventSleepProperty.set(Config.get().isPreventSleep()); preventSleepProperty.set(Config.get().isPreventSleep());
preventSleep.selectedProperty().bindBidirectional(preventSleepProperty); preventSleep.selectedProperty().bindBidirectional(preventSleepProperty);
MenuItem homeItem = new MenuItem("Home Folder...");
homeItem.setOnAction(this::restartInHome);
restart.getItems().add(homeItem);
List<Network> networks = new ArrayList<>(List.of(Network.MAINNET, Network.TESTNET, Network.SIGNET)); List<Network> networks = new ArrayList<>(List.of(Network.MAINNET, Network.TESTNET, Network.SIGNET));
networks.remove(Network.get()); networks.remove(Network.get());
for(Network network : networks) { for(Network network : networks) {
@ -973,19 +976,46 @@ public class AppController implements Initializable {
AppServices.get().setPreventSleep(item.isSelected()); AppServices.get().setPreventSleep(item.isSelected());
} }
public void restartInHome(ActionEvent event) {
Args args = getRestartArgs();
File initialDir = null;
if(args.dir != null) {
initialDir = new File(args.dir);
}
Stage window = new Stage();
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Choose Sparrow Home Folder");
directoryChooser.setInitialDirectory(initialDir == null || !initialDir.exists() ? Storage.getSparrowHome() : initialDir);
File newHome = directoryChooser.showDialog(window);
if(newHome != null) {
args.dir = newHome.getAbsolutePath();
restart(event, args);
}
}
public void restart(ActionEvent event, Network network) { public void restart(ActionEvent event, Network network) {
if(System.getProperty(JPACKAGE_APP_PATH) == null) { if(System.getProperty(JPACKAGE_APP_PATH) == null) {
throw new IllegalStateException("Property " + JPACKAGE_APP_PATH + " is not present"); throw new IllegalStateException("Property " + JPACKAGE_APP_PATH + " is not present");
} }
Args args = getRestartArgs();
args.network = network;
restart(event, args);
}
private static Args getRestartArgs() {
Args args = new Args(); Args args = new Args();
ProcessHandle.current().info().arguments().ifPresent(argv -> { ProcessHandle.current().info().arguments().ifPresent(argv -> {
JCommander jCommander = JCommander.newBuilder().addObject(args).acceptUnknownOptions(true).build(); JCommander jCommander = JCommander.newBuilder().addObject(args).acceptUnknownOptions(true).build();
jCommander.parse(argv); jCommander.parse(argv);
}); });
args.network = network; return args;
}
private void restart(ActionEvent event, Args args) {
try { try {
List<String> cmd = new ArrayList<>(); List<String> cmd = new ArrayList<>();
cmd.add(System.getProperty(JPACKAGE_APP_PATH)); cmd.add(System.getProperty(JPACKAGE_APP_PATH));

View file

@ -143,7 +143,7 @@
<MenuItem mnemonicParsing="false" text="Verify Download" onAction="#verifyDownload" /> <MenuItem mnemonicParsing="false" text="Verify Download" onAction="#verifyDownload" />
<MenuItem styleClass="osxHide,windowsHide" mnemonicParsing="false" text="Install Udev Rules" onAction="#installUdevRules"/> <MenuItem styleClass="osxHide,windowsHide" mnemonicParsing="false" text="Install Udev Rules" onAction="#installUdevRules"/>
<CheckMenuItem fx:id="preventSleep" mnemonicParsing="false" text="Prevent Computer Sleep" onAction="#preventSleep"/> <CheckMenuItem fx:id="preventSleep" mnemonicParsing="false" text="Prevent Computer Sleep" onAction="#preventSleep"/>
<Menu fx:id="restart" mnemonicParsing="false" text="Restart In Network" /> <Menu fx:id="restart" mnemonicParsing="false" text="Restart In" />
</Menu> </Menu>
<Menu fx:id="helpMenu" mnemonicParsing="false" text="Help"> <Menu fx:id="helpMenu" mnemonicParsing="false" text="Help">
<MenuItem mnemonicParsing="false" text="Show Introduction" onAction="#showIntroduction"/> <MenuItem mnemonicParsing="false" text="Show Introduction" onAction="#showIntroduction"/>