Skip to content

Commit

Permalink
More Desktop enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 4, 2024
1 parent ab25bc0 commit 3fd86b3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public synchronized boolean tryUnlock(char[] password) {
} catch (GeneralSecurityException e) {
return false;
}

}

@Override
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import javax.swing.SwingConstants;

import convex.api.Convex;
import convex.gui.client.ConvexClient;
import convex.gui.components.AbstractGUI;
import convex.gui.components.ActionPanel;
import convex.gui.components.ConnectPanel;
import convex.gui.dlfs.DLFSBrowser;
import convex.gui.panels.HomePanel;
import convex.gui.peer.PeerLaunchDialog;
import convex.gui.repl.REPLClient;
import convex.gui.tools.HackerTools;
import convex.gui.utils.Toolkit;
import convex.gui.wallet.WalletApp;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void launchDiscord() {
public void launchTerminalClient() {
Convex convex=ConnectPanel.tryConnect(this);
if (convex!=null) {
new ConvexClient(convex).run();
new REPLClient(convex).run();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import convex.gui.components.BalanceLabel;
import convex.gui.components.DropdownMenu;
import convex.gui.keys.KeyRingPanel;
import convex.gui.keys.UnlockWalletDialog;
import convex.gui.utils.Toolkit;
import net.miginfocom.swing.MigLayout;

Expand Down Expand Up @@ -163,31 +164,25 @@ public void updateAddress(Address a) {
}

public void setKeyPair(AWalletEntry we) {
if (we==keyCombo.getSelectedItem()) return; // no change

if (we==null) {
convex.setKeyPair(null);
} else {
AKeyPair kp;
if (we.isLocked()) {
String s=JOptionPane.showInputDialog(AccountChooserPanel.this,"Enter password to unlock wallet:\n"+we.getPublicKey());
if (s==null) {
convex.setKeyPair(null);
return;
}
char[] pass=s.toCharArray();
boolean unlock=we.tryUnlock(s.toCharArray());
boolean unlock=UnlockWalletDialog.offerUnlock(this, we);
if (!unlock) {
convex.setKeyPair(null);
keyCombo.setSelectedItem(null);
return;
}

kp=we.getKeyPair();
we.lock(pass);
we.lock();
} else {
kp=we.getKeyPair();
}
convex.setKeyPair(kp);
}
keyCombo.setSelectedItem(we);
}

public void updateBalance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public UnlockWalletDialog(AWalletEntry walletEntry) {
btnCancel.addActionListener(e -> close());
mainPanel.add(buttonPanel, "dock south");


Action closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -103,7 +102,7 @@ public void close() {
}

/**
* Shows a dialog to ask the user to unlock a wallet
* Shows a dialog to ask the user to unlock a wallet entry
* @param parent Parent component
* @param walletEntry Wallet Entry to consider
* @return True if unlocked, false otherwise
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/peer/PeerComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import convex.core.cvm.PeerStatus;
import convex.core.text.Text;
import convex.etch.EtchStore;
import convex.gui.client.ConvexClient;
import convex.gui.components.BaseImageButton;
import convex.gui.components.BaseListComponent;
import convex.gui.components.CodeLabel;
import convex.gui.components.DropdownMenu;
import convex.gui.components.Identicon;
import convex.gui.etch.EtchWindow;
import convex.gui.models.StateModel;
import convex.gui.repl.REPLClient;
import convex.gui.server.PeerWindow;
import convex.gui.state.StateExplorer;
import convex.gui.utils.Toolkit;
Expand Down Expand Up @@ -189,7 +189,7 @@ protected void launchClientWindow(Convex peer) {
Address addr=peer.getAddress();
AKeyPair kp=peer.getKeyPair();;
convex.setAddress(addr,kp);
new ConvexClient(convex).run();
new REPLClient(convex).run();
} catch (IOException | TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package convex.gui.client;
package convex.gui.repl;

import java.awt.BorderLayout;
import java.awt.Dimension;
Expand All @@ -13,10 +13,12 @@
import org.slf4j.LoggerFactory;

import convex.api.Convex;
import convex.core.crypto.wallet.AWalletEntry;
import convex.gui.components.AbstractGUI;
import convex.gui.components.ConnectPanel;
import convex.gui.keys.KeyRingPanel;
import convex.gui.panels.REPLPanel;
import convex.gui.keys.UnlockWalletDialog;
import convex.gui.utils.Toolkit;
import net.miginfocom.swing.MigLayout;

/**
Expand All @@ -25,9 +27,9 @@
* Doesn't run a Peer. Connects to convex.world.
*/
@SuppressWarnings("serial")
public class ConvexClient extends AbstractGUI {
public class REPLClient extends AbstractGUI {

private static final Logger log = LoggerFactory.getLogger(ConvexClient.class.getName());
private static final Logger log = LoggerFactory.getLogger(REPLClient.class.getName());

public static long maxBlock = 0;

Expand All @@ -46,7 +48,7 @@ public static void main(String[] args) throws IOException, TimeoutException {
if (convex==null) {
System.exit(1);
}
ConvexClient gui=new ConvexClient(convex);
REPLClient gui=new REPLClient(convex);
gui.run();
gui.waitForClose();
System.exit(0);
Expand All @@ -60,7 +62,7 @@ public static void main(String[] args) throws IOException, TimeoutException {
* Create the application.
* @param convex Convex client instance
*/
public ConvexClient(Convex convex) {
public REPLClient(Convex convex) {
super ("Convex Client");
setLayout(new BorderLayout());
replPanel=new REPLPanel(convex);
Expand All @@ -74,7 +76,21 @@ public ConvexClient(Convex convex) {
this.setPreferredSize(new Dimension(800,600));

this.convex=convex;

}

@Override
public void afterRun() {
if (convex.getKeyPair()==null) {
AWalletEntry we=KeyRingPanel.findWalletEntry(convex);
if (we!=null) {
if (we.isLocked()) {
UnlockWalletDialog.offerUnlock(this, we);
}
convex.setKeyPair(we.getKeyPair());
} else {
Toolkit.showMessge(this, "The key for this account is not in your key ring.\n\nTerminal opened in Query mode.");
}
}
}

public void switchPanel(String title) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package convex.gui.panels;
package convex.gui.repl;

import java.awt.Color;
import java.awt.Font;
Expand Down
2 changes: 1 addition & 1 deletion convex-gui/src/main/java/convex/gui/server/PeerWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import convex.api.Convex;
import convex.api.ConvexLocal;
import convex.gui.components.AbstractGUI;
import convex.gui.panels.REPLPanel;
import convex.gui.peer.PeerComponent;
import convex.gui.repl.REPLPanel;
import convex.peer.Server;
import net.miginfocom.swing.MigLayout;

Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/main/java/convex/gui/wallet/SettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import javax.swing.JPanel;

import convex.api.Convex;
import convex.gui.client.ConvexClient;
import convex.gui.components.ActionButton;
import convex.gui.components.account.AccountChooserPanel;
import convex.gui.repl.REPLClient;
import convex.gui.utils.Toolkit;
import net.miginfocom.swing.MigLayout;

Expand All @@ -23,7 +23,7 @@ public SettingsPanel(Convex convex) {
add(Toolkit.withTitledBorder("Account Selection", chooser));

ActionButton replButton=new ActionButton("Terminal REPL", 0xeb8e, e->{
new ConvexClient(convex).run();
new REPLClient(convex).run();
});
JPanel toolPanel=new JPanel();
toolPanel.add(replButton);
Expand Down
4 changes: 2 additions & 2 deletions convex-gui/src/test/java/convex/gui/GUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import convex.core.crypto.AKeyPair;
import convex.core.exceptions.InvalidDataException;
import convex.dlfs.DLFileSystem;
import convex.gui.client.ConvexClient;
import convex.gui.dlfs.DLFSBrowser;
import convex.gui.peer.PeerGUI;
import convex.gui.repl.REPLClient;
import convex.gui.tools.HackerTools;
import convex.gui.utils.Toolkit;
import convex.peer.PeerException;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void testHackerTools() {
public void testClientTools() {
GUITest.assumeGUI();

ConvexClient client=new ConvexClient(CONVEX);
REPLClient client=new REPLClient(CONVEX);
assertNotNull(client.tabs);
}
}

0 comments on commit 3fd86b3

Please sign in to comment.