# class DBus::ASessionBus

# D-Bus session bus class¶ ↑

The session bus is a session specific bus (mostly for desktop use).

Use SessionBus, the non-singleton ASessionBus is for the test suite.

### Public Class Methods

new() click to toggle source

Get the the default session bus.

Calls superclass method DBus::Connection.new

    # File lib/dbus/bus.rb, line 599
    def initialize
      super(ENV["DBUS_SESSION_BUS_ADDRESS"] || address_from_file || "launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET")
      send_hello
    end

### Public Instance Methods

address_from_file() click to toggle source

    # File lib/dbus/bus.rb, line 604
    def address_from_file
      # systemd uses /etc/machine-id
      # traditional dbus uses /var/lib/dbus/machine-id
      machine_id_path = Dir['{/etc,/var/lib/dbus}/machine-id'].first
      return nil unless machine_id_path
      machine_id = File.read(machine_id_path).chomp

      display = ENV["DISPLAY"][/:(\d+)\.?/, 1]

      bus_file_path = File.join(ENV["HOME"], "/.dbus/session-bus/#{machine_id}-#{display}")
      return nil unless File.exists?(bus_file_path)

      File.open(bus_file_path).each_line do |line|
        if line =~ /^DBUS_SESSION_BUS_ADDRESS=(.*)/
          return $1
        end
      end
    end