Kylin/Fluent/Utilities.cpp
2024-08-23 00:04:16 +08:00

73 lines
1.7 KiB
C++

#include "Utilities.h"
#include <QSettings>
Utilities *Utilities::instance() {
static Utilities *self = nullptr;
if (self == nullptr) {
self = new Utilities();
}
return self;
}
Utilities *Utilities::create(QQmlEngine *, QJSEngine *) {
auto ret = instance();
QJSEngine::setObjectOwnership(ret, QJSEngine::CppOwnership);
return ret;
}
Utilities::Utilities(QObject *parent) : QObject{parent} {
}
QRect Utilities::desktopAvailableGeometry(QQuickWindow *window) {
return window->screen()->availableGeometry();
}
QUrl Utilities::getUrlByFilePath(const QString &path) {
return QUrl::fromLocalFile(path);
}
bool Utilities::isMacos() {
#if defined(Q_OS_MACOS)
return true;
#else
return false;
#endif
}
bool Utilities::isWin() {
#if defined(Q_OS_WIN)
return true;
#else
return false;
#endif
}
int Utilities::windowBuildNumber() {
#if defined(Q_OS_WIN)
QSettings regKey{QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"),
QSettings::NativeFormat};
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
return buildNumber;
}
#endif
return -1;
}
bool Utilities::isWindows11OrGreater() {
static QVariant var;
if (var.isNull()) {
#if defined(Q_OS_WIN)
auto buildNumber = windowBuildNumber();
if (buildNumber >= 22000) {
var = QVariant::fromValue(true);
return true;
}
#endif
var = QVariant::fromValue(false);
return false;
} else {
return var.toBool();
}
}