Class: Snapsync::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/snapsync/Notification.rb

Overview

This class abstracts notifying each user on the system NOTE: Not multi-thread safe!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Notification

Returns a new instance of Notification.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/snapsync/Notification.rb', line 10

def initialize(config)
  @notified_users = {}


  Dir.each_child('/run/user') do |user_id|
    # seteuid _must_ be set for session dbus to accept the connection
    Process::Sys.seteuid(user_id.to_i)
    ENV['DBUS_SESSION_BUS_ADDRESS'] = "unix:path=/run/user/#{user_id}/bus"

    n = Libnotify.new(config)
    @notified_users[user_id.to_i] = n
    n.show!
  end
  # set euid back, so all commands works normally
  Process::Sys.seteuid Process::Sys.getuid
end

Instance Attribute Details

#notified_usersHash{Integer => Libnotify::API} (readonly)

Returns:

  • (Hash{Integer => Libnotify::API})


8
9
10
# File 'lib/snapsync/Notification.rb', line 8

def notified_users
  @notified_users
end

Instance Method Details

#closeObject



33
34
35
36
37
# File 'lib/snapsync/Notification.rb', line 33

def close
  each_raw_notification do |n|
    n.close
  end
end

#update(config) ⇒ Object



27
28
29
30
31
# File 'lib/snapsync/Notification.rb', line 27

def update(config)
  each_raw_notification do |n|
    n.update(config)
  end
end