From d23a89e78e5a9f2b75ad58ab008c9bff36ad3928 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Tue, 16 May 2023 21:04:25 -0500 Subject: [PATCH] Gui: Hack to ensure good macOS version number --- src/Gui/Splashscreen.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Gui/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index 2e3439dc97..08f645984f 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -59,6 +60,37 @@ using namespace Gui::Dialog; namespace fs = boost::filesystem; namespace Gui { + +QString prettyProductInfoWrapper() +{ + auto productName = QSysInfo::prettyProductName(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#ifdef FC_OS_MACOSX + auto macosVersionFile = QString::fromUtf8("/System/Library/CoreServices/.SystemVersionPlatform.plist"); + auto fi = QFileInfo (macosVersionFile); + if (fi.exists() && fi.isReadable()) { + auto plistFile = QFile(macosVersionFile); + plistFile.open(QIODevice::ReadOnly); + while (!plistFile.atEnd()) { + auto line = plistFile.readLine(); + if (line.contains("ProductUserVisibleVersion")) { + auto nextLine = plistFile.readLine(); + if (nextLine.contains("")) { + QRegularExpression re(QString::fromUtf8("\\s*(.*)")); + auto matches = re.match(QString::fromUtf8(nextLine)); + if (matches.hasMatch()) { + productName = QString::fromUtf8("macOS ") + matches.captured(1); + break; + } + } + } + } + } +#endif +#endif + return productName; +} + /** Displays all messages at startup inside the splash screen. * \author Werner Mayer */ @@ -349,7 +381,7 @@ void AboutDialog::setupLabels() ui->labelBuildDate->setText(date); QString os = ui->labelBuildOS->text(); - os.replace(QString::fromLatin1("Unknown"), QSysInfo::prettyProductName()); + os.replace(QString::fromLatin1("Unknown"), prettyProductInfoWrapper()); ui->labelBuildOS->setText(os); QString platform = ui->labelBuildPlatform->text(); @@ -745,7 +777,7 @@ void AboutDialog::copyToClipboard() } str << "[code]\n"; - str << "OS: " << QSysInfo::prettyProductName() << deskInfo << '\n'; + str << "OS: " << prettyProductInfoWrapper() << deskInfo << '\n'; str << "Word size of " << exe << ": " << QSysInfo::WordSize << "-bit\n"; str << "Version: " << major << "." << minor << "." << point << "." << build; char *appimage = getenv("APPIMAGE");