skype_lock_logout 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -5,14 +5,22 @@ class Skype_lock_logout
5
5
  #Spawns the object, starts to listen and blocks the thread.
6
6
  def self.start
7
7
  loop do
8
+ print "Starting Skype-lock-logout.\n"
9
+
8
10
  begin
9
11
  Skype_lock_logout.new.listen
10
12
  rescue => e
11
- puts e.inspect
12
- puts e.backtrace
13
+ if e.is_a?(DBus::Error) and e.message == "The name com.Skype.API was not provided by any .service files"
14
+ puts "Skype isnt running - trying again in 10 secs."
15
+ elsif e.is_a?(RuntimeError) and e.message == "Skype has stopped running."
16
+ puts "Skype stopped running - trying to reconnect in 10 secs."
17
+ else
18
+ puts e.inspect
19
+ puts e.backtrace
20
+ end
13
21
  end
14
22
 
15
- sleep 1
23
+ sleep 10
16
24
  end
17
25
  end
18
26
 
@@ -21,8 +29,8 @@ class Skype_lock_logout
21
29
  @bus = DBus::SessionBus.instance
22
30
 
23
31
  #Spawn Skype-DBus objects.
24
- @skype_service = @bus.service("com.Skype.API")
25
- @skype_obj = @skype_service.object("/com/Skype")
32
+ skype_service = @bus.service("com.Skype.API")
33
+ @skype_obj = skype_service.object("/com/Skype")
26
34
  @skype_obj.introspect
27
35
  @skype_obj.default_iface = "com.Skype.API"
28
36
 
@@ -30,13 +38,22 @@ class Skype_lock_logout
30
38
  res = @skype_obj.Invoke("NAME SkypeLockLogout").first
31
39
  raise "The application wasnt allowed use Skype: '#{res}'." if res != "OK"
32
40
 
33
- #Set the protocol to 8 - could only find documentation on this protocol.
41
+ #Set the protocol to 8 - could only find documentation on this protocol. Are there any better ones???
34
42
  res = @skype_obj.Invoke("PROTOCOL 8").first
35
43
  raise "Couldnt set the protocol for Skype: '#{res}'." if res != "PROTOCOL 8"
36
44
 
37
45
  #Listen for lock-events on the screensaver.
38
46
  mr = DBus::MatchRule.new.from_s("interface='org.gnome.ScreenSaver',member='ActiveChanged'")
39
47
  @bus.add_match(mr, &self.method(:gnome_screensaver_status))
48
+
49
+ #Listen for when Skype stops running to quit listening.
50
+ mr = DBus::MatchRule.new.from_s("path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged'")
51
+ @bus.add_match(mr, &self.method(:name_owner_changed))
52
+ end
53
+
54
+ #This method is being called on 'NameOwnerChanged', which helps us stop the app when Skype stops (a reconnect is needed after Skype restarts).
55
+ def name_owner_changed(msg)
56
+ raise "Skype has stopped running." if msg.params.first == "com.Skype.API" and msg.params[1].to_s.match(/^:\d\.\d+$/)
40
57
  end
41
58
 
42
59
  #This method is called, when the Gnome-Screensaver locks or unlocks.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{skype_lock_logout}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: skype_lock_logout
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- hash: -2047674363038107880
118
+ hash: 3428513175358633684
119
119
  segments:
120
120
  - 0
121
121
  version: "0"