Usable Browser
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
package org.openautonomousconnection.webclient;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.Listener;
|
||||
import org.openautonomousconnection.infonamelib.LibClientImpl;
|
||||
import org.openautonomousconnection.infonamelib.OacWebUrlInstaller;
|
||||
import org.openautonomousconnection.oacswing.component.OACOptionPane;
|
||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolINSServerEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Protocol client implementation for the WebClient.
|
||||
*/
|
||||
public class ClientImpl extends ProtocolClient {
|
||||
|
||||
private final LibImpl libImpl = new LibImpl();
|
||||
private final AtomicBoolean connectedInitialized = new AtomicBoolean(false);
|
||||
private final Component dialogParent;
|
||||
private final Runnable onServerReady;
|
||||
|
||||
public ClientImpl(Component dialogParent, Runnable onServerReady) {
|
||||
this.dialogParent = dialogParent;
|
||||
this.onServerReady = Objects.requireNonNull(onServerReady, "onServerReady");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trustINS(String caFingerprint) {
|
||||
Object[] options = {"Continue", "Cancel"};
|
||||
int result = OACOptionPane.showOptionDialog(
|
||||
Main.getUi(),
|
||||
dialogParent,
|
||||
"You never connected to this INS before!\n" +
|
||||
"Fingerprint: " + caFingerprint + "\nDo you want to connect?",
|
||||
"INS Connection",
|
||||
@@ -21,7 +38,7 @@ public class ClientImpl extends ProtocolClient {
|
||||
OACOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0] // default button: Continue
|
||||
options[0]
|
||||
);
|
||||
|
||||
return result == 0;
|
||||
@@ -31,13 +48,8 @@ public class ClientImpl extends ProtocolClient {
|
||||
public boolean trustNewINSFingerprint(String oldCAFingerprint, String newCAFingerprint) {
|
||||
Object[] options = {"Continue", "Cancel"};
|
||||
|
||||
String table = String.format("""
|
||||
Saved Fingerprint\tNew Fingerprint
|
||||
%s\t%s
|
||||
""", oldCAFingerprint, newCAFingerprint);
|
||||
|
||||
int result = OACOptionPane.showOptionDialog(
|
||||
Main.getUi(),
|
||||
dialogParent,
|
||||
"The fingerprint does not match with the saved fingerprint!\n" +
|
||||
"Saved Fingerprint: " + oldCAFingerprint + "\n" +
|
||||
"New Fingerprint: " + newCAFingerprint + "\n" +
|
||||
@@ -47,7 +59,7 @@ public class ClientImpl extends ProtocolClient {
|
||||
OACOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0] // default button: Continue
|
||||
options[0]
|
||||
);
|
||||
|
||||
return result == 0;
|
||||
@@ -57,15 +69,31 @@ public class ClientImpl extends ProtocolClient {
|
||||
public void onConnected(ConnectedToProtocolINSServerEvent event) {
|
||||
try {
|
||||
buildServerConnection(null, getProtocolBridge().getProtocolValues().ssl);
|
||||
|
||||
//ProtocolHandlerPackages.installPackage("org.openautonomousconnection.infonamelib");
|
||||
OacWebUrlInstaller.installOnce(getProtocolBridge().getProtocolValues().eventManager, this);
|
||||
|
||||
SwingUtilities.invokeLater(() -> Main.getUi().openNewTab("web://info.oac/"));
|
||||
OacWebUrlInstaller.installOnce(getProtocolBridge().getProtocolValues().eventManager, this, libImpl);
|
||||
if (connectedInitialized.compareAndSet(false, true)) {
|
||||
onServerReady.run();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Main.getClient().getProtocolBridge().getLogger().exception("Failed to build Server connection", e);
|
||||
OACOptionPane.showMessageDialog(Main.getUi(), "Failed to connect to build Server connection:\n" + e.getMessage(),
|
||||
"Server Connection", OACOptionPane.ERROR_MESSAGE);
|
||||
getProtocolBridge().getLogger().exception("Failed to build Server connection", e);
|
||||
OACOptionPane.showMessageDialog(
|
||||
dialogParent,
|
||||
"Failed to to build Server connection:\n" + e.getMessage(),
|
||||
"Server Connection",
|
||||
OACOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private class LibImpl extends LibClientImpl {
|
||||
@Override
|
||||
public void serverConnectionFailed(Exception exception) {
|
||||
getProtocolBridge().getLogger().exception("Failed to connect to server", exception);
|
||||
OACOptionPane.showMessageDialog(
|
||||
dialogParent,
|
||||
"Failed to connect to Server:\n" + exception.getMessage(),
|
||||
"Server Connection",
|
||||
OACOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user