newestRelease = result.get(0);
String newestTag = (String) newestRelease.get("tag_name");
System.out.println("Newest FRGUI version: " + newestTag);
//If user is not on latest version
- if (!newestTag.contains(currentFRGUIVersion)) {
+ if (!newestTag.equals(currentFRGUIVersion)) {
System.out.println("A newer version of FutureRestore GUI is available.");
- mainMenuInstance.appendToLog("A newer version of FutureRestore GUI is available.");
-
- Object[] choices = {"Open link", "Ok"};
+ mainMenuInstance.messageToLog("A newer version of FutureRestore GUI is available.");
+
+ // Label on top of release notes
+ JLabel label = new JLabel("A newer version of FutureRestore GUI is available.\n" +
+ "You're on version " + currentFRGUIVersion + " and the latest version is " + newestTag + ".");
+ Border padding = BorderFactory.createEmptyBorder(0, 0, 10, 10);
+ label.setBorder(padding);
+
+ // Fetch release notes
+ String mdReleaseBody = getLatestFrguiReleaseBody();
+ String htmlReleaseBody = "" +
+ "" +
+ "" +
+ "" +
+ ""
+ + Processor.process(mdReleaseBody).replaceAll("\\n", "") +
+ "
" +
+ "";
+ System.out.println(htmlReleaseBody);
+
+ // Build the text area
+ JTextPane whatsNewTextPane = new JTextPane();
+ whatsNewTextPane.setEditable(false);
+ whatsNewTextPane.setContentType("text/html");
+ whatsNewTextPane.setText(htmlReleaseBody);
+ JScrollPane scrollPane = new JScrollPane(whatsNewTextPane);
+ scrollPane.setBorder(null);
+ scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
+ scrollPane.setPreferredSize(new Dimension(150, 300));
+
+ JPanel panel = new JPanel();
+ BoxLayout boxlayout = new BoxLayout(panel, BoxLayout.Y_AXIS); // Top to bottom
+ panel.setBorder(null);
+ panel.setLayout(boxlayout);
+ panel.add(label);
+ panel.add(scrollPane);
+
+ Object[] choices = {"Update now", "Remind me later"};
Object defaultChoice = choices[0];
+ int response = JOptionPane.showOptionDialog(mainMenuFrame, panel, "Update FutureRestore GUI", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, defaultChoice);
- int response = JOptionPane.showOptionDialog(mainMenuInstance.mainMenuView, "A newer version of FutureRestore GUI is available.\n" +
- "You're on version " + currentFRGUIVersion + " and the latest version is " + newestTag + ".\n" +
- "https://github.com/CoocooFroggy/FutureRestore-GUI/releases", "Update FutureRestore GUI", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, defaultChoice);
if (response == JOptionPane.YES_OPTION) {
- FutureRestoreWorker.openWebpage("https://github.com/CoocooFroggy/FutureRestore-GUI/releases");
+// FRUtils.openWebpage("https://github.com/CoocooFroggy/FutureRestore-GUI/releases");
+ boolean didSucceedUpdate = FRUtils.updateFRGUI(mainMenuInstance);
+ // If update failed fatally, enable everything again
+ if (!didSucceedUpdate) {
+ FRUtils.setEnabled(mainMenuInstance.mainMenuView, true, true);
+ }
}
+
} else {
System.out.println("You're on the latest version of FutureRestore GUI.");
- mainMenuInstance.appendToLog("You're on the latest version of FutureRestore GUI.");
+ mainMenuInstance.messageToLog("You're on the latest version of FutureRestore GUI.");
}
- } catch (IOException e) {
+ } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}).start();
}
+ public static String getLatestFrguiReleaseBody() throws IOException {
+ String content = getRequestUrl("https://api.github.com/repos/CoocooFroggy/FutureRestore-GUI/releases");
+
+ Gson gson = new Gson();
+ ArrayList