From e4264d0199d02bc8dafd1c87a9af920428574f0a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 27 Apr 2021 13:56:32 +0200 Subject: [PATCH] support toggling trezor passphrase on and off in status bar usb menu --- .../sparrowwallet/sparrow/AppServices.java | 4 ++++ .../sparrow/control/UsbStatusButton.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index f0e1051f..569b5107 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -660,6 +660,10 @@ public class AppServices { deviceEnumerateService = createDeviceEnumerateService(); } + if(deviceEnumerateService.isRunning()) { + deviceEnumerateService.cancel(); + } + if(deviceEnumerateService.getState() == Worker.State.CANCELLED) { deviceEnumerateService.reset(); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/UsbStatusButton.java b/src/main/java/com/sparrowwallet/sparrow/control/UsbStatusButton.java index 0d8d22b6..9f8b2389 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/UsbStatusButton.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/UsbStatusButton.java @@ -1,8 +1,13 @@ package com.sparrowwallet.sparrow.control; +import com.sparrowwallet.drongo.wallet.WalletModel; +import com.sparrowwallet.sparrow.AppServices; +import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.event.RequestOpenWalletsEvent; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands; import com.sparrowwallet.sparrow.io.Device; +import com.sparrowwallet.sparrow.io.Hwi; import javafx.geometry.Side; import javafx.scene.Node; import javafx.scene.control.*; @@ -22,6 +27,22 @@ public class UsbStatusButton extends MenuButton { public void setDevices(List devices) { for(Device device : devices) { MenuItem deviceItem = new MenuItem(device.getModel().toDisplayString()); + if(!device.isNeedsPinSent() && (device.getModel() == WalletModel.TREZOR_1 || device.getModel() == WalletModel.TREZOR_T || device.getModel() == WalletModel.KEEPKEY)) { + deviceItem = new Menu(device.getModel().toDisplayString()); + MenuItem toggleItem = new MenuItem("Toggle Passphrase " + (device.isNeedsPassphraseSent() ? "Off" : "On")); + toggleItem.setOnAction(event -> { + Hwi.TogglePassphraseService togglePassphraseService = new Hwi.TogglePassphraseService(device); + togglePassphraseService.setOnSucceeded(event1 -> { + EventManager.get().post(new RequestOpenWalletsEvent()); + }); + togglePassphraseService.setOnFailed(event1 -> { + AppServices.showErrorDialog("Error toggling passphrase", event1.getSource().getException().getMessage()); + }); + togglePassphraseService.start(); + }); + ((Menu)deviceItem).getItems().add(toggleItem); + } + if(device.isNeedsPinSent()) { deviceItem.setGraphic(getLockIcon()); } else {