Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update manager #11

Merged
merged 6 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ ktfmt { kotlinLangStyle() }
dependencies {
implementation("com.jgoodies:jgoodies-forms:1.6.0")
implementation("com.miglayout:miglayout-swing:5.2")
implementation("com.konghq:unirest-java:3.14.2")
implementation(project(":core"))
testImplementation(project(":test-core"))
}

application {
Expand Down
50 changes: 0 additions & 50 deletions client/src/main/java/bean/HyperlinkAdaptor.java

This file was deleted.

9 changes: 0 additions & 9 deletions client/src/main/java/bean/HyperlinkListener.java

This file was deleted.

9 changes: 1 addition & 8 deletions client/src/main/java/online/util/DesktopEntropyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ public void sendAsyncInSingleThread(MessageSenderParams message)
senderThread.start();
}

/*public void sendAsync(MessageSenderParams message)
{
MessageSender senderRunnable = new MessageSender(this, message);
Thread senderThread = new Thread(senderRunnable, "MessageSender");
senderThread.start();
}*/

@Override
public String sendSyncOnDevice(MessageSender runnable)
{
Expand All @@ -91,6 +84,6 @@ public String sendSyncOnDevice(MessageSender runnable)
@Override
public void checkForUpdates()
{
UpdateChecker.checkForUpdates(FILE_NAME_ENTROPY_JAR, SERVER_PORT_NUMBER_DOWNLOAD);
UpdateManager.INSTANCE.checkForUpdates(OnlineConstants.ENTROPY_VERSION_NUMBER);
}
}
23 changes: 9 additions & 14 deletions client/src/main/java/online/util/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,23 @@ private static void handleConnectFailure(Element root)

if (failureReason.contains("out of date"))
{
promptForUpdate(root);
promptForUpdate();
}
else
{
DialogUtil.showErrorLater(failureReason);
}
}

private static void promptForUpdate(final Element rootElement)
private static void promptForUpdate()
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
int answer = DialogUtil.showQuestion("Entropy needs to update in order to connect. \n\nUpdate now?", false);
if (answer == JOptionPane.YES_OPTION)
{
UpdateChecker.startUpdate(rootElement, OnlineConstants.FILE_NAME_ENTROPY_JAR, OnlineConstants.SERVER_PORT_NUMBER_DOWNLOAD);
}
}
});
SwingUtilities.invokeLater(() -> {
int answer = DialogUtil.showQuestion("Entropy needs to update in order to connect. \n\nUpdate now?", false);
if (answer == JOptionPane.YES_OPTION)
{
UpdateManager.INSTANCE.checkForUpdates(OnlineConstants.ENTROPY_VERSION_NUMBER);
}
});
}

private static void handleKickOff(Element root)
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/screen/AbstractAboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import javax.swing.SwingConstants;

import bean.HyperlinkAdaptor;
import bean.HyperlinkListener;
import bean.IHyperlinkListener;

public abstract class AbstractAboutDialog extends JDialog
implements HyperlinkListener,
implements IHyperlinkListener,
ActionListener
{
public AbstractAboutDialog()
Expand Down
14 changes: 1 addition & 13 deletions client/src/main/java/util/DialogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import screen.LoadingDialog;

import static utils.InjectedThings.logger;

@Deprecated()
public class DialogUtil
{
private static LoadingDialog loadingDialog = new LoadingDialog();
private static boolean shownConnectionLost = false;

public static void showInfo(String infoText)
Expand Down Expand Up @@ -104,14 +102,4 @@ public static void showConnectionLost()
shownConnectionLost = true;
}
}

public static void showLoadingDialog(String text)
{
logger.info("loaderShown", text);
loadingDialog.showDialog(text);
}
public static void dismissLoadingDialog()
{
loadingDialog.dismissDialog();
}
}
110 changes: 0 additions & 110 deletions client/src/main/java/util/UpdateChecker.java

This file was deleted.

36 changes: 36 additions & 0 deletions client/src/main/kotlin/bean/HyperlinkAdaptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bean

import java.awt.Component
import java.awt.Cursor
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent

class HyperlinkAdaptor(private val listener: IHyperlinkListener) : MouseAdapter() {
private val listenerWindow = listener as Component

override fun mouseClicked(arg0: MouseEvent) = listener.linkClicked(arg0)

override fun mouseMoved(arg0: MouseEvent) {
if (listener.isOverHyperlink(arg0)) {
listenerWindow.cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
} else {
listenerWindow.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)
}
}

override fun mouseEntered(e: MouseEvent) {
if (listener.isOverHyperlink(e)) {
listenerWindow.cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
}
}

override fun mouseDragged(e: MouseEvent?) {
if (listenerWindow.cursor.type == Cursor.HAND_CURSOR) {
listenerWindow.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)
}
}

override fun mouseExited(arg0: MouseEvent?) {
listenerWindow.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)
}
}
9 changes: 9 additions & 0 deletions client/src/main/kotlin/bean/IHyperlinkListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bean

import java.awt.event.MouseEvent

interface IHyperlinkListener {
fun linkClicked(arg0: MouseEvent)

fun isOverHyperlink(arg0: MouseEvent): Boolean
}
20 changes: 20 additions & 0 deletions client/src/main/kotlin/bean/LinkLabel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package bean

import java.awt.Color
import java.awt.event.MouseEvent
import javax.swing.JLabel

class LinkLabel(text: String, private val linkClicked: () -> Unit) :
JLabel("<html><u>$text</u></html>"), IHyperlinkListener {
init {
foreground = Color.BLUE

val adaptor = HyperlinkAdaptor(this)
addMouseListener(adaptor)
addMouseMotionListener(adaptor)
}

override fun linkClicked(arg0: MouseEvent) = linkClicked()

override fun isOverHyperlink(arg0: MouseEvent) = true
}
Loading
Loading