diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ab017ebc3..1d4bbedf3 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -20,7 +20,7 @@ assignees: '' **Chatterino version** - + **Additional context** diff --git a/chatterino.pro b/chatterino.pro index 29319e894..0230bba30 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -89,6 +89,7 @@ SOURCES += \ src/common/NetworkRequest.cpp \ src/common/NetworkResult.cpp \ src/common/UsernameSet.cpp \ + src/common/Version.cpp \ src/controllers/accounts/Account.cpp \ src/controllers/accounts/AccountController.cpp \ src/controllers/accounts/AccountModel.cpp \ diff --git a/src/common/Version.cpp b/src/common/Version.cpp new file mode 100644 index 000000000..e6a47ef38 --- /dev/null +++ b/src/common/Version.cpp @@ -0,0 +1,67 @@ +#include "common/Version.hpp" + +#include "common/Modes.hpp" + +#define UGLYMACROHACK1(s) #s +#define FROM_EXTERNAL_DEFINE(s) UGLYMACROHACK1(s) + +namespace chatterino { + +Version::Version() +{ + // Version + this->version_ = CHATTERINO_VERSION; + + // Commit hash + this->commitHash_ = + QString(FROM_EXTERNAL_DEFINE(CHATTERINO_GIT_HASH)).remove('"'); + + // Date of build +#ifdef CHATTERINO_NIGHTLY_VERSION_STRING + this->dateOfBuild_ = + QString(FROM_EXTERNAL_DEFINE(CHATTERINO_NIGHTLY_VERSION_STRING)) + .remove('"'); +#endif + + // "Full" version string, as displayed in window title + this->fullVersion_ = "Chatterino "; + if (Modes::getInstance().isNightly) + { + this->fullVersion_ += "Nightly "; + } + + this->fullVersion_ += this->version_; + + if (Modes::getInstance().isNightly) + { + this->fullVersion_ += this->dateOfBuild_; + } +} + +const Version &Version::getInstance() +{ + static Version instance; + return instance; +} + +const QString &Version::getVersion() const +{ + return this->version_; +} + +const QString &Version::getFullVersion() const +{ + return this->fullVersion_; +} + +const QString &Version::getCommitHash() const +{ + return this->commitHash_; +} + +const QString &Version::getDateOfBuild() const +{ + return this->dateOfBuild_; +} + +} // namespace chatterino diff --git a/src/common/Version.hpp b/src/common/Version.hpp index b97a70a54..dd3baa9fa 100644 --- a/src/common/Version.hpp +++ b/src/common/Version.hpp @@ -13,3 +13,26 @@ #else # define CHATTERINO_OS "unknown" #endif + +namespace chatterino { + +class Version +{ +public: + static const Version &getInstance(); + + const QString &getVersion() const; + const QString &getCommitHash() const; + const QString &getDateOfBuild() const; + const QString &getFullVersion() const; + +private: + Version(); + + QString version_; + QString commitHash_; + QString dateOfBuild_; + QString fullVersion_; +}; + +}; diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 0c4838abf..79b637671 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -364,30 +364,12 @@ void Window::addMenuBar() [=] { this->notebook_->selectPreviousTab(); }); } -#define UGLYMACROHACK1(s) #s -#define UGLYMACROHACK(s) UGLYMACROHACK1(s) - void Window::onAccountSelected() { auto user = getApp()->accounts->twitch.getCurrent(); // update title - QString title = "Chatterino "; - if (Modes::getInstance().isNightly) - { - title += "Nightly "; - } - title += CHATTERINO_VERSION; - - if (Modes::getInstance().isNightly) - { -#ifdef CHATTERINO_NIGHTLY_VERSION_STRING - title += - QString(" (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")"); -#endif - } - - this->setWindowTitle(title); + this->setWindowTitle(Version::getInstance().getFullVersion()); // update user if (user->isAnon()) diff --git a/src/widgets/settingspages/AboutPage.cpp b/src/widgets/settingspages/AboutPage.cpp index 71d0a01dc..fd1ce1d3f 100644 --- a/src/widgets/settingspages/AboutPage.cpp +++ b/src/widgets/settingspages/AboutPage.cpp @@ -1,5 +1,7 @@ #include "AboutPage.hpp" +#include "common/Modes.hpp" +#include "common/Version.hpp" #include "debug/Log.hpp" #include "util/LayoutCreator.hpp" #include "util/RemoveScrollAreaBackground.hpp" @@ -71,6 +73,24 @@ AboutPage::AboutPage() // } }*/ + auto versionInfo = layout.emplace("Version"); + { + auto version = Version::getInstance(); + QString text = QString("%1 (commit %2%3)") + .arg(version.getFullVersion()) + .arg("" + + version.getCommitHash() + "") + .arg(Modes::getInstance().isNightly ? ", " + version.getDateOfBuild() : ""); + + auto versionLabel = versionInfo.emplace(text); + versionLabel->setOpenExternalLinks(true); + versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | + Qt::LinksAccessibleByMouse); + } + auto licenses = layout.emplace("Open source software used..."); {