#include "shell/common/application_info.h"
#include <gio/gdesktopappinfo.h>
#include <gio/gio.h>
#include <string>
#include "base/logging.h"
#include "electron/electron_version.h"
#include "shell/common/platform_util.h"
namespace {
GDesktopAppInfo* get_desktop_app_info() {
GDesktopAppInfo* ret = nullptr;
if (std::optional<std::string> desktop_id = platform_util::GetDesktopName())
ret = g_desktop_app_info_new(desktop_id->c_str());
return ret;
}
}
namespace electron {
std::string GetApplicationName() {
std::string ret = OverriddenApplicationName();
if (ret.empty()) {
GDesktopAppInfo* info = get_desktop_app_info();
if (info != nullptr) {
char* str = g_desktop_app_info_get_string(info, "Name");
g_clear_object(&info);
if (str != nullptr)
ret = str;
g_clear_pointer(&str, g_free);
}
}
if (ret.empty()) {
ret = ELECTRON_PRODUCT_NAME;
}
return ret;
}
std::string GetApplicationVersion() {
std::string ret;
if (GetApplicationName() == ELECTRON_PRODUCT_NAME)
ret = ELECTRON_VERSION_STRING;
if (ret.empty())
ret = OverriddenApplicationVersion();
if (ret.empty()) {
LOG(WARNING) << "No version found. Was app.setVersion() called?";
ret = "0.0";
}
return ret;
}
}