How to use dbus-next - 10 common examples

To help you get started, we’ve selected a few dbus-next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbusjs / mpris-service / src / interfaces / mpris-interface.js View on Github external
const dbus = require('dbus-next');
const Variant = dbus.Variant;
const types = require('./types');
const deepEqual = require('deep-equal');
const constants = require('../constants');
const logging = require('../logging');

let {
  Interface, property, method, signal, DBusError,
  ACCESS_READ, ACCESS_WRITE, ACCESS_READWRITE
} = dbus.interface;

class MprisInterface extends Interface {
  constructor(name, player) {
    super(name);
    this.player = player;
  }

  _setPropertyInternal(property, valueDbus) {
    // nothing is currently settable internally that needs conversion to plain
    this.player.emit(property[0].toLowerCase() + property.substr(1), valueDbus);
  }

  setProperty(property, valuePlain) {
    // convert the plain value to a dbus value (default to the plain value)
    let valueDbus = valuePlain;
github headsetapp / headset-electron / src / lib / mediaKeys / linux.js View on Github external
module.exports = (win) => {
  logger.media('Registering media Keys');
  try {
    const bus = DBus.sessionBus();

    registerBindings(win, 'gnome', bus);
    registerBindings(win, 'gnome3', bus);
    registerBindings(win, 'mate', bus);
  } catch (error) {
    console.error(error);
  }

  // Register shortcut key to open Developer Tools
  globalShortcut.register('CommandOrControl+Shift+I', () => {
    logger.info('Opening Developer Tools');
    win.webContents.openDevTools();
  });
};
github dbusjs / mpris-service / src / interfaces / playlists.js View on Github external
// TODO proper import
let MprisInterface = require('./mpris-interface');
let dbus = require('dbus-next');
let Variant = dbus.Variant;
let types = require('./types');

let {
  property, method, signal, DBusError,
  ACCESS_READ, ACCESS_WRITE, ACCESS_READWRITE
} = dbus.interface;

class PlaylistsInterface extends MprisInterface {
  constructor(player) {
    super('org.mpris.MediaPlayer2.Playlists', player);
  }

  _ActivePlaylist = [ false, types.emptyPlaylist ];
  _PlaylistCount = 0;

  @property({signature: 'u', access: ACCESS_READ})
  get PlaylistCount() {
    return this._PlaylistCount;
  }

  @property({signature: 'as', access: ACCESS_READ})
  get Orderings() {
github Superjo149 / auryo / src / main / features / linux / dbusService.ts View on Github external
async register() {
    try {
      dbus.setBigIntCompat(true);

      const session = dbus.sessionBus();

      try {
        await this.registerBindings('gnome', session);
      } catch (err) {
        // ignore
      }

      try {
        await this.registerBindings('mate', session);
      } catch (err) {
        // ignore
      }
    } catch (e) {
      this.logger.error(e);
    }
github MarshallOfSound / Google-Play-Music-Desktop-Player-UNOFFICIAL- / src / main / features / linux / mediaKeysDBus.js View on Github external
const interfaceLegacy = legacy.getInterface(`org.${desktopEnv}.SettingsDaemon.MediaKeys`);
  interfaceLegacy.on('MediaPlayerKeyPressed', listener);
  app.on('browser-window-focus', () => {
    interfaceLegacy.GrabMediaPlayerKeys('GPMDP', 0); // eslint-disable-line
  });

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

try {
  const session = dbus.sessionBus();
  registerBindings('gnome', session);
  registerBindings('mate', session);
} catch (e) {
  // Do nothing
}
github Superjo149 / auryo / src / main / features / linux / dbusService.ts View on Github external
async register() {
    try {
      dbus.setBigIntCompat(true);

      const session = dbus.sessionBus();

      try {
        await this.registerBindings('gnome', session);
      } catch (err) {
        // ignore
      }

      try {
        await this.registerBindings('mate', session);
      } catch (err) {
        // ignore
      }
    } catch (e) {
      this.logger.error(e);
github dbusjs / mpris-service / src / index.js View on Github external
Player.prototype.init = function(opts) {
  this.serviceName = `org.mpris.MediaPlayer2.${this.name}`;
  dbus.validators.assertBusNameValid(this.serviceName);

  this._bus = dbus.sessionBus();

  this._bus.on('error', (err) => {
    this.emit('error', err);
  });

  this.interfaces = {};

  this._addRootInterface(this._bus, opts);

  if (this.supportedInterfaces.indexOf('player') >= 0) {
    this._addPlayerInterface(this._bus);
  }
  if (this.supportedInterfaces.indexOf('trackList') >= 0) {
    this._addTracklistInterface(this._bus);
  }
  if (this.supportedInterfaces.indexOf('playlists') >= 0) {
github dbusjs / mpris-service / src / index.js View on Github external
if (this.supportedInterfaces.indexOf('player') >= 0) {
    this._addPlayerInterface(this._bus);
  }
  if (this.supportedInterfaces.indexOf('trackList') >= 0) {
    this._addTracklistInterface(this._bus);
  }
  if (this.supportedInterfaces.indexOf('playlists') >= 0) {
    this._addPlaylistsInterface(this._bus);
  }

  for (let k of Object.keys(this.interfaces)) {
    let iface = this.interfaces[k];
    this._bus.export(MPRIS_PATH, iface);
  }

  this._bus.requestName(this.serviceName, dbus.NameFlag.DO_NOT_QUEUE)
    .then((reply) => {
      if (reply === dbus.RequestNameReply.EXISTS) {
        this.serviceName = `${this.serviceName}.instance${process.pid}`;
        return this._bus.requestName(this.serviceName);
      }
    })
    .catch((err) => {
      this.emit('error', err);
    });
};
github dbusjs / mpris-service / src / index.js View on Github external
Player.prototype.init = function(opts) {
  this.serviceName = `org.mpris.MediaPlayer2.${this.name}`;
  dbus.validators.assertBusNameValid(this.serviceName);

  this._bus = dbus.sessionBus();

  this._bus.on('error', (err) => {
    this.emit('error', err);
  });

  this.interfaces = {};

  this._addRootInterface(this._bus, opts);

  if (this.supportedInterfaces.indexOf('player') >= 0) {
    this._addPlayerInterface(this._bus);
  }
  if (this.supportedInterfaces.indexOf('trackList') >= 0) {
    this._addTracklistInterface(this._bus);
github dbusjs / mpris-service / src / interfaces / tracklist.js View on Github external
let MprisInterface = require('./mpris-interface');
let dbus = require('dbus-next');
let Variant = dbus.Variant;
let types = require('./types');

let {
  property, method, signal, DBusError,
  ACCESS_READ, ACCESS_WRITE, ACCESS_READWRITE
} = dbus.interface;

class TracklistInterface extends MprisInterface {
  constructor(player) {
    super('org.mpris.MediaPlayer2.TrackList', player);
  }

  _Tracks = [];
  _CanEditTracks = false;

  setTracks(tracksPlain) {
    this.setProperty('Tracks', tracksPlain);
  }

  @property({signature: 'ao', access: ACCESS_READ})
  get Tracks() {
    return this._Tracks;