mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
UI: news page shown only on new posts available;
This commit is contained in:
parent
e3e3577923
commit
7c8ba650a2
2 changed files with 59 additions and 12 deletions
|
@ -272,6 +272,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
public static final String KEY_PROXY_PSWD = "proxyPassword";
|
public static final String KEY_PROXY_PSWD = "proxyPassword";
|
||||||
public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList";
|
public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList";
|
||||||
|
|
||||||
|
// news
|
||||||
|
public static final String KEY_NEWS_PAGE_LAST_VERSION = "newsPageLastVersion";
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
public static final String KEY_CONTROL_TOGGLE_MACRO = "controlToggleMacro";
|
public static final String KEY_CONTROL_TOGGLE_MACRO = "controlToggleMacro";
|
||||||
public static final String KEY_CONTROL_CONFIRM = "controlConfirm";
|
public static final String KEY_CONTROL_CONFIRM = "controlConfirm";
|
||||||
|
|
|
@ -17,10 +17,9 @@ import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.*;
|
||||||
import java.net.URISyntaxException;
|
import java.util.Scanner;
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JayDi85
|
* @author JayDi85
|
||||||
|
@ -31,6 +30,7 @@ public class WhatsNewDialog extends MageDialog {
|
||||||
private static final MageVersion clientVersion = new MageVersion(WhatsNewDialog.class);
|
private static final MageVersion clientVersion = new MageVersion(WhatsNewDialog.class);
|
||||||
|
|
||||||
private static final String WHATS_NEW_PAGE = "https://jaydi85.github.io/xmage-web-news/news.html";
|
private static final String WHATS_NEW_PAGE = "https://jaydi85.github.io/xmage-web-news/news.html";
|
||||||
|
private static final String WHATS_NEW_VERSION_PAGE = "https://jaydi85.github.io/xmage-web-news/news_version.html"; // increment version=123 to auto-shown for all users
|
||||||
private static final int WHATS_NEW_LOAD_TIMEOUT_SECS = 20; // timeout for page loading
|
private static final int WHATS_NEW_LOAD_TIMEOUT_SECS = 20; // timeout for page loading
|
||||||
|
|
||||||
final JFXPanel fxPanel;
|
final JFXPanel fxPanel;
|
||||||
|
@ -41,7 +41,6 @@ public class WhatsNewDialog extends MageDialog {
|
||||||
@Override
|
@Override
|
||||||
public Void doInBackground() {
|
public Void doInBackground() {
|
||||||
try {
|
try {
|
||||||
logger.info("Checking news...");
|
|
||||||
int maxWait = WHATS_NEW_LOAD_TIMEOUT_SECS;
|
int maxWait = WHATS_NEW_LOAD_TIMEOUT_SECS;
|
||||||
int currentWait = 0;
|
int currentWait = 0;
|
||||||
while (!isPageReady) {
|
while (!isPageReady) {
|
||||||
|
@ -72,6 +71,50 @@ public class WhatsNewDialog extends MageDialog {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final SwingWorker<Void, Void> backgroundUpdatesWorker = new SwingWorker<Void, Void>() {
|
||||||
|
|
||||||
|
private String newVersion = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() {
|
||||||
|
try {
|
||||||
|
// download version
|
||||||
|
URLConnection connection = new URL(WHATS_NEW_VERSION_PAGE).openConnection();
|
||||||
|
connection.setRequestProperty("user-agent", "xmage");
|
||||||
|
InputStream download = connection.getInputStream();
|
||||||
|
Scanner s = new Scanner(download).useDelimiter("\\A");
|
||||||
|
String result = s.hasNext() ? s.next() : "";
|
||||||
|
|
||||||
|
// check version (default: always have new version)
|
||||||
|
if (result.startsWith("version=")) {
|
||||||
|
newVersion = result.substring("version=".length());
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
logger.error("Checking updates got wrong url " + WHATS_NEW_VERSION_PAGE, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Checking updates got error", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void done() {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String oldVersion = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEWS_PAGE_LAST_VERSION, "1");
|
||||||
|
|
||||||
|
boolean isHaveUpdates = newVersion.isEmpty() || !newVersion.equals(oldVersion);
|
||||||
|
if (isHaveUpdates) {
|
||||||
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEWS_PAGE_LAST_VERSION, newVersion);
|
||||||
|
loadURL(WHATS_NEW_PAGE);
|
||||||
|
backgroundWorker.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public WhatsNewDialog() {
|
public WhatsNewDialog() {
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
@ -86,15 +129,16 @@ public class WhatsNewDialog extends MageDialog {
|
||||||
// shows it on page ready or by force
|
// shows it on page ready or by force
|
||||||
|
|
||||||
isPageReady = false;
|
isPageReady = false;
|
||||||
loadURL(WHATS_NEW_PAGE);
|
|
||||||
|
|
||||||
if (forceToShowPage) {
|
if (forceToShowPage) {
|
||||||
if (!backgroundWorker.isDone()) {
|
// direct open
|
||||||
backgroundWorker.cancel(true);
|
loadURL(WHATS_NEW_PAGE);
|
||||||
}
|
if (!backgroundUpdatesWorker.isDone()) backgroundUpdatesWorker.cancel(true);
|
||||||
|
if (!backgroundWorker.isDone()) backgroundWorker.cancel(true);
|
||||||
|
|
||||||
showDialog();
|
showDialog();
|
||||||
} else {
|
} else {
|
||||||
backgroundWorker.execute();
|
// checks version -> loads on new
|
||||||
|
backgroundUpdatesWorker.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +184,7 @@ public class WhatsNewDialog extends MageDialog {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.error("Can't load news page: " + (value != null ? value.getMessage() : "null"));
|
logger.error("Can't load news page: " + (value != null ? value.getMessage() : "null"), value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue