Skip to content

Commit

Permalink
Merge pull request #5914 from nextcloud/backport/5468/stable-3.9
Browse files Browse the repository at this point in the history
[stable-3.9] Improve macOS Sparkle updater
  • Loading branch information
mgallien authored Jul 24, 2023
2 parents 375f260 + 0eec4ab commit 434b60a
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 61 deletions.
8 changes: 7 additions & 1 deletion src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,15 @@ void GeneralSettings::slotUpdateInfo()
ocupdater->downloadState() != OCUpdater::DownloadComplete);
}
#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
else if (auto sparkleUpdater = qobject_cast<SparkleUpdater *>(updater)) {
else if (const auto sparkleUpdater = qobject_cast<SparkleUpdater *>(updater)) {
connect(sparkleUpdater, &SparkleUpdater::statusChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection);
_ui->updateStateLabel->setText(sparkleUpdater->statusString());
_ui->restartButton->setVisible(false);

const auto updaterState = sparkleUpdater->state();
const auto enableUpdateButton = updaterState == SparkleUpdater::State::Idle ||
updaterState == SparkleUpdater::State::Unknown;
_ui->updateButton->setEnabled(enableUpdateButton);
}
#endif

Expand Down
32 changes: 25 additions & 7 deletions src/gui/updater/sparkleupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,40 @@ namespace OCC {
class SparkleUpdater : public Updater
{
Q_OBJECT
Q_PROPERTY(QString statusString READ statusString NOTIFY statusChanged)
Q_PROPERTY(State state READ state NOTIFY statusChanged)

public:
SparkleUpdater(const QUrl &appCastUrl);
class SparkleInterface;
enum class State {
Unknown = 0,
Idle,
Working,
AwaitingUserInput
};

explicit SparkleUpdater(const QUrl &appCastUrl);
~SparkleUpdater() override;

void setUpdateUrl(const QUrl &url);
[[nodiscard]] static bool autoUpdaterAllowed();

// unused in this updater
[[nodiscard]] bool handleStartup() override { return false; }
[[nodiscard]] QString statusString() const;
[[nodiscard]] State state() const;

public slots:
void setUpdateUrl(const QUrl &url);
void checkForUpdate() override;
void backgroundCheckForUpdate() override;
bool handleStartup() override { return false; }

QString statusString();
signals:
void statusChanged();

private:
class Private;
Private *d;
std::unique_ptr<SparkleInterface> _interface;
QString _statusString;
State _state = State::Unknown;
friend class SparkleInterface;
};

} // namespace OCC
Expand Down
Loading

0 comments on commit 434b60a

Please sign in to comment.