add menu command to install udev rules via hwi on linux

This commit is contained in:
Craig Raw 2021-03-17 13:51:44 +02:00
parent 80a079cbee
commit d34c8b8bde
2 changed files with 29 additions and 3 deletions

View file

@ -86,6 +86,9 @@ public class AppController implements Initializable {
@FXML @FXML
private Menu fileMenu; private Menu fileMenu;
@FXML
private Menu toolsMenu;
@FXML @FXML
private Menu helpMenu; private Menu helpMenu;
@ -134,7 +137,7 @@ public class AppController implements Initializable {
} }
void initializeView() { void initializeView() {
setOsxApplicationMenu(); setPlatformApplicationMenu();
rootStack.setOnDragOver(event -> { rootStack.setOnDragOver(event -> {
if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) { if(event.getGestureSource() != rootStack && event.getDragboard().hasFiles()) {
@ -256,8 +259,9 @@ public class AppController implements Initializable {
openTransactionIdItem.disableProperty().bind(onlineProperty().not()); openTransactionIdItem.disableProperty().bind(onlineProperty().not());
} }
private void setOsxApplicationMenu() { private void setPlatformApplicationMenu() {
if(org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.OSX) { org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent();
if(platform == org.controlsfx.tools.Platform.OSX) {
MenuToolkit tk = MenuToolkit.toolkit(); MenuToolkit tk = MenuToolkit.toolkit();
MenuItem preferences = new MenuItem("Preferences..."); MenuItem preferences = new MenuItem("Preferences...");
preferences.setOnAction(this::openPreferences); preferences.setOnAction(this::openPreferences);
@ -269,7 +273,10 @@ public class AppController implements Initializable {
tk.setApplicationMenu(defaultApplicationMenu); tk.setApplicationMenu(defaultApplicationMenu);
fileMenu.getItems().removeIf(item -> item.getStyleClass().contains("osxHide")); fileMenu.getItems().removeIf(item -> item.getStyleClass().contains("osxHide"));
toolsMenu.getItems().removeIf(item -> item.getStyleClass().contains("osxHide"));
helpMenu.getItems().removeIf(item -> item.getStyleClass().contains("osxHide")); helpMenu.getItems().removeIf(item -> item.getStyleClass().contains("osxHide"));
} else if(platform == org.controlsfx.tools.Platform.WINDOWS) {
toolsMenu.getItems().removeIf(item -> item.getStyleClass().contains("windowsHide"));
} }
} }
@ -323,6 +330,24 @@ public class AppController implements Initializable {
return null; return null;
} }
public void installUdevRules(ActionEvent event) {
Hwi.EnumerateService enumerateService = new Hwi.EnumerateService(null);
enumerateService.setOnSucceeded(workerStateEvent -> {
Platform.runLater(this::showInstallUdevMessage);
});
enumerateService.setOnFailed(workerStateEvent -> {
Platform.runLater(this::showInstallUdevMessage);
});
enumerateService.start();
}
public void showInstallUdevMessage() {
TextAreaDialog dialog = new TextAreaDialog("sudo " + Config.get().getHwi().getAbsolutePath() + " installudevrules");
dialog.setTitle("Install Udev Rules");
dialog.getDialogPane().setHeaderText("Installing udev rules ensures devices can connect over USB.\nThis command requires root privileges.\nOpen a shell and enter the following:");
dialog.showAndWait();
}
public void openTransactionFromFile(ActionEvent event) { public void openTransactionFromFile(ActionEvent event) {
Stage window = new Stage(); Stage window = new Stage();

View file

@ -88,6 +88,7 @@
</Menu> </Menu>
<Menu fx:id="toolsMenu" mnemonicParsing="false" text="Tools"> <Menu fx:id="toolsMenu" mnemonicParsing="false" text="Tools">
<MenuItem mnemonicParsing="false" text="Sign/Verify Message" accelerator="Shortcut+M" onAction="#signVerifyMessage"/> <MenuItem mnemonicParsing="false" text="Sign/Verify Message" accelerator="Shortcut+M" onAction="#signVerifyMessage"/>
<MenuItem styleClass="osxHide,windowsHide" mnemonicParsing="false" text="Install Udev Rules" onAction="#installUdevRules"/>
</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"/>