Improve check for platform-specific GUI support & url access for CF needs user-agent.
This commit is contained in:
parent
c3f6796833
commit
835acf45eb
@ -21,8 +21,8 @@ package com.lyndir.masterpassword.gui;
|
|||||||
import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
|
import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.ByteSource;
|
||||||
import com.google.common.io.CharSource;
|
import com.google.common.io.CharSource;
|
||||||
import com.google.common.io.Resources;
|
|
||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import com.lyndir.lhunath.opal.system.util.TypeUtils;
|
import com.lyndir.lhunath.opal.system.util.TypeUtils;
|
||||||
import com.lyndir.masterpassword.gui.view.PasswordFrame;
|
import com.lyndir.masterpassword.gui.view.PasswordFrame;
|
||||||
@ -30,8 +30,7 @@ import com.lyndir.masterpassword.gui.view.UnlockFrame;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URI;
|
import java.net.*;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
@ -62,18 +61,24 @@ public class GUI implements UnlockFrame.SignInCallback {
|
|||||||
catch (final UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) {
|
catch (final UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create().open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GUI create() {
|
||||||
try {
|
try {
|
||||||
// AppleGUI adds support for macOS features.
|
// AppleGUI adds support for macOS features.
|
||||||
Optional<Class<GUI>> appleGUI = TypeUtils.loadClass( "com.lyndir.masterpassword.gui.platform.mac.AppleGUI" );
|
Optional<Class<GUI>> appleGUI = TypeUtils.loadClass( "com.lyndir.masterpassword.gui.platform.mac.AppleGUI" );
|
||||||
if (appleGUI.isPresent())
|
if (appleGUI.isPresent())
|
||||||
appleGUI.get().getConstructor().newInstance().open();
|
return appleGUI.get().getConstructor().newInstance();
|
||||||
|
}
|
||||||
else // No special platform handling.
|
catch (@SuppressWarnings("ErrorNotRethrown") final LinkageError ignored) {
|
||||||
new GUI().open();
|
|
||||||
}
|
}
|
||||||
catch (final IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
catch (final IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
throw logger.bug( e );
|
throw logger.bug( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use platform-independent GUI.
|
||||||
|
return new GUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkUpdate() {
|
private static void checkUpdate() {
|
||||||
@ -86,9 +91,17 @@ public class GUI implements UnlockFrame.SignInCallback {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
String manifestRevision = attributes.getValue( Attributes.Name.IMPLEMENTATION_VERSION );
|
String manifestRevision = attributes.getValue( Attributes.Name.IMPLEMENTATION_VERSION );
|
||||||
String upstreamRevisionURL = "https://masterpassword.app/masterpassword-gui.jar.rev";
|
String upstreamRevision = new ByteSource() {
|
||||||
CharSource upstream = Resources.asCharSource( URI.create( upstreamRevisionURL ).toURL(), Charsets.UTF_8 );
|
@Override
|
||||||
String upstreamRevision = upstream.readFirstLine();
|
public InputStream openStream()
|
||||||
|
throws IOException {
|
||||||
|
URL url = URI.create( "https://masterpassword.app/masterpassword-gui.jar.rev" ).toURL();
|
||||||
|
URLConnection conn = url.openConnection();
|
||||||
|
conn.addRequestProperty( "User-Agent", "masterpassword-gui" );
|
||||||
|
return conn.getInputStream();
|
||||||
|
}
|
||||||
|
}.asCharSource( Charsets.UTF_8 ).readFirstLine();
|
||||||
|
|
||||||
if ((manifestRevision != null) && (upstreamRevision != null) && !manifestRevision.equalsIgnoreCase(
|
if ((manifestRevision != null) && (upstreamRevision != null) && !manifestRevision.equalsIgnoreCase(
|
||||||
upstreamRevision )) {
|
upstreamRevision )) {
|
||||||
logger.inf( "Local Revision: <%s>", manifestRevision );
|
logger.inf( "Local Revision: <%s>", manifestRevision );
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.lyndir.masterpassword.gui.platform.mac;
|
package com.lyndir.masterpassword.gui.platform.mac;
|
||||||
|
|
||||||
import com.apple.eawt.*;
|
import com.apple.eawt.*;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.lyndir.masterpassword.gui.GUI;
|
import com.lyndir.masterpassword.gui.GUI;
|
||||||
|
|
||||||
|
|
||||||
@ -27,10 +28,17 @@ import com.lyndir.masterpassword.gui.GUI;
|
|||||||
*/
|
*/
|
||||||
public class AppleGUI extends GUI {
|
public class AppleGUI extends GUI {
|
||||||
|
|
||||||
public AppleGUI() {
|
static Application application;
|
||||||
|
|
||||||
Application application = Application.getApplication();
|
static {
|
||||||
application.addAppEventListener( new AppForegroundListener() {
|
application = Preconditions.checkNotNull( Application.getApplication(), "Not an Apple Java application." );
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppleGUI() {
|
||||||
|
application.addAppEventListener( new ApplicationListener() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ApplicationListener implements AppForegroundListener, AppReOpenedListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appMovedToBackground(final AppEvent.AppForegroundEvent arg0) {
|
public void appMovedToBackground(final AppEvent.AppForegroundEvent arg0) {
|
||||||
@ -40,12 +48,10 @@ public class AppleGUI extends GUI {
|
|||||||
public void appRaisedToForeground(final AppEvent.AppForegroundEvent arg0) {
|
public void appRaisedToForeground(final AppEvent.AppForegroundEvent arg0) {
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
application.addAppEventListener( new AppReOpenedListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void appReOpened(final AppEvent.AppReOpenedEvent arg0) {
|
public void appReOpened(final AppEvent.AppReOpenedEvent arg0) {
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user