profiles: Ui fixes and improvements (#1538)

profiles: Ui fixes and improvements
This commit is contained in:
ST0NEWALL
2019-09-04 11:18:21 -04:00
committed by GitHub

View File

@@ -120,6 +120,9 @@ class ProfilesPanel extends PluginPanel
txtDecryptPassword.setEchoChar((char) 0); txtDecryptPassword.setEchoChar((char) 0);
txtDecryptPassword.setForeground(ColorScheme.LIGHT_GRAY_COLOR); txtDecryptPassword.setForeground(ColorScheme.LIGHT_GRAY_COLOR);
txtDecryptPassword.setToolTipText(UNLOCK_PASSWORD); txtDecryptPassword.setToolTipText(UNLOCK_PASSWORD);
txtDecryptPassword.addActionListener(e -> decryptAccounts());
txtDecryptPassword.addFocusListener(new FocusListener() txtDecryptPassword.addFocusListener(new FocusListener()
{ {
@Override @Override
@@ -156,27 +159,7 @@ class ProfilesPanel extends PluginPanel
@Override @Override
public void mousePressed(MouseEvent e) public void mousePressed(MouseEvent e)
{ {
boolean error = false; decryptAccounts();
try
{
redrawProfiles();
}
catch (InvalidKeySpecException | NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException ex)
{
error = true;
showErrorMessage("Unable to load data", "Incorrect password!");
}
if (error)
{
return;
}
remove(loginPanel);
add(accountPanel, BorderLayout.CENTER);
profilesPanel.setLayout(new DynamicGridLayout(0, 1, 0, 3));
add(profilesPanel, BorderLayout.SOUTH);
} }
@Override @Override
@@ -386,6 +369,38 @@ class ProfilesPanel extends PluginPanel
// addAccounts(config.profilesData()); // addAccounts(config.profilesData());
} }
private void decryptAccounts()
{
if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
{
showErrorMessage("Unable to load data", "Please enter a password!");
return;
}
boolean error = false;
try
{
redrawProfiles();
}
catch (InvalidKeySpecException | NoSuchAlgorithmException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchPaddingException ex)
{
error = true;
showErrorMessage("Unable to load data", "Incorrect password!");
txtDecryptPassword.setText("");
}
if (error)
{
return;
}
remove(loginPanel);
add(accountPanel, BorderLayout.CENTER);
profilesPanel.setLayout(new DynamicGridLayout(0, 1, 0, 3));
add(profilesPanel, BorderLayout.SOUTH);
}
private void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException private void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException
{ {
profilesPanel.removeAll(); profilesPanel.removeAll();
@@ -462,11 +477,6 @@ class ProfilesPanel extends PluginPanel
String tmp = profilesConfig.profilesData(); String tmp = profilesConfig.profilesData();
if (tmp.startsWith("¬")) if (tmp.startsWith("¬"))
{ {
if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
{
showErrorMessage("Unable to load data", "Please enter a password!");
return tmp;
}
tmp = tmp.substring(1); tmp = tmp.substring(1);
return decryptText(base64Decode(tmp), getAesKey()); return decryptText(base64Decode(tmp), getAesKey());
} }