Added status messages to GuiThemeDownloader

This commit is contained in:
Leon Styhre 2023-03-29 22:21:55 +02:00
parent 3c23f38b9a
commit b0cf51aa6b
2 changed files with 55 additions and 13 deletions

View file

@ -133,7 +133,7 @@ GuiThemeDownloader::GuiThemeDownloader()
(mRenderer->getScreenHeight() - mSize.y) / 2.0f); (mRenderer->getScreenHeight() - mSize.y) / 2.0f);
mBusyAnim.setSize(mSize); mBusyAnim.setSize(mSize);
mBusyAnim.setText("100%"); mBusyAnim.setText("DOWNLOADING THEMES LIST 100%");
mBusyAnim.onSizeChanged(); mBusyAnim.onSizeChanged();
mList->setCursorChangedCallback([this](CursorState state) { mList->setCursorChangedCallback([this](CursorState state) {
@ -167,7 +167,7 @@ bool GuiThemeDownloader::fetchRepository(const std::string& repositoryName,
int errorCode {0}; int errorCode {0};
const std::string path {mThemeDirectory + repositoryName}; const std::string path {mThemeDirectory + repositoryName};
mRepositoryError = RepositoryError::NO_REPO_ERROR; mRepositoryError = RepositoryError::NO_REPO_ERROR;
mErrorMessage = ""; mMessage = "";
const bool isThemesList {repositoryName == "themes-list"}; const bool isThemesList {repositoryName == "themes-list"};
git_repository* repository {nullptr}; git_repository* repository {nullptr};
@ -265,6 +265,8 @@ bool GuiThemeDownloader::fetchRepository(const std::string& repositoryName,
if (mergeAnalysis & GIT_MERGE_ANALYSIS_UP_TO_DATE) { if (mergeAnalysis & GIT_MERGE_ANALYSIS_UP_TO_DATE) {
LOG(LogInfo) << "Repository \"" << repositoryName << "\" already up to date"; LOG(LogInfo) << "Repository \"" << repositoryName << "\" already up to date";
if (repositoryName != "themes-list")
mMessage = "THEME ALREADY UP TO DATE";
git_annotated_commit_free(annotated); git_annotated_commit_free(annotated);
git_object_free(object); git_object_free(object);
mPromise.set_value(true); mPromise.set_value(true);
@ -318,7 +320,7 @@ bool GuiThemeDownloader::fetchRepository(const std::string& repositoryName,
catch (std::runtime_error& runtimeError) { catch (std::runtime_error& runtimeError) {
const git_error* gitError {git_error_last()}; const git_error* gitError {git_error_last()};
LOG(LogError) << "GuiThemeDownloader: " << runtimeError.what() << gitError->message; LOG(LogError) << "GuiThemeDownloader: " << runtimeError.what() << gitError->message;
mErrorMessage = gitError->message; mMessage = gitError->message;
git_error_clear(); git_error_clear();
if (gitRemote != nullptr) if (gitRemote != nullptr)
git_remote_disconnect(gitRemote); git_remote_disconnect(gitRemote);
@ -326,6 +328,9 @@ bool GuiThemeDownloader::fetchRepository(const std::string& repositoryName,
return true; return true;
} }
if (repositoryName != "themes-list")
mMessage = "THEME HAS BEEN UPDATED";
mPromise.set_value(true); mPromise.set_value(true);
return false; return false;
} }
@ -525,7 +530,6 @@ void GuiThemeDownloader::parseThemesList()
} }
} }
mWindow->queueInfoPopup("PARSED " + std::to_string(mThemeSets.size()) + " THEME SETS", 6000);
LOG(LogInfo) << "GuiThemeDownloader: Parsed " << mThemeSets.size() << " theme sets"; LOG(LogInfo) << "GuiThemeDownloader: Parsed " << mThemeSets.size() << " theme sets";
} }
@ -569,6 +573,8 @@ void GuiThemeDownloader::populateGUI()
mFuture = mPromise.get_future(); mFuture = mPromise.get_future();
mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this, mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this,
theme.reponame, theme.url); theme.reponame, theme.url);
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
}, },
"ABORT", [] { return; }, "", nullptr, true, true, "ABORT", [] { return; }, "", nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ? (mRenderer->getIsVerticalOrientation() ?
@ -587,6 +593,8 @@ void GuiThemeDownloader::populateGUI()
mFuture = mPromise.get_future(); mFuture = mPromise.get_future();
mFetchThread = std::thread(&GuiThemeDownloader::fetchRepository, this, mFetchThread = std::thread(&GuiThemeDownloader::fetchRepository, this,
theme.reponame, theme.url, true); theme.reponame, theme.url, true);
mStatusType = StatusType::STATUS_UPDATING;
mStatusText = "UPDATING THEME";
}, },
"ABORT", [] { return; }, "", nullptr, true, true, "ABORT", [] { return; }, "", nullptr, true, true,
(mRenderer->getIsVerticalOrientation() ? (mRenderer->getIsVerticalOrientation() ?
@ -597,11 +605,15 @@ void GuiThemeDownloader::populateGUI()
mFuture = mPromise.get_future(); mFuture = mPromise.get_future();
mFetchThread = std::thread(&GuiThemeDownloader::fetchRepository, this, mFetchThread = std::thread(&GuiThemeDownloader::fetchRepository, this,
theme.reponame, theme.url, false); theme.reponame, theme.url, false);
mStatusType = StatusType::STATUS_UPDATING;
mStatusText = "UPDATING THEME";
} }
else { else {
mFuture = mPromise.get_future(); mFuture = mPromise.get_future();
mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this, mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this,
theme.reponame, theme.url); theme.reponame, theme.url);
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEME";
} }
}); });
mList->addRow(row); mList->addRow(row);
@ -681,9 +693,10 @@ void GuiThemeDownloader::update(int deltaTime)
mFetching = false; mFetching = false;
if (mRepositoryError != RepositoryError::NO_REPO_ERROR) { if (mRepositoryError != RepositoryError::NO_REPO_ERROR) {
std::string errorMessage {"ERROR: "}; std::string errorMessage {"ERROR: "};
errorMessage.append(Utils::String::toUpper(mErrorMessage)); errorMessage.append(Utils::String::toUpper(mMessage));
mWindow->queueInfoPopup(errorMessage, 6000); mWindow->queueInfoPopup(errorMessage, 6000);
LOG(LogError) << "Error: " << mErrorMessage; LOG(LogError) << "Error: " << mMessage;
mMessage = "";
} }
if (mThemeSets.empty() && mLatestThemesList) { if (mThemeSets.empty() && mLatestThemesList) {
parseThemesList(); parseThemesList();
@ -700,21 +713,38 @@ void GuiThemeDownloader::update(int deltaTime)
if (mFetching) { if (mFetching) {
int progress {mReceivedObjectsProgress != 1.0f ? 0 : 100}; int progress {mReceivedObjectsProgress != 1.0f ? 0 : 100};
if (mStatusType != StatusType::STATUS_NO_CHANGE) {
if (mStatusType == StatusType::STATUS_DOWNLOADING)
mBusyAnim.setText(mStatusText + " 100%");
else if (mStatusType == StatusType::STATUS_UPDATING)
mBusyAnim.setText(mStatusText);
mBusyAnim.onSizeChanged();
mStatusType = StatusType::STATUS_NO_CHANGE;
}
if (mReceivedObjectsProgress != 1.0f) { if (mReceivedObjectsProgress != 1.0f) {
progress = static_cast<int>( progress = static_cast<int>(
std::round(glm::mix(0.0f, 100.0f, static_cast<float>(mReceivedObjectsProgress)))); std::round(glm::mix(0.0f, 100.0f, static_cast<float>(mReceivedObjectsProgress))));
const std::string progressText {std::to_string(progress) + "%"}; if (mStatusText.substr(0, 11) == "DOWNLOADING")
mBusyAnim.setText(progressText); mBusyAnim.setText(mStatusText + " " + std::to_string(progress) + "%");
else
mBusyAnim.setText(mStatusText);
} }
else if (mReceivedObjectsProgress != 0.0f) { else if (mReceivedObjectsProgress != 0.0f) {
progress = static_cast<int>( progress = static_cast<int>(
std::round(glm::mix(0.0f, 100.0f, static_cast<float>(mResolveDeltaProgress)))); std::round(glm::mix(0.0f, 100.0f, static_cast<float>(mResolveDeltaProgress))));
const std::string progressText {std::to_string(progress) + "%"}; if (mStatusText.substr(0, 11) == "DOWNLOADING")
mBusyAnim.setText(progressText); mBusyAnim.setText(mStatusText + " " + std::to_string(progress) + "%");
else
mBusyAnim.setText(mStatusText);
} }
mBusyAnim.update(deltaTime); mBusyAnim.update(deltaTime);
} }
if (mMessage != "") {
mWindow->queueInfoPopup(mMessage, 6000);
mMessage = "";
}
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
@ -783,7 +813,7 @@ bool GuiThemeDownloader::input(InputConfig* config, Input input)
return true; return true;
} }
return mGrid.input(config, input); return GuiComponent::input(config, input);
} }
std::vector<HelpPrompt> GuiThemeDownloader::getHelpPrompts() std::vector<HelpPrompt> GuiThemeDownloader::getHelpPrompts()
@ -823,10 +853,14 @@ bool GuiThemeDownloader::fetchThemesList()
mFetchThread = mFetchThread =
std::thread(&GuiThemeDownloader::fetchRepository, this, repositoryName, url, false); std::thread(&GuiThemeDownloader::fetchRepository, this, repositoryName, url, false);
mStatusType = StatusType::STATUS_UPDATING;
mStatusText = "UPDATING THEMES LIST";
} }
else { else {
LOG(LogInfo) << "GuiThemeDownloader: Creating initial themes list repository clone"; LOG(LogInfo) << "GuiThemeDownloader: Creating initial themes list repository clone";
mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this, repositoryName, url); mFetchThread = std::thread(&GuiThemeDownloader::cloneRepository, this, repositoryName, url);
mStatusType = StatusType::STATUS_DOWNLOADING;
mStatusText = "DOWNLOADING THEMES LIST";
return false; return false;
} }
@ -892,7 +926,7 @@ bool GuiThemeDownloader::cloneRepository(const std::string& repositoryName, cons
const git_error* gitError {git_error_last()}; const git_error* gitError {git_error_last()};
LOG(LogWarning) << "GuiThemeDownloader: Git returned error code " << errorCode LOG(LogWarning) << "GuiThemeDownloader: Git returned error code " << errorCode
<< ", error message: \"" << gitError->message << "\""; << ", error message: \"" << gitError->message << "\"";
mErrorMessage = gitError->message; mMessage = gitError->message;
git_error_clear(); git_error_clear();
mPromise.set_value(true); mPromise.set_value(true);
return true; return true;

View file

@ -110,6 +110,12 @@ private:
std::vector<ThemeGUIEntry> mThemeGUIEntries; std::vector<ThemeGUIEntry> mThemeGUIEntries;
enum class StatusType {
STATUS_NO_CHANGE,
STATUS_DOWNLOADING,
STATUS_UPDATING
};
enum class RepositoryError { enum class RepositoryError {
NO_REPO_ERROR, NO_REPO_ERROR,
MANUALLY_DOWNLOADED, MANUALLY_DOWNLOADED,
@ -121,7 +127,7 @@ private:
RepositoryError mRepositoryError; RepositoryError mRepositoryError;
std::string mThemeDirectory; std::string mThemeDirectory;
std::string mErrorMessage; std::string mMessage;
std::thread mFetchThread; std::thread mFetchThread;
std::promise<bool> mPromise; std::promise<bool> mPromise;
std::future<bool> mFuture; std::future<bool> mFuture;
@ -130,6 +136,8 @@ private:
static inline std::atomic<float> mReceivedObjectsProgress {0.0f}; static inline std::atomic<float> mReceivedObjectsProgress {0.0f};
static inline std::atomic<float> mResolveDeltaProgress {0.0f}; static inline std::atomic<float> mResolveDeltaProgress {0.0f};
std::vector<ThemeEntry> mThemeSets; std::vector<ThemeEntry> mThemeSets;
StatusType mStatusType;
std::string mStatusText;
std::shared_ptr<ImageComponent> mScrollUp; std::shared_ptr<ImageComponent> mScrollUp;
std::shared_ptr<ImageComponent> mScrollDown; std::shared_ptr<ImageComponent> mScrollDown;