Fix brightray::GetApplicationName(), ..Version() on Linux (#11980)
* add brightray API to override app version * in atom browser, use brightray app version API * on Linux, have GetApplicationVersion() use brightray version API * on Linux, implement brightray::GetApplicationName() * fix typo in brightray API * make browser.GetName() logic follow GetVersion() logic * improve variable name in OverrideApplicationVersion declaration * fix typo in brightray impl
This commit is contained in:
parent
dc62e51ba4
commit
8d086a43cb
6 changed files with 84 additions and 24 deletions
|
@ -97,27 +97,21 @@ void Browser::Shutdown() {
|
|||
}
|
||||
|
||||
std::string Browser::GetVersion() const {
|
||||
if (version_override_.empty()) {
|
||||
std::string version = GetExecutableFileVersion();
|
||||
if (!version.empty())
|
||||
return version;
|
||||
}
|
||||
|
||||
return version_override_;
|
||||
std::string ret = brightray::GetOverriddenApplicationVersion();
|
||||
if (ret.empty())
|
||||
ret = GetExecutableFileVersion();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Browser::SetVersion(const std::string& version) {
|
||||
version_override_ = version;
|
||||
brightray::OverrideApplicationVersion(version);
|
||||
}
|
||||
|
||||
std::string Browser::GetName() const {
|
||||
if (name_override_.empty()) {
|
||||
std::string name = GetExecutableFileProductName();
|
||||
if (!name.empty())
|
||||
return name;
|
||||
}
|
||||
|
||||
return name_override_;
|
||||
std::string ret = name_override_;
|
||||
if (ret.empty())
|
||||
ret = GetExecutableFileProductName();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Browser::SetName(const std::string& name) {
|
||||
|
|
|
@ -273,7 +273,6 @@ class Browser : public WindowListObserver {
|
|||
// The browser is being shutdown.
|
||||
bool is_shutdown_;
|
||||
|
||||
std::string version_override_;
|
||||
std::string name_override_;
|
||||
|
||||
int badge_count_ = 0;
|
||||
|
|
|
@ -2,18 +2,74 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "brightray/common/application_info.h"
|
||||
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/atom_version.h"
|
||||
#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
|
||||
|
||||
namespace brightray {
|
||||
|
||||
std::string GetApplicationName() {
|
||||
return ATOM_PRODUCT_NAME;
|
||||
// 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;
|
||||
}
|
||||
|
||||
std::string GetApplicationVersion() {
|
||||
return ATOM_VERSION_STRING;
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -4,15 +4,23 @@ namespace brightray {
|
|||
|
||||
namespace {
|
||||
|
||||
std::string g_overriden_application_name;
|
||||
std::string g_overridden_application_name;
|
||||
std::string g_overridden_application_version;
|
||||
|
||||
}
|
||||
|
||||
void OverrideApplicationName(const std::string& name) {
|
||||
g_overriden_application_name = name;
|
||||
g_overridden_application_name = name;
|
||||
}
|
||||
std::string GetOverridenApplicationName() {
|
||||
return g_overriden_application_name;
|
||||
std::string GetOverriddenApplicationName() {
|
||||
return g_overridden_application_name;
|
||||
}
|
||||
|
||||
void OverrideApplicationVersion(const std::string& version) {
|
||||
g_overridden_application_version = version;
|
||||
}
|
||||
std::string GetOverriddenApplicationVersion() {
|
||||
return g_overridden_application_version;
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -10,7 +10,10 @@
|
|||
namespace brightray {
|
||||
|
||||
void OverrideApplicationName(const std::string& name);
|
||||
std::string GetOverridenApplicationName();
|
||||
std::string GetOverriddenApplicationName();
|
||||
|
||||
void OverrideApplicationVersion(const std::string& version);
|
||||
std::string GetOverriddenApplicationVersion();
|
||||
|
||||
std::string GetApplicationName();
|
||||
std::string GetApplicationVersion();
|
||||
|
|
|
@ -47,7 +47,7 @@ PCWSTR GetRawAppUserModelID() {
|
|||
if (SUCCEEDED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id))) {
|
||||
g_app_user_model_id = current_app_id;
|
||||
} else {
|
||||
std::string name = GetOverridenApplicationName();
|
||||
std::string name = GetOverriddenApplicationName();
|
||||
if (name.empty()) {
|
||||
name = GetApplicationName();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue