2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-12-31 12:24:30 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-02-20 16:16:51 +00:00
|
|
|
#include "brightray/common/application_info.h"
|
|
|
|
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
#include <memory>
|
2013-12-31 12:24:30 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/atom_version.h"
|
2018-02-20 16:16:51 +00:00
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
GDesktopAppInfo* get_desktop_app_info() {
|
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
const std::string desktop_id = libgtkui::GetDesktopName(env.get());
|
|
|
|
return desktop_id.empty() ? nullptr
|
|
|
|
: g_desktop_app_info_new(desktop_id.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2013-12-31 12:24:30 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
|
|
|
std::string GetApplicationName() {
|
2018-02-20 16:16:51 +00:00
|
|
|
// attempt #1: the string set in app.setName()
|
|
|
|
std::string ret = GetOverriddenApplicationName();
|
|
|
|
|
|
|
|
// attempt #2: the 'Name' entry from .desktop file's [Desktop] section
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// attempt #3: Electron's name
|
|
|
|
if (ret.empty()) {
|
|
|
|
ret = ATOM_PRODUCT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-12-31 12:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetApplicationVersion() {
|
2018-02-20 16:16:51 +00:00
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
// ensure ATOM_PRODUCT_NAME and ATOM_PRODUCT_STRING match up
|
|
|
|
if (GetApplicationName() == ATOM_PRODUCT_NAME)
|
|
|
|
ret = ATOM_VERSION_STRING;
|
|
|
|
|
|
|
|
// try to use the string set in app.setVersion()
|
|
|
|
if (ret.empty())
|
|
|
|
ret = GetOverriddenApplicationVersion();
|
|
|
|
|
|
|
|
// no known version number; return some safe fallback
|
|
|
|
if (ret.empty()) {
|
|
|
|
LOG(WARNING) << "No version found. Was app.setVersion() called?";
|
|
|
|
ret = "0.0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-12-31 12:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace brightray
|