Fix initialization dependency cycle & load files on init.
This commit is contained in:
parent
6b9e1b8cb8
commit
40fdc8d248
@ -51,8 +51,9 @@ public final class MasterPassword {
|
|||||||
private static final MasterPassword instance = new MasterPassword();
|
private static final MasterPassword instance = new MasterPassword();
|
||||||
|
|
||||||
private final Collection<Listener> listeners = new CopyOnWriteArraySet<>();
|
private final Collection<Listener> listeners = new CopyOnWriteArraySet<>();
|
||||||
private final MasterPasswordFrame frame = new MasterPasswordFrame();
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private MasterPasswordFrame frame;
|
||||||
@Nullable
|
@Nullable
|
||||||
private MPUser<?> activeUser;
|
private MPUser<?> activeUser;
|
||||||
|
|
||||||
@ -60,12 +61,13 @@ public final class MasterPassword {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addListener(final Listener listener) {
|
public void addListener(final Listener listener) {
|
||||||
return listeners.add( listener );
|
if (listeners.add( listener ))
|
||||||
|
listener.onUserSelected( activeUser );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeListener(final Listener listener) {
|
public void removeListener(final Listener listener) {
|
||||||
return listeners.remove( listener );
|
listeners.remove( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activateUser(final MPUser<?> user) {
|
public void activateUser(final MPUser<?> user) {
|
||||||
@ -84,6 +86,9 @@ public final class MasterPassword {
|
|||||||
|
|
||||||
public void open() {
|
public void open() {
|
||||||
Res.ui( () -> {
|
Res.ui( () -> {
|
||||||
|
if (frame == null)
|
||||||
|
frame = new MasterPasswordFrame();
|
||||||
|
|
||||||
frame.setAlwaysOnTop( true );
|
frame.setAlwaysOnTop( true );
|
||||||
frame.setVisible( true );
|
frame.setVisible( true );
|
||||||
frame.setExtendedState( Frame.NORMAL );
|
frame.setExtendedState( Frame.NORMAL );
|
||||||
|
@ -114,9 +114,9 @@ public interface MPUser<S extends MPSite<?>> extends Comparable<MPUser<?>> {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
ImmutableCollection<S> findSites(@Nullable String query);
|
ImmutableCollection<S> findSites(@Nullable String query);
|
||||||
|
|
||||||
boolean addListener(Listener listener);
|
void addListener(Listener listener);
|
||||||
|
|
||||||
boolean removeListener(Listener listener);
|
void removeListener(Listener listener);
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
|
|
||||||
|
@ -211,13 +211,13 @@ public abstract class MPBasicUser<S extends MPBasicSite<?, ?>> extends Changeabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addListener(final Listener listener) {
|
public void addListener(final Listener listener) {
|
||||||
return listeners.add( listener );
|
listeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeListener(final Listener listener) {
|
public void removeListener(final Listener listener) {
|
||||||
return listeners.remove( listener );
|
listeners.remove( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,6 +66,7 @@ public class MPFileUserManager {
|
|||||||
|
|
||||||
protected MPFileUserManager(final File path) {
|
protected MPFileUserManager(final File path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
@ -128,12 +129,13 @@ public class MPFileUserManager {
|
|||||||
return ImmutableSortedSet.copyOf( userByName.values() );
|
return ImmutableSortedSet.copyOf( userByName.values() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addListener(final Listener listener) {
|
public void addListener(final Listener listener) {
|
||||||
return listeners.add( listener );
|
if (listeners.add( listener ))
|
||||||
|
listener.onFilesUpdated( getFiles() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeListener(final Listener listener) {
|
public void removeListener(final Listener listener) {
|
||||||
return listeners.remove( listener );
|
listeners.remove( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireUpdated() {
|
private void fireUpdated() {
|
||||||
@ -141,7 +143,6 @@ public class MPFileUserManager {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ImmutableSortedSet<MPFileUser> files = getFiles();
|
ImmutableSortedSet<MPFileUser> files = getFiles();
|
||||||
|
|
||||||
for (final Listener listener : listeners)
|
for (final Listener listener : listeners)
|
||||||
listener.onFilesUpdated( files );
|
listener.onFilesUpdated( files );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user