Bug 1676045 - Implement DesktopEntry for MPRIS r=stransky

The DesktopEntry property allows MPRIS clients to match a player on the bus
with application metadata such as its icon.

The desktop entry name is computed as the lowercasing of the XRE app info name.
This is the same way it's done for g_set_prgname in nsAppRunner.

Differential Revision: https://phabricator.services.mozilla.com/D96327
This commit is contained in:
Greg V 2020-11-12 13:38:52 +00:00
Родитель bc8d4ed13b
Коммит 3e316137c4
3 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -21,6 +21,7 @@ extern const gchar introspection_xml[] =
"<property name=\"CanRaise\" type=\"b\" access=\"read\"/>"
"<property name=\"HasTrackList\" type=\"b\" access=\"read\"/>"
"<property name=\"Identity\" type=\"s\" access=\"read\"/>"
"<property name=\"DesktopEntry\" type=\"s\" access=\"read\"/>"
"<property name=\"SupportedUriSchemes\" type=\"as\" access=\"read\"/>"
"<property name=\"SupportedMimeTypes\" type=\"as\" access=\"read\"/>"
"</interface>"

Просмотреть файл

@ -78,6 +78,7 @@ static void HandleMethodCall(GDBusConnection* aConnection, const gchar* aSender,
enum class Property : uint8_t {
eIdentity,
eDesktopEntry,
eHasTrackList,
eCanRaise,
eCanQuit,
@ -115,6 +116,7 @@ static inline Maybe<Property> GetProperty(const gchar* aPropertyName) {
const std::unordered_map<std::string, Property> map = {
// org.mpris.MediaPlayer2 properties
{"Identity", Property::eIdentity},
{"DesktopEntry", Property::eDesktopEntry},
{"HasTrackList", Property::eHasTrackList},
{"CanRaise", Property::eCanRaise},
{"CanQuit", Property::eCanQuit},
@ -163,6 +165,8 @@ static GVariant* HandleGetProperty(GDBusConnection* aConnection,
return handler->GetMetadataAsGVariant();
case Property::eIdentity:
return g_variant_new_string(handler->Identity());
case Property::eDesktopEntry:
return g_variant_new_string(handler->DesktopEntry());
case Property::eHasTrackList:
case Property::eCanQuit:
case Property::eCanSeek:
@ -355,18 +359,20 @@ bool MPRISServiceHandler::IsOpened() const { return mInitialized; }
void MPRISServiceHandler::InitIdentity() {
nsresult rv;
nsAutoCString appName;
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1", &rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = appInfo->GetVendor(mIdentity);
MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = appInfo->GetName(appName);
rv = appInfo->GetName(mDesktopEntry);
MOZ_ASSERT(NS_SUCCEEDED(rv));
mIdentity.Append(' ');
mIdentity.Append(appName);
mIdentity.Append(mDesktopEntry);
// Compute the desktop entry name like nsAppRunner does for g_set_prgname
ToLowerCase(mDesktopEntry);
}
const char* MPRISServiceHandler::Identity() const {
@ -374,6 +380,11 @@ const char* MPRISServiceHandler::Identity() const {
return mIdentity.get();
}
const char* MPRISServiceHandler::DesktopEntry() const {
MOZ_ASSERT(mInitialized);
return mDesktopEntry.get();
}
bool MPRISServiceHandler::PressKey(mozilla::dom::MediaControlKey aKey) const {
MOZ_ASSERT(mInitialized);
if (!IsMediaKeySupported(aKey)) {

Просмотреть файл

@ -75,6 +75,7 @@ class MPRISServiceHandler final : public dom::MediaControlKeySource {
GVariant* GetPlaybackStatus() const;
const char* Identity() const;
const char* DesktopEntry() const;
bool PressKey(dom::MediaControlKey aKey) const;
void SetMediaMetadata(const dom::MediaMetadataBase& aMetadata) override;
@ -100,6 +101,7 @@ class MPRISServiceHandler final : public dom::MediaControlKeySource {
GDBusConnection* mConnection = nullptr;
bool mInitialized = false;
nsAutoCString mIdentity;
nsAutoCString mDesktopEntry;
nsCString mMimeType;