Skip to content

Commit

Permalink
Client|Refactor: Revising the Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 0a43595 commit 4c718e3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
8 changes: 0 additions & 8 deletions doomsday/apps/client/include/updater.h
Expand Up @@ -58,11 +58,6 @@ class Updater

de::ProgressWidget &progress();

// void gotReply(QNetworkReply *);
// void downloadProgressed(int percentage);
// void downloadCompleted(int result);
// void downloadFailed(QString);

void recheck();

/**
Expand All @@ -88,9 +83,6 @@ class Updater
*/
void printLastUpdated();

//protected slots:
// void downloadDialogClosed();

private:
DE_PRIVATE(d)
};
Expand Down
86 changes: 55 additions & 31 deletions doomsday/apps/client/src/updater/updater.cpp
Expand Up @@ -9,7 +9,7 @@
* replaced with the engine's own (scriptable) UI widgets (once they are
* available).
*
* @authors Copyright © 2012-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2012-2018 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
* @par License
Expand All @@ -27,13 +27,6 @@
* 02110-1301 USA</small>
*/

//#include <QDateTime>
//#include <StringList>
//#include <QDesktopServices>
//#include <QNetworkAccessManager>
//#include <QTextStream>
//#include <QDir>

#include "de_platform.h"

#ifdef WIN32
Expand All @@ -46,6 +39,7 @@
#include "dd_def.h"
#include "dd_types.h"
#include "dd_main.h"
#include "network/net_main.h"
#include "clientapp.h"
#include "ui/nativeui.h"
#include "ui/clientwindowsystem.h"
Expand All @@ -63,8 +57,8 @@
#include <de/Date>
#include <de/LogBuffer>
#include <de/NotificationAreaWidget>
//#include <de/SignalAction>
#include <de/Time>
#include <de/WebRequest>
#include <de/data/json.h>
#include <doomsday/console/exec.h>

Expand All @@ -83,11 +77,11 @@ static CommandLine* installerCommand;
*/
static void runInstallerCommand(void)
{
DE_ASSERT(installerCommand != 0);
DE_ASSERT(installerCommand != nullptr);

installerCommand->execute();
delete installerCommand;
installerCommand = 0;
installerCommand = nullptr;
}

/**
Expand Down Expand Up @@ -120,6 +114,8 @@ class UpdaterStatusWidget : public ProgressWidget
add(_clickable);
}

virtual ~UpdaterStatusWidget() = default;

void showIcon(DotPath const &path)
{
_icon->setImageColor(ClientApp::windowSystem().style().colors().colorf(path));
Expand All @@ -142,8 +138,10 @@ class UpdaterStatusWidget : public ProgressWidget

DE_PIMPL(Updater)
, DE_OBSERVES(App, StartupComplete)
, DE_OBSERVES(WebRequest, Progress)
, DE_OBSERVES(WebRequest, Finished)
{
// QNetworkAccessManager *network = nullptr;
WebRequest web;
UpdateDownloadDialog *download = nullptr; // not owned (in the widget tree, if exists)
UniqueWidgetPtr<UpdaterStatusWidget> status;
UpdateAvailableDialog *availableDlg = nullptr; ///< If currently open (not owned).
Expand All @@ -157,7 +155,9 @@ DE_PIMPL(Updater)

Impl(Public *i) : Base(i)
{
// network = new QNetworkAccessManager(thisPublic);
web.setUserAgent(Net_UserAgent());
web.audienceForProgress() += this;
web.audienceForFinished() += this;

// Delete a package installed earlier?
UpdaterSettings st;
Expand All @@ -177,6 +177,18 @@ DE_PIMPL(Updater)
st.setPathToDeleteAtStartup("");
}

void webRequestProgress(WebRequest &, dsize current, dsize total) override
{
DE_ASSERT(status);
status->setRange(Rangei(0, 100));
if (total) status->setProgress(current / total);
}

void webRequestFinished(WebRequest &) override
{

}

void setupUI()
{
status.reset(new UpdaterStatusWidget);
Expand Down Expand Up @@ -241,7 +253,7 @@ DE_PIMPL(Updater)
return false;
}

void appStartupCompleted()
void appStartupCompleted() override
{
LOG_AS("Updater")
LOG_DEBUG("App startup was completed");
Expand Down Expand Up @@ -383,7 +395,7 @@ DE_PIMPL(Updater)

void execAvailableDialog()
{
DE_ASSERT(availableDlg != 0);
DE_ASSERT(availableDlg != nullptr);

availableDlg->setDeleteAfterDismissed(true);
availableDlg->audienceForRecheck() += [this]() { self().recheck(); };
Expand All @@ -393,7 +405,7 @@ DE_PIMPL(Updater)
startDownload();
download->open();
}
availableDlg = 0;
availableDlg = nullptr;
}

void startDownload()
Expand All @@ -406,6 +418,17 @@ DE_PIMPL(Updater)
LOG_MSG("Download and install update");

download = new UpdateDownloadDialog(latestPackageUri, latestPackageUri2);
download->audienceForClose() += [this]() {
if (!download || download->isFailed())
{
if (download)
{
download->setDeleteAfterDismissed(true);
download = nullptr;
}
showNotification(false);
}
};
status->popupButton().setPopup(*download, ui::Down);
// download->audienceForClose() += [this]() { self().downloadDialogClosed(); }
// download->audienceForAccept() += [this]() { self().downloadCompleted(1); };
Expand All @@ -416,6 +439,22 @@ DE_PIMPL(Updater)
ClientWindow::main().root().addOnTop(download);
}

#if 0
void downloadDialogClosed()
// void panelBeingClosed(PanelWidget &)
{
if (!d->download || d->download->isFailed())
{
if (d->download)
{
d->download->setDeleteAfterDismissed(true);
d->download = 0;
}
d->showNotification(false);
}
}
#endif

/**
* Starts the installation process using the provided distribution package.
* The engine is first shut down gracefully (game has already been autosaved).
Expand Down Expand Up @@ -655,18 +694,3 @@ void Updater::printLastUpdated(void)
LOG_MSG("Latest update check was made %s") << ago;
}
}

#if 0
void Updater::downloadDialogClosed()
{
if (!d->download || d->download->isFailed())
{
if (d->download)
{
d->download->setDeleteAfterDismissed(true);
d->download = 0;
}
d->showNotification(false);
}
}
#endif
6 changes: 3 additions & 3 deletions doomsday/libs/gui/src/guiapp.cpp
Expand Up @@ -275,8 +275,8 @@ void GuiApp::revealFile(const NativePath &fileOrFolder) // static
#if defined (MACOSX)
{
using namespace std;
const NativePath scriptPath = cachePath() / "reveal_path.scpt";

const NativePath scriptPath = cachePath() / "reveal-path.scpt";
if (ofstream f{scriptPath.toStdString()})
{
// Apple Script to select a specific file.
Expand All @@ -287,7 +287,7 @@ void GuiApp::revealFile(const NativePath &fileOrFolder) // static
<< " end tell" << endl
<< "end run" << endl;
f.close();

CommandLine{{"/usr/bin/osascript", scriptPath, fileOrFolder}}.execute();
}
}
Expand Down

0 comments on commit 4c718e3

Please sign in to comment.