Skip to content

Commit

Permalink
KDESKTOP-1130 - Fix locked version management
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementKunz committed Oct 15, 2024
1 parent 24c7ef2 commit b52696b
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 113 deletions.
5 changes: 2 additions & 3 deletions src/gui/clientgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void ClientGui::showSynthesisDialog() {
_synthesisPopover->setPosition(trayIconRect);
raiseDialog(_synthesisPopover.get());
}
_synthesisPopover->onUpdateAvailabalityChange();
_synthesisPopover->refreshLockedStatus();
}
}

Expand All @@ -322,8 +322,7 @@ int ClientGui::driveErrorsCount(int driveDbId, bool unresolved) const {
}

const QString ClientGui::folderPath(int syncDbId, const QString &filePath) const {
QString fullFilePath = QString();

QString fullFilePath;
const auto syncInfoIt = _syncInfoMap.find(syncDbId);
if (syncInfoIt != _syncInfoMap.end()) {
fullFilePath = syncInfoIt->second.localPath() + dirSeparator + filePath;
Expand Down
23 changes: 10 additions & 13 deletions src/gui/guirequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,7 @@ ExitCode GuiRequests::changeDistributionChannel(const DistributionChannel channe
QDataStream paramsStream(&params, QIODevice::WriteOnly);
paramsStream << channel;

QByteArray results;
if (!CommClient::instance()->execute(RequestNum::UPDATER_CHANGE_CHANNEL, params, results)) {
if (QByteArray results; !CommClient::instance()->execute(RequestNum::UPDATER_CHANGE_CHANNEL, params, results)) {
return ExitCode::SystemError;
}
return ExitCode::Ok;
Expand Down Expand Up @@ -1239,8 +1238,7 @@ ExitCode GuiRequests::updateState(UpdateState &state) {
}

ExitCode GuiRequests::startInstaller() {
QByteArray results;
if (!CommClient::instance()->execute(RequestNum::UPDATER_START_INSTALLER, QByteArray(), results)) {
if (QByteArray results; !CommClient::instance()->execute(RequestNum::UPDATER_START_INSTALLER, QByteArray(), results)) {
return ExitCode::SystemError;
}
return ExitCode::Ok;
Expand All @@ -1251,19 +1249,18 @@ ExitCode GuiRequests::skipUpdate(const std::string &version) {
QDataStream paramsStream(&params, QIODevice::WriteOnly);
paramsStream << QString::fromStdString(version);

QByteArray results;
if (!CommClient::instance()->execute(RequestNum::UPDATER_SKIP_VERSION, params, results)) {
if (QByteArray results; !CommClient::instance()->execute(RequestNum::UPDATER_SKIP_VERSION, params, results)) {
return ExitCode::SystemError;
}
return ExitCode::Ok;
}

ExitCode GuiRequests::unskipUpdate() {
QByteArray results;
if (!CommClient::instance()->execute(RequestNum::RECONSIDER_SKIPPED_UPDATE, QByteArray(), results)) {
return ExitCode::SystemError;
}
return ExitCode::Ok;
}
// ExitCode GuiRequests::unskipUpdate() {
// QByteArray results;
// if (!CommClient::instance()->execute(RequestNum::RECONSIDER_SKIPPED_UPDATE, QByteArray(), results)) {
// return ExitCode::SystemError;
// }
// return ExitCode::Ok;
// }

} // namespace KDC
2 changes: 1 addition & 1 deletion src/gui/guirequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ struct GuiRequests {
static ExitCode updateState(UpdateState &state);
static ExitCode startInstaller();
static ExitCode skipUpdate(const std::string &version);
static ExitCode unskipUpdate();
// static ExitCode unskipUpdate();
};
} // namespace KDC
91 changes: 39 additions & 52 deletions src/gui/synthesispopover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ void SynthesisPopover::forceRedraw() {
});
#endif
}
void SynthesisPopover::refreshLockedStatus() {
auto updateState = UpdateState::Unknown;
GuiRequests::updateState(updateState);
onUpdateAvailabalityChange(updateState);
}

void SynthesisPopover::changeEvent(QEvent *event) {
QDialog::changeEvent(event);
Expand All @@ -214,7 +219,7 @@ void SynthesisPopover::changeEvent(QEvent *event) {
}

void SynthesisPopover::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
Q_UNUSED(event)

QScreen *screen = QGuiApplication::screenAt(_sysTrayIconRect.center());
if (!screen) {
Expand Down Expand Up @@ -604,10 +609,10 @@ void SynthesisPopover::initUI() {
connect(_statusBarWidget, &StatusBarWidget::resumeSync, this, &SynthesisPopover::onResumeSync);
connect(_statusBarWidget, &StatusBarWidget::linkActivated, this, &SynthesisPopover::onLinkActivated);
connect(_buttonsBarWidget, &ButtonsBarWidget::buttonToggled, this, &SynthesisPopover::onButtonBarToggled);
// TODO : put back for locked versions
// connect(UpdaterClient::instance(), &UpdaterClient::downloadStateChanged, this,
// &SynthesisPopover::onUpdateAvailabalityChange,
// Qt::UniqueConnection);

connect(_lockedAppUpdateButton, &QPushButton::clicked, this, &SynthesisPopover::onStartInstaller, Qt::UniqueConnection);
connect(_gui.get(), &ClientGui::updateStateChanged, this, &SynthesisPopover::onUpdateAvailabalityChange,
Qt::UniqueConnection);
}

QUrl SynthesisPopover::syncUrl(int syncDbId, const QString &filePath) {
Expand Down Expand Up @@ -1062,52 +1067,34 @@ void SynthesisPopover::onUpdateSynchronizedListWidget() {
}
}

void SynthesisPopover::onUpdateAvailabalityChange() {
// if (!_lockedAppUpdateButton || !_lockedAppUpdateOptionalLabel) return;
// if (_lockedAppVersionWidget->isHidden()) return;
// QString statusString;
// UpdateState updateState = UpdateState::Unknown;
// // try {
// // if (!UpdaterClient::instance()->isSparkleUpdater()) {
// // statusString = UpdaterClient::instance()->statusString();
// // updateState = UpdaterClient::instance()->updateState();
// // } else {
// // updateState = UpdateState::Ready; // On macOS, we just start the installer (Sparkle does the rest)
// // }
// // } catch (std::exception const &) {
// // return;
// // }
// if (GuiRequests::updateState(updateState) != ExitCode::Ok) {
// qCWarning(lcSynthesisPopover()) << "Failed to fetch update state.";
// }
//
// _lockedAppUpdateButton->setEnabled(updateState == UpdateState::Ready);
// _lockedAppUpdateOptionalLabel->setVisible(updateState != UpdateState::Ready && updateState != UpdateState::Downloading);
// switch (updateState) {
// case UpdateState::Ready:
// _lockedAppUpdateButton->setText(tr("Update"));
// break;
// case UpdateState::Downloading:
// _lockedAppUpdateButton->setText(tr("Update download in progress"));
// break;
// case UpdateState::Skipped:
// UpdaterClient::instance()->unskipUpdate();
// case UpdateState::Checking:
// _lockedAppUpdateButton->setText(tr("Looking for update..."));
// break;
// case UpdateState::ManualOnly:
// _lockedAppUpdateButton->setText(tr("Manual update"));
// //_lockedAppUpdateOptionalLabel->setText(statusString);
// break;
// default:
// _lockedAppUpdateButton->setText(tr("Unavailable"));
// //_lockedAppUpdateOptionalLabel->setText(statusString);
// SentryHandler::instance()->captureMessage(
// SentryLevel::Fatal, "AppLocked",
// "406 uError received but unable to fetch an pdate: " + statusString.toStdString());
// break;
// }
// connect(_lockedAppUpdateButton, &QPushButton::clicked, this, &SynthesisPopover::onStartInstaller, Qt::UniqueConnection);
void SynthesisPopover::onUpdateAvailabalityChange(const UpdateState updateState) {
if (!_lockedAppUpdateButton || !_lockedAppUpdateOptionalLabel) return;
if (_lockedAppVersionWidget->isHidden()) return;

_lockedAppUpdateButton->setEnabled(updateState == UpdateState::Ready || updateState == UpdateState::Available);
_lockedAppUpdateOptionalLabel->setVisible(updateState != UpdateState::Ready && updateState != UpdateState::Downloading);
switch (updateState) {
case UpdateState::Ready:
case UpdateState::Available:
_lockedAppUpdateButton->setText(tr("Update"));
break;
case UpdateState::Downloading:
_lockedAppUpdateButton->setText(tr("Update download in progress"));
break;
case UpdateState::Checking:
_lockedAppUpdateButton->setText(tr("Looking for update..."));
break;
case UpdateState::ManualUpdateAvailable:
_lockedAppUpdateButton->setText(tr("Manual update"));
//_lockedAppUpdateOptionalLabel->setText(statusString);
break;
default:
_lockedAppUpdateButton->setText(tr("Unavailable"));
//_lockedAppUpdateOptionalLabel->setText(statusString);
SentryHandler::instance()->captureMessage(SentryLevel::Fatal, "AppLocked",
"406 uError received but unable to fetch an update");
break;
}
}

void SynthesisPopover::onStartInstaller() noexcept {
Expand All @@ -1124,7 +1111,7 @@ void SynthesisPopover::onAppVersionLocked(bool currentVersionLocked) {
_lockedAppVersionWidget->show();
setFixedSize(lockedWindowSize);
_gui->closeAllExcept(this);
onUpdateAvailabalityChange();
refreshLockedStatus();
} else if (!currentVersionLocked && _mainWidget->isHidden()) {
_lockedAppVersionWidget->hide();
_mainWidget->show();
Expand Down
8 changes: 5 additions & 3 deletions src/gui/synthesispopover.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class SynthesisPopover : public QDialog {
void setPosition(const QRect &sysTrayIconRect);
void forceRedraw();

void refreshLockedStatus();

signals:
void showParametersDialog(int syncDbId = 0, bool errorPage = false);
void exit();
Expand All @@ -87,7 +89,7 @@ class SynthesisPopover : public QDialog {
void onRefreshErrorList(int driveDbId);
void onAppVersionLocked(bool currentVersionLocked);
void onRefreshStatusNeeded();
void onUpdateAvailabalityChange();
void onUpdateAvailabalityChange(UpdateState updateState);

private:
std::shared_ptr<ClientGui> _gui;
Expand Down Expand Up @@ -127,8 +129,8 @@ class SynthesisPopover : public QDialog {
void paintEvent(QPaintEvent *event) override;
bool event(QEvent *event) override;

inline QColor backgroundMainColor() const { return _backgroundMainColor; }
inline void setBackgroundMainColor(const QColor &value) { _backgroundMainColor = value; }
[[nodiscard]] QColor backgroundMainColor() const { return _backgroundMainColor; }
void setBackgroundMainColor(const QColor &value) { _backgroundMainColor = value; }

void initUI();
QUrl syncUrl(int syncDbId, const QString &filePath);
Expand Down
3 changes: 1 addition & 2 deletions src/gui/versionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ void VersionWidget::refresh(UpdateState state /*= UpdateState::Unknown*/) const
break;
}
case UpdateState::Available:
case UpdateState::Ready:
case UpdateState::Skipped: {
case UpdateState::Ready: {
statusString = tr("An update is available: %1").arg(versionStr);
showReleaseNote = true;
showUpdateButton = true;
Expand Down
6 changes: 3 additions & 3 deletions src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ enum class RequestNum {
UPDATER_STATE,
UPDATER_START_INSTALLER,
UPDATER_SKIP_VERSION,
RECONSIDER_SKIPPED_UPDATE,
// RECONSIDER_SKIPPED_UPDATE,
UTILITY_CRASH,
UTILITY_QUIT,
};
Expand Down Expand Up @@ -270,8 +270,8 @@ inline std::string toString(RequestNum e) {
return "UPDATER_START_INSTALLER";
case RequestNum::UPDATER_SKIP_VERSION:
return "UPDATER_SKIP_VERSION";
case RequestNum::RECONSIDER_SKIPPED_UPDATE:
return "RECONSIDER_SKIPPED_UPDATE";
// case RequestNum::RECONSIDER_SKIPPED_UPDATE:
// return "RECONSIDER_SKIPPED_UPDATE";
case RequestNum::UTILITY_CRASH:
return "UTILITY_CRASH";
case RequestNum::UTILITY_QUIT:
Expand Down
1 change: 0 additions & 1 deletion src/libcommon/utility/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ enum class UpdateState {
ManualUpdateAvailable,
Downloading,
Ready,
Skipped,
CheckError,
DownloadError,
UpdateError,
Expand Down
13 changes: 7 additions & 6 deletions src/server/appserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,10 +1983,10 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
_updateManager->skipVersion(tmp.toStdString());
break;
}
case RequestNum::RECONSIDER_SKIPPED_UPDATE: {
_updateManager->unskipVersion();
break;
}
// case RequestNum::RECONSIDER_SKIPPED_UPDATE: {
// _updateManager->unskipVersion();
// break;
// }
case RequestNum::UTILITY_CRASH: {
resultStream << ExitCode::Ok;
QTimer::singleShot(QUIT_DELAY, []() { CommonUtility::crash(); });
Expand Down Expand Up @@ -3906,13 +3906,14 @@ void AppServer::addError(const Error &error) {

// Decrease JobManager pool capacity
JobManager::instance()->decreasePoolCapacity();
} else if (error.exitCode() == ExitCode::UpdateRequired) {
UpdateManager::unskipVersion();
}

if (!ServerRequests::isAutoResolvedError(error)) {
// Send error to sentry only for technical errors
SentryUser sentryUser(user.email().c_str(), user.name().c_str(), std::to_string(user.userId()).c_str());
SentryHandler::instance()->captureMessage(SentryLevel::Warning, "AppServer::addError", error.errorString().c_str(),
sentryUser);
SentryHandler::instance()->captureMessage(SentryLevel::Warning, "AppServer::addError", error.errorString(), sentryUser);
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/server/updater/abstractupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ void AbstractUpdater::onAppVersionReceived() {
}
}

void AbstractUpdater::skipVersion(const std::string& skippedVersion) const {
void AbstractUpdater::skipVersion(const std::string& skippedVersion) {
ParametersCache::instance()->parameters().setSeenVersion(skippedVersion);
ParametersCache::instance()->save();
}
void AbstractUpdater::unskipVersion() const {
ParametersCache::instance()->parameters().setSeenVersion("");
ParametersCache::instance()->save();

void AbstractUpdater::unskipVersion() {
if (!ParametersCache::instance()->parameters().seenVersion().empty()) {
ParametersCache::instance()->parameters().setSeenVersion("");
ParametersCache::instance()->save();
}
}

bool AbstractUpdater::isVersionSkipped(const std::string& version) const {
bool AbstractUpdater::isVersionSkipped(const std::string& version) {
if (version.empty()) return false;

const auto seenVerison = ParametersCache::instance()->parameters().seenVersion();
Expand Down
6 changes: 3 additions & 3 deletions src/server/updater/abstractupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class AbstractUpdater {
virtual void setQuitCallback(const std::function<void()> &quitCallback) { /* Redefined in child class if necessary */ }
void setStateChangeCallback(const std::function<void(UpdateState)> &stateChangeCallback);

void skipVersion(const std::string &skippedVersion) const;
void unskipVersion() const;
[[nodiscard]] bool isVersionSkipped(const std::string &version) const;
static void skipVersion(const std::string &skippedVersion);
static void unskipVersion();
[[nodiscard]] static bool isVersionSkipped(const std::string &version);

protected:
void setState(UpdateState newState);
Expand Down
2 changes: 0 additions & 2 deletions src/server/updater/sparkleupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

namespace KDC {

enum DownloadState { Unknown = 0, FindValidUpdate, DidNotFindUpdate, AbortWithError }; // TODO : useful??

class SparkleUpdater final : public AbstractUpdater {
public:
explicit SparkleUpdater();
Expand Down
Loading

0 comments on commit b52696b

Please sign in to comment.