Browse Source

Fix dbus media implementation. Now grabs media keys on window focus (#3587)

pull/3597/head
Jesse Ostrander 5 months ago
parent
commit
908be223d7
No account linked to committer's email address
3 changed files with 56 additions and 37 deletions
  1. 2
    2
      package.json
  2. 23
    16
      src/main/features/linux/mediaKeysDBus.js
  3. 31
    19
      yarn.lock

+ 2
- 2
package.json View File

@@ -160,13 +160,13 @@
"@nodert-win10/windows.media.playback": "^0.2.95",
"@nodert-win10/windows.storage.streams": "^0.2.95",
"appdmg": "^0.4.5",
"dbus-next": "^0.6.1",
"dbus-next": "^0.7.1",
"electron-installer-debian": "^0.4.0",
"electron-installer-redhat": "^0.3.0",
"electron-media-service": "^0.2.2",
"ll-keyboard-hook-win": "^3.0.0",
"mouse-forward-back": "^1.0.1",
"mpris-service": "^2.0.0"
"mpris-service": "^2.1.0"
},
"babel": {
"presets": [

+ 23
- 16
src/main/features/linux/mediaKeysDBus.js View File

@@ -1,23 +1,30 @@
import dbus from 'dbus-next';
import { app } from 'electron';

function registerBindings(desktopEnv, session) {
const listener = (err, iface) => {
if (!err) {
iface.on('MediaPlayerKeyPressed', (n, keyName) => {
switch (keyName) {
case 'Next': Emitter.sendToGooglePlayMusic('playback:nextTrack'); return;
case 'Previous': Emitter.sendToGooglePlayMusic('playback:previousTrack'); return;
case 'Play': Emitter.sendToGooglePlayMusic('playback:playPause'); return;
case 'Stop': Emitter.sendToGooglePlayMusic('playback:stop'); return;
default: return;
}
});
iface.GrabMediaPlayerKeys('GPMDP', 0); // eslint-disable-line
async function registerBindings(desktopEnv, session) {
const listener = (n, keyName) => {
switch (keyName) {
case 'Next': Emitter.sendToGooglePlayMusic('playback:nextTrack'); return;
case 'Previous': Emitter.sendToGooglePlayMusic('playback:previousTrack'); return;
case 'Play': Emitter.sendToGooglePlayMusic('playback:playPause'); return;
case 'Stop': Emitter.sendToGooglePlayMusic('playback:stop'); return;
default: return;
}
};

session.getInterface(`org.${desktopEnv}.SettingsDaemon`, `/org/${desktopEnv}/SettingsDaemon/MediaKeys`, `org.${desktopEnv}.SettingsDaemon.MediaKeys`, listener);
session.getInterface(`org.${desktopEnv}.SettingsDaemon.MediaKeys`, `/org/${desktopEnv}/SettingsDaemon/MediaKeys`, `org.${desktopEnv}.SettingsDaemon.MediaKeys`, listener);
const legacy = await session.getProxyObject(`org.${desktopEnv}.SettingsDaemon`, `/org/${desktopEnv}/SettingsDaemon/MediaKeys`);
legacy.getInterface(`org.${desktopEnv}.SettingsDaemon.MediaKeys`);
legacy.on('MediaPlayerKeyPressed', listener);
app.on('browser-window-focus', () => {
legacy.GrabMediaPlayerKeys('GPMDP', 0); // eslint-disable-line
});

const future = await session.getProxyObject(`org.${desktopEnv}.SettingsDaemon.MediaKeys`, `/org/${desktopEnv}/SettingsDaemon/MediaKeys`);
future.getInterface(`org.${desktopEnv}.SettingsDaemon.MediaKeys`);
future.on('MediaPlayerKeyPressed', listener);
app.on('browser-window-focus', () => {
future.GrabMediaPlayerKeys('GPMDP', 0); // eslint-disable-line
});
}

try {
@@ -25,5 +32,5 @@ try {
registerBindings('gnome', session);
registerBindings('mate', session);
} catch (e) {
// do nothing.
// Do nothing
}

+ 31
- 19
yarn.lock View File

@@ -30,6 +30,11 @@
dependencies:
nan latest

"@nornagon/put@0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@nornagon/put/-/put-0.0.8.tgz#9d497ec46c9364acc3f8b59aa3cf8ee4134ae337"
integrity sha512-ugvXJjwF5ldtUpa7D95kruNJ41yFQDEKyF5CW4TgKJnh+W/zmlBzXXeKTyqIgwMFrkePN2JqOBqcF0M0oOunow==

"@slack/client@^4.8.0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@slack/client/-/client-4.8.0.tgz#265606f1cebae1d72f3fdd2cdf7cf1510783dde4"
@@ -1990,30 +1995,31 @@ dateformat@^2.0.0:
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.2.0.tgz#4065e2013cf9fb916ddfd82efb506ad4c6769062"
integrity sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=

dbus-next@0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/dbus-next/-/dbus-next-0.3.1.tgz#748d54e0eabc7bce4852496f67e27d73b48e8917"
integrity sha512-tTmAZmXrGtJpEaZ3EZUoxPSAZAaofZYhyVcxk2o9/g+KQOYNlEC8lMvLFFAgBn/kXOveLViZWEB0OUP2hR69Yg==
dbus-next@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/dbus-next/-/dbus-next-0.5.1.tgz#94bb1a30d744bc75045be40e40b59e7a195fd882"
integrity sha512-PzsudTX5HMLocSuwHefIohto8L4Gnh5ST2+VNAoax9Xurh+lTosmXIfgi/Mrc93vqUU3D1v7jE9/vjiWd3KIbA==
dependencies:
event-stream "3.3.4"
hexy "^0.2.10"
jsbi "^2.0.5"
long "^4.0.0"
put "0.0.6"
safe-buffer "^5.1.1"
xml2js "^0.4.17"
optionalDependencies:
abstract-socket "^2.0.0"

dbus-next@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/dbus-next/-/dbus-next-0.6.1.tgz#841bff291a38db0233d19dfde43a9bf18d291f38"
integrity sha512-4huuqmErCAtp7x77KmBXg1jD/0Xj+zU3r53MVpfkO17QICwbvaZCrEAOjqo5tMP4tybOlEpsgiutYyQdjuheYw==
dbus-next@^0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/dbus-next/-/dbus-next-0.7.1.tgz#9d89d0415c8691177a456efe0ea98196fb1e7f7e"
integrity sha512-3za7fLvf2b3hje+2mnG28EQwUhLMcvsEQ94EXYEFkbKJVpuo5uVQH7bp2NG4Zi5kJWmOceF/z1PZYbHa8Cgx/Q==
dependencies:
"@nornagon/put" "0.0.8"
event-stream "3.3.4"
hexy "^0.2.10"
jsbi "^2.0.5"
long "^4.0.0"
put "0.0.6"
safe-buffer "^5.1.1"
xml2js "^0.4.17"
optionalDependencies:
@@ -2078,6 +2084,11 @@ deep-eql@^0.1.3:
dependencies:
type-detect "0.1.1"

deep-equal@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
integrity sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=

deep-extend@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
@@ -5868,13 +5879,14 @@ mouse-forward-back@^1.0.1:
bindings "^1.2.1"
nan "*"

mpris-service@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/mpris-service/-/mpris-service-2.0.0.tgz#98d34e1c4a6b9c5ec5b45309e1c59e13bbfabe45"
integrity sha512-qlAOD1GJ0BJvfijNcpdJODPy4Iu1aKh0dt9mnfZpAp8KnfHDIjcUv4/TAYF0m9gucsgVMeK5OeMnaY+miuy+6Q==
mpris-service@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mpris-service/-/mpris-service-2.1.0.tgz#0bbfb5b47a9b3e01ce8b9a41a8aef0ad3210c909"
integrity sha512-HWFimtWYrfm7iMz8VjTrY68c2vwBMb5kDXqAQ9GmgIMv5exfgz+w277F1XFBc72Nu6FM3QH6jqMGT89m2MMDBg==
dependencies:
dbus-next "0.3.1"
source-map-support "^0.5.9"
dbus-next "^0.5.1"
deep-equal "^1.0.1"
source-map-support "^0.5.11"

ms@2.0.0:
version "2.0.0"
@@ -7757,10 +7769,10 @@ source-map-support@^0.4.15:
dependencies:
source-map "^0.5.6"

source-map-support@^0.5.9:
version "0.5.11"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.11.tgz#efac2ce0800355d026326a0ca23e162aeac9a4e2"
integrity sha512-//sajEx/fGL3iw6fltKMdPvy8kL3kJ2O3iuYlRoT3k9Kb4BjOoZ+BZzaNHeuaruSt+Kf3Zk9tnfAQg9/AJqUVQ==
source-map-support@^0.5.11:
version "0.5.12"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.12.tgz#b4f3b10d51857a5af0138d3ce8003b201613d599"
integrity sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

Loading…
Cancel
Save