Improve iOS machine hostname in case it returns only localhost

pull/1129/head
Simon Stürz 2025-12-02 09:31:51 +01:00
parent 7eea6bd2c0
commit 1e3171a379
1 changed files with 24 additions and 1 deletions

View File

@ -30,6 +30,7 @@
#include <QTimer> #include <QTimer>
#include <QWindow> #include <QWindow>
#include <QtWebView> #include <QtWebView>
#include <sys/utsname.h>
PlatformHelperIOS::PlatformHelperIOS(QObject *parent) : PlatformHelper(parent) PlatformHelperIOS::PlatformHelperIOS(QObject *parent) : PlatformHelper(parent)
{ {
@ -61,7 +62,21 @@ void PlatformHelperIOS::hideSplashScreen()
QString PlatformHelperIOS::machineHostname() const QString PlatformHelperIOS::machineHostname() const
{ {
return QSysInfo::machineHostName(); const QString hostName = QSysInfo::machineHostName();
if (!hostName.isEmpty() && hostName != "localhost") {
return hostName;
}
// Fall back to something user visible when the OS only reports "localhost".
const QString model = deviceModel();
const QString manufacturer = deviceManufacturer();
if (model.isEmpty()) {
return manufacturer;
}
if (manufacturer.isEmpty() || model.startsWith(manufacturer)) {
return model;
}
return manufacturer + " " + model;
} }
QString PlatformHelperIOS::device() const QString PlatformHelperIOS::device() const
@ -87,6 +102,14 @@ QString PlatformHelperIOS::deviceSerial() const
QString PlatformHelperIOS::deviceModel() const QString PlatformHelperIOS::deviceModel() const
{ {
struct utsname systemInfo;
if (uname(&systemInfo) == 0) {
const QString machine = QString::fromUtf8(systemInfo.machine);
if (!machine.isEmpty()) {
return machine;
}
}
return QSysInfo::prettyProductName(); return QSysInfo::prettyProductName();
} }