User config in _ext_mpw, global config.json & residence config.
Moved user preferences (default type & hide passwords) into _ext_mpw. Fixed an issue with JSON serialization of any values. Made update check & background residency globally configurable preferences saved in config.json.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package com.lyndir.masterpassword.gui;
|
||||
|
||||
import com.lyndir.lhunath.opal.system.util.ConversionUtils;
|
||||
import com.lyndir.masterpassword.model.MPConfig;
|
||||
import com.lyndir.masterpassword.model.MPModelConstants;
|
||||
|
||||
|
||||
@@ -26,15 +27,32 @@ import com.lyndir.masterpassword.model.MPModelConstants;
|
||||
* @author lhunath, 2014-08-31
|
||||
*/
|
||||
@SuppressWarnings("CallToSystemGetenv")
|
||||
public class MPConfig {
|
||||
public class MPGuiConfig extends MPConfig {
|
||||
|
||||
private static final MPConfig instance = new MPConfig();
|
||||
|
||||
public static MPConfig get() {
|
||||
return instance;
|
||||
public static MPGuiConfig get() {
|
||||
return get( MPGuiConfig.class );
|
||||
}
|
||||
|
||||
Boolean checkForUpdates;
|
||||
Boolean stayResident;
|
||||
|
||||
public boolean checkForUpdates() {
|
||||
return ConversionUtils.toBoolean( System.getenv( MPModelConstants.env_checkUpdates ) ).orElse( true );
|
||||
return (checkForUpdates != null)? checkForUpdates:
|
||||
ConversionUtils.toBoolean( System.getenv( MPModelConstants.env_checkUpdates ) ).orElse( true );
|
||||
}
|
||||
|
||||
public void setCheckForUpdates(final boolean checkForUpdates) {
|
||||
this.checkForUpdates = checkForUpdates;
|
||||
MasterPassword.get().updateCheck();
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public boolean stayResident() {
|
||||
return (stayResident != null)? stayResident: false;
|
||||
}
|
||||
|
||||
public void setStayResident(final boolean stayResident) {
|
||||
this.stayResident = stayResident;
|
||||
setChanged();
|
||||
}
|
||||
}
|
@@ -46,10 +46,10 @@ import javax.swing.*;
|
||||
public final class MasterPassword {
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
private static final Logger logger = Logger.get( MasterPassword.class );
|
||||
|
||||
private static final Logger logger = Logger.get( MasterPassword.class );
|
||||
private static final MasterPassword instance = new MasterPassword();
|
||||
|
||||
private final Provider keyMaster = Provider.getCurrentProvider( true );
|
||||
private final Collection<Listener> listeners = new CopyOnWriteArraySet<>();
|
||||
|
||||
@Nullable
|
||||
@@ -97,7 +97,29 @@ public final class MasterPassword {
|
||||
} );
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
public static void main(final String... args) {
|
||||
//Thread.setDefaultUncaughtExceptionHandler(
|
||||
// (t, e) -> logger.bug( e, "Uncaught: %s", e.getLocalizedMessage() ) );
|
||||
|
||||
// Set the system look & feel, if available.
|
||||
try {
|
||||
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
|
||||
}
|
||||
catch (final UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) {
|
||||
}
|
||||
|
||||
// Create and open the UI.
|
||||
get().open();
|
||||
|
||||
// UI features.
|
||||
get().updateResidence();
|
||||
get().updateCheck();
|
||||
}
|
||||
|
||||
public void updateCheck() {
|
||||
if (!MPGuiConfig.get().checkForUpdates())
|
||||
return;
|
||||
|
||||
try {
|
||||
String implementationVersion = version();
|
||||
String latestVersion = new ByteSource() {
|
||||
@@ -127,26 +149,10 @@ public final class MasterPassword {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(final String... args) {
|
||||
//Thread.setDefaultUncaughtExceptionHandler(
|
||||
// (t, e) -> logger.bug( e, "Uncaught: %s", e.getLocalizedMessage() ) );
|
||||
|
||||
// Try and set the system look & feel, if available.
|
||||
try {
|
||||
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
|
||||
Platform.get().installAppForegroundHandler( get()::open );
|
||||
Platform.get().installAppReopenHandler( get()::open );
|
||||
Provider.getCurrentProvider( true ).register( MPGuiConstants.ui_hotkey, hotKey -> get().open() );
|
||||
}
|
||||
catch (final UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) {
|
||||
}
|
||||
|
||||
// Create a platform-specific GUI and open it.
|
||||
get().open();
|
||||
|
||||
// Check online to see if this version has been superseded.
|
||||
if (MPConfig.get().checkForUpdates())
|
||||
get().checkUpdate();
|
||||
public void updateResidence() {
|
||||
Platform.get().installAppForegroundHandler( get()::open );
|
||||
Platform.get().installAppReopenHandler( get()::open );
|
||||
keyMaster.register( MPGuiConstants.ui_hotkey, hotKey -> get().open() );
|
||||
}
|
||||
|
||||
@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
|
||||
|
@@ -17,24 +17,47 @@ public class ApplePlatform implements IPlatform {
|
||||
private static final Application application = Preconditions.checkNotNull(
|
||||
Application.getApplication(), "Not an Apple Java application." );
|
||||
|
||||
private AppForegroundListener appForegroundHandler;
|
||||
private AppReOpenedListener appReopenHandler;
|
||||
|
||||
@Override
|
||||
public boolean installAppForegroundHandler(final Runnable handler) {
|
||||
application.addAppEventListener( new AppForegroundListener() {
|
||||
@Override
|
||||
public void appMovedToBackground(final AppEvent.AppForegroundEvent e) {
|
||||
}
|
||||
if (appForegroundHandler == null)
|
||||
application.addAppEventListener( appForegroundHandler = new AppForegroundListener() {
|
||||
@Override
|
||||
public void appMovedToBackground(final AppEvent.AppForegroundEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appRaisedToForeground(final AppEvent.AppForegroundEvent e) {
|
||||
handler.run();
|
||||
}
|
||||
} );
|
||||
@Override
|
||||
public void appRaisedToForeground(final AppEvent.AppForegroundEvent e) {
|
||||
handler.run();
|
||||
}
|
||||
} );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppForegroundHandler() {
|
||||
if (appForegroundHandler == null)
|
||||
return false;
|
||||
|
||||
application.removeAppEventListener( appForegroundHandler );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean installAppReopenHandler(final Runnable handler) {
|
||||
application.addAppEventListener( (AppReOpenedListener) e -> handler.run() );
|
||||
application.addAppEventListener( appReopenHandler = e -> handler.run() );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppReopenHandler() {
|
||||
if (appReopenHandler == null)
|
||||
return false;
|
||||
|
||||
application.removeAppEventListener( appReopenHandler );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -14,11 +14,21 @@ public class BasePlatform implements IPlatform {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppForegroundHandler() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean installAppReopenHandler(final Runnable handler) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppReopenHandler() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestForeground() {
|
||||
return false;
|
||||
|
@@ -12,8 +12,12 @@ public interface IPlatform {
|
||||
|
||||
boolean installAppForegroundHandler(Runnable handler);
|
||||
|
||||
boolean removeAppForegroundHandler();
|
||||
|
||||
boolean installAppReopenHandler(Runnable handler);
|
||||
|
||||
boolean removeAppReopenHandler();
|
||||
|
||||
boolean requestForeground();
|
||||
|
||||
boolean show(File file);
|
||||
|
@@ -17,24 +17,49 @@ public class JDK9Platform implements IPlatform {
|
||||
private static final Logger logger = Logger.get( JDK9Platform.class );
|
||||
private static final Desktop desktop = Desktop.getDesktop();
|
||||
|
||||
private AppForegroundListener appForegroundHandler;
|
||||
private AppReopenedListener appReopenHandler;
|
||||
|
||||
@Override
|
||||
public boolean installAppForegroundHandler(final Runnable handler) {
|
||||
desktop.addAppEventListener( new AppForegroundListener() {
|
||||
@Override
|
||||
public void appRaisedToForeground(final AppForegroundEvent e) {
|
||||
handler.run();
|
||||
}
|
||||
if (appForegroundHandler == null)
|
||||
desktop.addAppEventListener( appForegroundHandler = new AppForegroundListener() {
|
||||
@Override
|
||||
public void appRaisedToForeground(final AppForegroundEvent e) {
|
||||
handler.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appMovedToBackground(final AppForegroundEvent e) {
|
||||
}
|
||||
} );
|
||||
@Override
|
||||
public void appMovedToBackground(final AppForegroundEvent e) {
|
||||
}
|
||||
} );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppForegroundHandler() {
|
||||
if (appForegroundHandler == null)
|
||||
return false;
|
||||
|
||||
desktop.removeAppEventListener( appForegroundHandler );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean installAppReopenHandler(final Runnable handler) {
|
||||
desktop.addAppEventListener( (AppReopenedListener) e -> handler.run() );
|
||||
if (appReopenHandler == null)
|
||||
desktop.addAppEventListener( appReopenHandler = e -> handler.run() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAppReopenHandler() {
|
||||
if (appReopenHandler == null)
|
||||
return false;
|
||||
|
||||
desktop.removeAppEventListener( appReopenHandler );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package com.lyndir.masterpassword.gui.view;
|
||||
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import com.lyndir.masterpassword.gui.MPGuiConfig;
|
||||
import com.lyndir.masterpassword.gui.util.Components;
|
||||
import com.lyndir.masterpassword.gui.util.Res;
|
||||
import com.lyndir.masterpassword.model.impl.MPFileUserManager;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.BevelBorder;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MasterPasswordFrame extends JFrame {
|
||||
|
||||
private static final Logger logger = Logger.get( MasterPasswordFrame.class );
|
||||
|
||||
private final UserContentPanel userContent;
|
||||
private final UserContentPanel userContent;
|
||||
|
||||
@SuppressWarnings("MagicNumber")
|
||||
public MasterPasswordFrame() {
|
||||
@@ -39,6 +39,7 @@ public class MasterPasswordFrame extends JFrame {
|
||||
userPanel.add( userContent.getSiteToolbar(), BorderLayout.LINE_END );
|
||||
|
||||
addComponentListener( new ComponentHandler() );
|
||||
addWindowListener( new WindowHandler() );
|
||||
setPreferredSize( new Dimension( 800, 560 ) );
|
||||
setDefaultCloseOperation( DISPOSE_ON_CLOSE );
|
||||
pack();
|
||||
@@ -55,4 +56,14 @@ public class MasterPasswordFrame extends JFrame {
|
||||
userContent.transferFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class WindowHandler extends WindowAdapter {
|
||||
|
||||
@Override
|
||||
public void windowClosed(final WindowEvent e) {
|
||||
if (!MPGuiConfig.get().stayResident())
|
||||
System.exit( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,8 +9,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||
import com.lyndir.lhunath.opal.system.util.ObjectUtils;
|
||||
import com.lyndir.masterpassword.*;
|
||||
import com.lyndir.masterpassword.gui.MPGuiConstants;
|
||||
import com.lyndir.masterpassword.gui.MasterPassword;
|
||||
import com.lyndir.masterpassword.gui.*;
|
||||
import com.lyndir.masterpassword.gui.model.*;
|
||||
import com.lyndir.masterpassword.gui.util.*;
|
||||
import com.lyndir.masterpassword.gui.util.Platform;
|
||||
@@ -577,21 +576,25 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
|
||||
components.add( Components.label( "Default Algorithm:" ),
|
||||
Components.comboBox( MPAlgorithm.Version.values(), MPAlgorithm.Version::name,
|
||||
user.getAlgorithm().version(),
|
||||
version -> user.setAlgorithm( version.getAlgorithm() ) ) );
|
||||
user.getAlgorithm().version(), version -> user.setAlgorithm( version.getAlgorithm() ) ) );
|
||||
|
||||
MPFileUser fileUser = (user instanceof MPFileUser)? (MPFileUser) user: null;
|
||||
if (fileUser != null) {
|
||||
components.add( Components.label( "Default Password Type:" ),
|
||||
Components.comboBox( MPResultType.values(), MPResultType::getLongName,
|
||||
fileUser.getPreferences().getDefaultType(),
|
||||
fileUser.getPreferences()::setDefaultType ),
|
||||
Components.strut() );
|
||||
components.add( Components.label( "Default Password Type:" ),
|
||||
Components.comboBox( MPResultType.values(), MPResultType::getLongName,
|
||||
user.getPreferences().getDefaultType(), user.getPreferences()::setDefaultType ),
|
||||
Components.strut() );
|
||||
|
||||
components.add( Components.checkBox( "Hide Passwords",
|
||||
fileUser.getPreferences().isHidePasswords(),
|
||||
fileUser.getPreferences()::setHidePasswords ) );
|
||||
}
|
||||
components.add( Components.checkBox( "Hide Passwords",
|
||||
user.getPreferences().isHidePasswords(), user.getPreferences()::setHidePasswords ) );
|
||||
|
||||
components.add( new JSeparator() );
|
||||
|
||||
components.add( Components.checkBox( "Check For Updates",
|
||||
MPGuiConfig.get().checkForUpdates(), MPGuiConfig.get()::setCheckForUpdates ) );
|
||||
|
||||
components.add( Components.checkBox( strf( "<html>Stay Resident (reactivate with <strong><code>%s+%s</code></strong>)",
|
||||
InputEvent.getModifiersExText( MPGuiConstants.ui_hotkey.getModifiers() ),
|
||||
KeyEvent.getKeyText( MPGuiConstants.ui_hotkey.getKeyCode() ) ),
|
||||
MPGuiConfig.get().stayResident(), MPGuiConfig.get()::setStayResident ) );
|
||||
|
||||
Components.showDialog( this, user.getFullName(), new JOptionPane( Components.panel(
|
||||
BoxLayout.PAGE_AXIS, components.build().toArray( new Component[0] ) ) ) );
|
||||
|
Reference in New Issue
Block a user