<commit_before>const DBus = require('dbus-next');
const debug = require('debug');
const { ipcMain } = require('electron');

const logger = debug('headset:mediaKeys');

let track = null;

ipcMain.on('win2Player', (e, args) => {
  if (args[0] === 'trackInfo') {
    track = args[1];
  }
});

function executeMediaKey(win, key) {
  logger('Executing %o media key command', key);
  win.webContents.executeJavaScript(`
    window.electronConnector.emit('${key}')
  `);
}

async function registerBindings(win, desktopEnv, bus) {
  let serviceName = `org.${desktopEnv}.SettingsDaemon`;
  let objectPath = `/org/${desktopEnv}/SettingsDaemon/MediaKeys`;
  let interfaceName = `org.${desktopEnv}.SettingsDaemon.MediaKeys`;

  if (desktopEnv === 'gnome3') {
    serviceName = 'org.gnome.SettingsDaemon.MediaKeys';
    objectPath = '/org/gnome/SettingsDaemon/MediaKeys';
    interfaceName = 'org.gnome.SettingsDaemon.MediaKeys';
  }

  try {
    const settings = await bus.getProxyObject(serviceName, objectPath);
    const mediaKeys = settings.getInterface(interfaceName);

    mediaKeys.on('MediaPlayerKeyPressed', (iface, n, keyName) => {
      logger('Media key pressed: %o', keyName);
      switch (keyName) {<commit_msg>Fix MediaKeys with new mpris API MediaKeys code only works for Mate and older version of gnome All OSs using gnome3 use MPRIS to send mediakey shortcuts<commit_after>const DBus = require('dbus-next');
const debug = require('debug');
const { ipcMain } = require('electron');

const logger = debug('headset:mediaKeys');

let track = null;

ipcMain.on('win2Player', (e, args) => {
  if (args[0] === 'trackInfo') {
    track = args[1];
  }
});

function executeMediaKey(win, key) {
  logger('Executing %o media key command', key);
  win.webContents.executeJavaScript(`
    window.electronConnector.emit('${key}')
  `);
}

async function registerBindings(win, desktopEnv, bus) {
  let serviceName = `org.${desktopEnv}.SettingsDaemon`;
  let objectPath = `/org/${desktopEnv}/SettingsDaemon/MediaKeys`;
  let interfaceName = `org.${desktopEnv}.SettingsDaemon.MediaKeys`;

  if (desktopEnv === 'gnome3') {
    serviceName = 'org.gnome.SettingsDaemon.MediaKeys';
    objectPath = '/org/gnome/SettingsDaemon/MediaKeys';
    interfaceName = 'org.gnome.SettingsDaemon.MediaKeys';
  }

  try {
    const settings = await bus.getProxyObject(serviceName, objectPath);
    const mediaKeys = settings.getInterface(interfaceName);

    mediaKeys.on('MediaPlayerKeyPressed', (iface, keyName) => {
      logger('Media key pressed: %o', keyName);
      switch (keyName) {
{'fraction_non_alphanumeric': 0.1485959438377535, 'fraction_numerical': 0.0035101404056162248, 'mean_word_length': 4.725446428571429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692795', 'n_tokens_mistral': 835, 'n_tokens_neox': 806, 'n_words': 179}