From: Niki Roo Date: Thu, 7 May 2020 09:37:33 +0000 (+0200) Subject: version checking Fanfix -> Utils X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=ea4d29a2a5297ed265eba8e05505b2fd41729eb1;p=fanfix-swing.git version checking Fanfix -> Utils --- diff --git a/src/be/nikiroo/fanfix_swing/Main.java b/src/be/nikiroo/fanfix_swing/Main.java index 9ebfb1a9..ea61240e 100644 --- a/src/be/nikiroo/fanfix_swing/Main.java +++ b/src/be/nikiroo/fanfix_swing/Main.java @@ -1,27 +1,19 @@ package be.nikiroo.fanfix_swing; -import java.awt.Desktop; import java.io.IOException; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; -import javax.swing.JEditorPane; import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.SwingWorker; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.VersionCheck; import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix_swing.gui.MainFrame; import be.nikiroo.fanfix_swing.gui.TouchFrame; -import be.nikiroo.utils.Version; +import be.nikiroo.utils.VersionCheck; import be.nikiroo.utils.ui.UIUtils; /** @@ -73,10 +65,13 @@ public class Main extends be.nikiroo.fanfix.Main { @Override protected VersionCheck checkUpdates() { + // We use a SwingWorker instead of deferring to checkUpdates("...") + // So we can check in BG new SwingWorker() { @Override protected VersionCheck doInBackground() throws Exception { - return VersionCheck.check("nikiroo/fanfix-swing"); + return VersionCheck.check("nikiroo/fanfix-swing", + Instance.getInstance().getTrans().getLocale()); } @Override @@ -88,6 +83,7 @@ public class Main extends be.nikiroo.fanfix.Main { } } catch (InterruptedException e) { } catch (ExecutionException e) { + e.printStackTrace(); } } }.execute(); @@ -148,69 +144,13 @@ public class Main extends be.nikiroo.fanfix.Main { @Override protected void notifyUpdates(VersionCheck updates) { - StringBuilder builder = new StringBuilder(); - final JEditorPane updateMessage = new JEditorPane("text/html", ""); - builder.append(trans(StringIdGui.NEW_VERSION_AVAILABLE, + String title = trans(StringIdGui.NEW_VERSION_TITLE); + String introText = trans(StringIdGui.NEW_VERSION_AVAILABLE, "" + "https://github.com/nikiroo/fanfix-swing/releases" - + "")); - builder.append("
"); - builder.append("
"); - for (Version v : updates.getNewer()) { - builder.append("\t" - + trans(StringIdGui.NEW_VERSION_VERSION, v.toString()) - + ""); - builder.append("
"); - builder.append(""); - } - - // html content - updateMessage.setText("" // - + builder// - + ""); - - // handle link events - updateMessage.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent e) { - if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) - try { - Desktop.getDesktop().browse(e.getURL().toURI()); - } catch (IOException ee) { - Instance.getInstance().getTraceHandler().error(ee); - } catch (URISyntaxException ee) { - Instance.getInstance().getTraceHandler().error(ee); - } - } - }); - updateMessage.setEditable(false); - updateMessage.setBackground(new JLabel().getBackground()); - updateMessage.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent evn) { - if (evn.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - if (Desktop.isDesktopSupported()) { - try { - Desktop.getDesktop().browse(evn.getURL().toURI()); - } catch (IOException e) { - } catch (URISyntaxException e) { - } - } - } - } - }); - - int rep = JOptionPane.showConfirmDialog(null, updateMessage, - trans(StringIdGui.NEW_VERSION_TITLE), - JOptionPane.OK_CANCEL_OPTION); - if (rep == JOptionPane.OK_OPTION) { - updates.ok(); - } else { - updates.ignore(); + + ""); + if (UIUtils.showUpdatedDialog(null, updates, introText, title)) { + Instance.getInstance().setVersionChecked(); } }