Fix desktop-id notification edge case (#12216)
* Fix desktop-id notification edge case * Extract-method platform_util::GetDesktopName() This removes duplicated code from libnotify_notifications.cc and atom/common/linux/application_info.cc. * Check for empty case in GetDesktopName(). * Move GetDesktopName() to brightray::util * Remove unnecessary changes in platform_util * Add a brightray::platform_util namespace
This commit is contained in:
parent
86af20ded0
commit
dd2c2660b9
5 changed files with 62 additions and 8 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
#include "base/environment.h"
|
#include "base/environment.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
#include "brightray/common/platform_util.h"
|
||||||
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -20,10 +21,8 @@ namespace {
|
||||||
GDesktopAppInfo* get_desktop_app_info() {
|
GDesktopAppInfo* get_desktop_app_info() {
|
||||||
GDesktopAppInfo * ret = nullptr;
|
GDesktopAppInfo * ret = nullptr;
|
||||||
|
|
||||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
std::string desktop_id;
|
||||||
const std::string desktop_id = libgtkui::GetDesktopName(env.get());
|
if (brightray::platform_util::GetDesktopName(&desktop_id))
|
||||||
const char * libcc_default_id = "chromium-browser.desktop";
|
|
||||||
if (!desktop_id.empty() && (desktop_id != libcc_default_id))
|
|
||||||
ret = g_desktop_app_info_new(desktop_id.c_str());
|
ret = g_desktop_app_info_new(desktop_id.c_str());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/environment.h"
|
|
||||||
#include "base/files/file_enumerator.h"
|
#include "base/files/file_enumerator.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "brightray/browser/notification_delegate.h"
|
#include "brightray/browser/notification_delegate.h"
|
||||||
#include "brightray/common/application_info.h"
|
#include "brightray/common/application_info.h"
|
||||||
|
#include "brightray/common/platform_util.h"
|
||||||
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||||
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
|
#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
@ -130,9 +130,8 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
|
||||||
|
|
||||||
// Send the desktop name to identify the application
|
// Send the desktop name to identify the application
|
||||||
// The desktop-entry is the part before the .desktop
|
// The desktop-entry is the part before the .desktop
|
||||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
std::string desktop_id;
|
||||||
std::string desktop_id = libgtkui::GetDesktopName(env.get());
|
if (platform_util::GetDesktopName(&desktop_id)) {
|
||||||
if (!desktop_id.empty()) {
|
|
||||||
const std::string suffix{".desktop"};
|
const std::string suffix{".desktop"};
|
||||||
if (base::EndsWith(desktop_id, suffix,
|
if (base::EndsWith(desktop_id, suffix,
|
||||||
base::CompareCase::INSENSITIVE_ASCII)) {
|
base::CompareCase::INSENSITIVE_ASCII)) {
|
||||||
|
|
24
brightray/common/platform_util.h
Normal file
24
brightray/common/platform_util.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (c) 2018 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef BRIGHTRAY_COMMON_PLATFORM_UTIL_H_
|
||||||
|
#define BRIGHTRAY_COMMON_PLATFORM_UTIL_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
namespace platform_util {
|
||||||
|
|
||||||
|
#if defined(OS_LINUX)
|
||||||
|
// Returns a success flag.
|
||||||
|
// Unlike libgtkui, does *not* use "chromium-browser.desktop" as a fallback.
|
||||||
|
bool GetDesktopName(std::string* setme);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace platform_util
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
||||||
|
#endif // BRIGHTRAY_COMMON_PLATFORM_UTIL_H_
|
30
brightray/common/platform_util_linux.cc
Normal file
30
brightray/common/platform_util_linux.cc
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (c) 2018 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "brightray/common/platform_util.h"
|
||||||
|
|
||||||
|
#include "base/environment.h"
|
||||||
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
namespace platform_util {
|
||||||
|
|
||||||
|
bool GetDesktopName(std::string* setme) {
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
std::string desktop_id = libgtkui::GetDesktopName(env.get());
|
||||||
|
constexpr char const* libcc_default_id = "chromium-browser.desktop";
|
||||||
|
if (!desktop_id.empty() && (desktop_id != libcc_default_id)) {
|
||||||
|
*setme = desktop_id;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace platform_util
|
||||||
|
|
||||||
|
} // namespace brightray
|
|
@ -124,6 +124,8 @@
|
||||||
'common/main_delegate_mac.mm',
|
'common/main_delegate_mac.mm',
|
||||||
'common/switches.cc',
|
'common/switches.cc',
|
||||||
'common/switches.h',
|
'common/switches.h',
|
||||||
|
'common/platform_util_linux.cc',
|
||||||
|
'common/platform_util.h',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue