Skip to content

Commit 8589ead

Browse files
committed
Add support for enabling/disabling automatic update check
1 parent 20b3e9d commit 8589ead

5 files changed

Lines changed: 35 additions & 10 deletions

File tree

Source/AutoUpdater.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "AutoUpdater.h"
2626
#include "CoreServices.h"
27+
#include "MainWindow.h"
2728
#ifdef _WIN32
2829
#include <windows.h>
2930
#include <shellapi.h>
@@ -32,6 +33,7 @@
3233
//==============================================================================
3334
LatestVersionCheckerAndUpdater::LatestVersionCheckerAndUpdater()
3435
: Thread ("VersionChecker")
36+
, mainWindow(nullptr)
3537
{
3638
}
3739

@@ -41,11 +43,12 @@ LatestVersionCheckerAndUpdater::~LatestVersionCheckerAndUpdater()
4143
clearSingletonInstance();
4244
}
4345

44-
void LatestVersionCheckerAndUpdater::checkForNewVersion (bool background)
46+
void LatestVersionCheckerAndUpdater::checkForNewVersion (bool background, MainWindow* mw)
4547
{
4648
if (! isThreadRunning())
4749
{
4850
backgroundCheck = background;
51+
mainWindow = mw;
4952
startThread (3);
5053
}
5154
}
@@ -179,7 +182,7 @@ void LatestVersionCheckerAndUpdater::run()
179182
class UpdateDialog : public Component
180183
{
181184
public:
182-
UpdateDialog (const String& newVersion, const String& releaseNotes)
185+
UpdateDialog (const String& newVersion, const String& releaseNotes, bool automaticVerCheck)
183186
{
184187
titleLabel.setText ("Open Ephys GUI version " + newVersion, dontSendNotification);
185188
titleLabel.setFont (Font("Fira Sans", "SemiBold", 18.0f));
@@ -203,11 +206,13 @@ class UpdateDialog : public Component
203206
addAndMakeVisible (cancelButton);
204207
cancelButton.onClick = [this]
205208
{
206-
// ProjucerApplication::getApp().setAutomaticVersionCheckingEnabled (! dontAskAgainButton.getToggleState());
207-
exitModalStateWithResult (-1);
209+
if(dontAskAgainButton.getToggleState())
210+
exitModalStateWithResult (-1);
211+
else
212+
exitModalStateWithResult(0);
208213
};
209214

210-
dontAskAgainButton.setToggleState (false, dontSendNotification);
215+
dontAskAgainButton.setToggleState (!automaticVerCheck, dontSendNotification);
211216
addAndMakeVisible (dontAskAgainButton);
212217

213218
#if JUCE_MAC
@@ -251,14 +256,15 @@ class UpdateDialog : public Component
251256
}
252257

253258
static std::unique_ptr<DialogWindow> launchDialog (const String& newVersionString,
254-
const String& releaseNotes)
259+
const String& releaseNotes,
260+
bool automaticVerCheck)
255261
{
256262
DialogWindow::LaunchOptions options;
257263

258264
options.dialogTitle = "Download Open Ephys GUI version " + newVersionString + "?";
259265
options.resizable = false;
260266

261-
auto* content = new UpdateDialog (newVersionString, releaseNotes);
267+
auto* content = new UpdateDialog (newVersionString, releaseNotes, automaticVerCheck);
262268
options.content.set (content, true);
263269

264270
std::unique_ptr<DialogWindow> dialog (options.create());
@@ -319,7 +325,9 @@ void LatestVersionCheckerAndUpdater::askUserAboutNewVersion (const String& newVe
319325
const String& releaseNotes,
320326
const Asset& asset)
321327
{
322-
dialogWindow = UpdateDialog::launchDialog (newVersionString, releaseNotes);
328+
dialogWindow = UpdateDialog::launchDialog (newVersionString,
329+
releaseNotes,
330+
mainWindow->automaticVersionChecking);
323331

324332
if (auto* mm = ModalComponentManager::getInstance())
325333
{
@@ -328,6 +336,10 @@ void LatestVersionCheckerAndUpdater::askUserAboutNewVersion (const String& newVe
328336
{
329337
if (result == 1)
330338
askUserForLocationToDownload (asset);
339+
else if(result == -1)
340+
mainWindow->automaticVersionChecking = false;
341+
else if(result == 0)
342+
mainWindow->automaticVersionChecking = true;
331343

332344
dialogWindow.reset();
333345
}));

Source/AutoUpdater.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "../JuceLibraryCode/JuceHeader.h"
2828

29+
class MainWindow;
2930
class DownloadThread;
3031

3132
class LatestVersionCheckerAndUpdater : public DeletedAtShutdown,
@@ -42,7 +43,7 @@ class LatestVersionCheckerAndUpdater : public DeletedAtShutdown,
4243
const int size;
4344
};
4445

45-
void checkForNewVersion (bool isBackgroundCheck);
46+
void checkForNewVersion (bool isBackgroundCheck, MainWindow* mw);
4647

4748
//==============================================================================
4849
JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL (LatestVersionCheckerAndUpdater)
@@ -56,6 +57,7 @@ class LatestVersionCheckerAndUpdater : public DeletedAtShutdown,
5657

5758
//==============================================================================
5859
bool backgroundCheck = false;
60+
MainWindow* mainWindow;
5961

6062
std::unique_ptr<DownloadThread> downloader;
6163
std::unique_ptr<Component> dialogWindow;

Source/MainWindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "Utils/OpenEphysHttpServer.h"
2626
#include "UI/UIComponent.h"
2727
#include "UI/EditorViewport.h"
28+
#include "AutoUpdater.h"
2829
#include <stdio.h>
2930

3031

@@ -59,6 +60,7 @@ MainWindow::MainWindow(const File& fileToLoad)
5960
shouldReloadOnStartup = true;
6061
shouldEnableHttpServer = true;
6162
openDefaultConfigWindow = false;
63+
automaticVersionChecking = true;
6264

6365
// Create ProcessorGraph and AudioComponent, and connect them.
6466
// Callbacks will be set by the play button in the control panel
@@ -160,6 +162,9 @@ MainWindow::MainWindow(const File& fileToLoad)
160162
disableHttpServer();
161163
}
162164

