updated device_info to latest API

This commit is contained in:
kidfromjupiter
2025-12-29 16:35:50 +00:00
parent 6c41d26a86
commit 8f6086345d
2 changed files with 23 additions and 49 deletions
@@ -63,12 +63,10 @@ DeviceInfo::DeviceInfo(std::shared_ptr<sdbus::IConnection> system_bus)
current_user_session_(std::make_unique<CurrentUserSession>(*system_bus_)),
login_manager_(std::make_unique<LoginManager>(*system_bus_)) {}
std::optional<std::u16string> DeviceInfo::GetOsDeviceName() const {
std::optional<std::string> DeviceInfo::GetOsDeviceName() const {
avahi::Server avahi(*system_bus_);
try {
std::string hostname = avahi.GetHostNameFqdn();
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
return convert.from_bytes(hostname);
return avahi.GetHostNameFqdn();
} catch (const sdbus::Error &e) {
DBUS_LOG_PROPERTY_GET_ERROR(&avahi, "GetHostNameFqdn", e);
return std::nullopt;
@@ -94,58 +92,42 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const {
}
}
std::optional<std::u16string> DeviceInfo::GetFullName() const {
struct passwd *pwd = getpwuid(getuid());
if (pwd == nullptr) {
return std::nullopt;
}
char *name = strtok(pwd->pw_gecos, ",");
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
return convert.from_bytes(name != nullptr ? name : pwd->pw_gecos);
}
std::optional<std::string> DeviceInfo::GetProfileUserName() const {
char *logname = secure_getenv("LOGNAME");
return logname == nullptr ? std::nullopt
: std::optional(std::string(logname));
}
std::optional<std::filesystem::path> DeviceInfo::GetDownloadPath() const {
std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
char *dir = getenv("XDG_DOWNLOAD_DIR");
return std::filesystem::path(std::string(dir));
return FilePath(std::string(dir));
}
std::optional<std::filesystem::path> DeviceInfo::GetLocalAppDataPath() const {
std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const {
char *dir = getenv("XDG_CONFIG_HOME");
if (dir == nullptr) {
return std::filesystem::path("/tmp");
return FilePath("/tmp");
}
return std::filesystem::path(std::string(dir)) / "Google Nearby";
return FilePath(std::string((std::filesystem::path(std::string(dir)) / "Google Nearby")));
}
std::optional<std::filesystem::path> DeviceInfo::GetTemporaryPath() const {
std::optional<FilePath> DeviceInfo::GetTemporaryPath() const {
char *dir = getenv("XDG_RUNTIME_PATH");
if (dir == nullptr) {
return std::filesystem::path("/tmp");
return FilePath("/tmp");
}
return std::filesystem::path(std::string(dir)) / "Google Nearby";
return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby"));
}
std::optional<std::filesystem::path> DeviceInfo::GetLogPath() const {
std::optional<FilePath> DeviceInfo::GetLogPath() const {
char *dir = getenv("XDG_STATE_HOME");
if (dir == nullptr) {
return std::filesystem::path("/tmp");
return FilePath("/tmp");
}
return std::filesystem::path(std::string(dir)) / "Google Nearby" / "logs";
return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby" / "logs"));
}
std::optional<std::filesystem::path> DeviceInfo::GetCrashDumpPath() const {
std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
char *dir = getenv("XDG_STATE_HOME");
if (dir == nullptr) {
return std::filesystem::path("/tmp");
return FilePath("/tmp");
}
return std::filesystem::path(std::string(dir)) / "Google Nearby" / "crashes";
return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby" / "crashes"));
}
bool DeviceInfo::IsScreenLocked() const {
@@ -121,28 +121,20 @@ class DeviceInfo final : public api::DeviceInfo {
public:
explicit DeviceInfo(std::shared_ptr<sdbus::IConnection> system_bus);
std::optional<std::u16string> GetOsDeviceName() const override;
std::optional<std::string> GetOsDeviceName() const override;
api::DeviceInfo::DeviceType GetDeviceType() const override;
api::DeviceInfo::OsType GetOsType() const override {
return api::DeviceInfo::OsType::kWindows; // Or ChromeOS?
}
std::optional<std::u16string> GetFullName() const override;
std::optional<std::u16string> GetGivenName() const override {
return GetFullName();
}
std::optional<std::u16string> GetLastName() const override {
return GetFullName();
}
std::optional<std::string> GetProfileUserName() const override;
std::optional<std::filesystem::path> GetDownloadPath() const override;
std::optional<std::filesystem::path> GetLocalAppDataPath() const override;
std::optional<std::filesystem::path> GetCommonAppDataPath() const override {
std::optional<FilePath> GetDownloadPath() const override;
std::optional<FilePath> GetLocalAppDataPath() const override;
std::optional<FilePath> GetCommonAppDataPath() const override {
return std::nullopt;
};
std::optional<std::filesystem::path> GetTemporaryPath() const override;
std::optional<std::filesystem::path> GetLogPath() const override;
std::optional<std::filesystem::path> GetCrashDumpPath() const override;
std::optional<FilePath> GetTemporaryPath() const override;
std::optional<FilePath> GetLogPath() const override;
std::optional<FilePath> GetCrashDumpPath() const override;
bool IsScreenLocked() const override;
void RegisterScreenLockedListener(