From 6def248483f074946563325a963f636bc27337c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 8 Jul 2022 23:41:20 +0300 Subject: [PATCH 1/2] refactor: extract XDG app ID logic into a method --- .../notifications/linux/libnotify_notification.cc | 10 ++-------- shell/common/platform_util.h | 4 ++++ shell/common/platform_util_linux.cc | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/shell/browser/notifications/linux/libnotify_notification.cc b/shell/browser/notifications/linux/libnotify_notification.cc index 07d7135788de1..3f7a2fa24f887 100644 --- a/shell/browser/notifications/linux/libnotify_notification.cc +++ b/shell/browser/notifications/linux/libnotify_notification.cc @@ -9,7 +9,6 @@ #include "base/files/file_enumerator.h" #include "base/logging.h" -#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "shell/browser/notifications/notification_delegate.h" #include "shell/browser/ui/gtk_util.h" @@ -138,13 +137,8 @@ void LibnotifyNotification::Show(const NotificationOptions& options) { // Send the desktop name to identify the application // The desktop-entry is the part before the .desktop - std::string desktop_id; - if (platform_util::GetDesktopName(&desktop_id)) { - const std::string suffix{".desktop"}; - if (base::EndsWith(desktop_id, suffix, - base::CompareCase::INSENSITIVE_ASCII)) { - desktop_id.resize(desktop_id.size() - suffix.size()); - } + std::string desktop_id = platform_util::GetXdgAppId(); + if (!desktop_id.empty()) { libnotify_loader_.notify_notification_set_hint_string( notification_, "desktop-entry", desktop_id.c_str()); } diff --git a/shell/common/platform_util.h b/shell/common/platform_util.h index ba8f9652dba29..085c7e3a7d926 100644 --- a/shell/common/platform_util.h +++ b/shell/common/platform_util.h @@ -56,6 +56,10 @@ bool SetLoginItemEnabled(bool enabled); // Returns a success flag. // Unlike libgtkui, does *not* use "chromium-browser.desktop" as a fallback. bool GetDesktopName(std::string* setme); + +// The XDG application ID must match the name of the desktop entry file without +// the .desktop extension. +std::string GetXdgAppId(); #endif } // namespace platform_util diff --git a/shell/common/platform_util_linux.cc b/shell/common/platform_util_linux.cc index ef8d8f8f0de01..2018c6d8864bf 100644 --- a/shell/common/platform_util_linux.cc +++ b/shell/common/platform_util_linux.cc @@ -20,6 +20,7 @@ #include "base/posix/eintr_wrapper.h" #include "base/process/kill.h" #include "base/process/launch.h" +#include "base/strings/string_util.h" #include "base/threading/thread_restrictions.h" #include "components/dbus/thread_linux/dbus_thread_linux.h" #include "content/public/browser/browser_thread.h" @@ -403,4 +404,18 @@ bool GetDesktopName(std::string* setme) { return base::Environment::Create()->GetVar("CHROME_DESKTOP", setme); } +std::string GetXdgAppId() { + std::string desktop_file_name; + if (GetDesktopName(&desktop_file_name)) { + const std::string kDesktopExtension{".desktop"}; + if (base::EndsWith(desktop_file_name, kDesktopExtension, + base::CompareCase::INSENSITIVE_ASCII)) { + desktop_file_name.resize(desktop_file_name.size() - + kDesktopExtension.size()); + } + } + + return desktop_file_name; +} + } // namespace platform_util From ce2463c4d58460f336ccfafbba5acf1a61832a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 8 Jul 2022 23:55:02 +0300 Subject: [PATCH 2/2] fix: set application ID on Wayland --- shell/browser/native_window_views.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 50ff87885c583..674a4bf26eb5e 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -51,6 +51,7 @@ #include "shell/browser/ui/views/client_frame_view_linux.h" #include "shell/browser/ui/views/frameless_view.h" #include "shell/browser/ui/views/native_frame_view.h" +#include "shell/common/platform_util.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/window/native_frame_view.h" @@ -271,6 +272,8 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, // Set WM_CLASS. params.wm_class_name = base::ToLowerASCII(name); params.wm_class_class = name; + // Set Wayland application ID. + params.wayland_app_id = platform_util::GetXdgAppId(); auto* native_widget = new views::DesktopNativeWidgetAura(widget()); params.native_widget = native_widget;