From 2edced4d5d7c6c5c2242f5efcfe0e1945e4ea556 Mon Sep 17 00:00:00 2001 From: Richard Waltman Date: Tue, 28 Sep 2021 19:48:24 -0500 Subject: [PATCH] Further improvements to GUI Update Button logic --- CHANGELOG.md | 1 + OpenBCI_GUI/OpenBCI_GUI.pde | 1 + OpenBCI_GUI/TopNav.pde | 15 ++++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 940a9baf0..4336d8ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Improvements * Show info in footer when a new version of the GUI is available #992 +* Further improvements to GUI Update Button logic * Add GUI-wide settings class to keep certain settings across sessions and app starts #997 * Remove 30 second window option from Focus widget diff --git a/OpenBCI_GUI/OpenBCI_GUI.pde b/OpenBCI_GUI/OpenBCI_GUI.pde index 8245b5f48..662590055 100644 --- a/OpenBCI_GUI/OpenBCI_GUI.pde +++ b/OpenBCI_GUI/OpenBCI_GUI.pde @@ -64,6 +64,7 @@ String localGUIVersionString = "v5.0.7"; String localGUIVersionDate = "September 2021"; String guiLatestVersionGithubAPI = "https://api.github.com/repos/OpenBCI/OpenBCI_GUI/releases/latest"; String guiLatestReleaseLocation = "https://github.com/OpenBCI/OpenBCI_GUI/releases/latest"; +Boolean guiIsUpToDate; PApplet ourApplet; diff --git a/OpenBCI_GUI/TopNav.pde b/OpenBCI_GUI/TopNav.pde index b8d41b69d..0bf18568e 100644 --- a/OpenBCI_GUI/TopNav.pde +++ b/OpenBCI_GUI/TopNav.pde @@ -533,15 +533,20 @@ class TopNav { updateGuiVersionButton = createTNButton("updateGuiVersionButton", text, _x, _y, _w, _h, font, _fontSize, _bg, _textColor); //Attempt to compare local and remote GUI versions when TopNav is instantiated //This will also set the description/help-text for this cp5 button - final Boolean upToDate = guiVersionIsUpToDate(); + //Do this check on app start and store as a global variable + guiIsUpToDate = guiVersionIsUpToDate(); updateGuiVersionButton.onRelease(new CallbackListener() { public void controlEvent(CallbackEvent theEvent) { - if (upToDate == null) { + //Perform check again when button is pressed. User may have connected to internet by now! + guiIsUpToDate = guiVersionIsUpToDate(); + + if (guiIsUpToDate == null) { + outputError("Update GUI: Unable to check for new version of GUI. Try again when connected to the internet."); return; } - if (!upToDate) { + if (!guiIsUpToDate) { openURLInBrowser(guiLatestReleaseLocation); outputInfo("Update GUI: Opening latest GUI release page using default browser"); } else { @@ -550,11 +555,11 @@ class TopNav { } }); - if (upToDate == null) { + if (guiIsUpToDate == null) { return; } - if (!upToDate) { + if (!guiIsUpToDate) { outputWarn("Update Available! Press the \"Update\" button at the top of the GUI to download the latest version."); } }