165+
if(automaticVersionChecking)
166+
LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (true, this);
167+
163168
}
164169

165170
MainWindow::~MainWindow()
@@ -267,6 +272,7 @@ void MainWindow::saveWindowBounds()
267272
xml->setAttribute("version", JUCEApplication::getInstance()->getApplicationVersion());
268273
xml->setAttribute("shouldReloadOnStartup", shouldReloadOnStartup);
269274
xml->setAttribute("shouldEnableHttpServer", shouldEnableHttpServer);
275+
xml->setAttribute("automaticVersionChecking", automaticVersionChecking);
270276

271277
XmlElement* bounds = new XmlElement("BOUNDS");
272278
bounds->setAttribute("x",getScreenX());
@@ -330,6 +336,7 @@ void MainWindow::loadWindowBounds()
330336

331337
shouldReloadOnStartup = xml->getBoolAttribute("shouldReloadOnStartup", false);
332338
shouldEnableHttpServer = xml->getBoolAttribute("shouldEnableHttpServer", false);
339+
automaticVersionChecking = xml->getBoolAttribute("automaticVersionChecking", true);
333340

334341
for (auto* e : xml->getChildIterator())
335342
{

Source/MainWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ class MainWindow : public DocumentWindow
6868
/** Determines whether the ProcessorGraph http server is enabled. */
6969
bool shouldEnableHttpServer;
7070

71+
/** Determines whether the default config selection window needs to open on startup. */
7172
bool openDefaultConfigWindow;
7273

74+
/** Determines whether the Auto Updater needs to run on startup. */
75+
bool automaticVersionChecking;
76+
7377
/** Ends the process() callbacks and disables all processors.*/
7478
void shutDownGUI();
7579

Source/UI/UIComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ bool UIComponent::perform(const InvocationInfo& info)
863863

864864
case checkForUpdates:
865865
{
866-
LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (false);
866+
LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (false, mainWindow);
867867
break;
868868
}
869869

0 commit comments

Comments
 (0)