xscreen_usb_unlocker 0.90.1 → 0.90.2
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/bin/xscreen_usb_unlocker
CHANGED
|
@@ -5,7 +5,7 @@ Options.banner = "Usage: Used to lock/unlock xscreensaver based on usb device id
|
|
|
5
5
|
Options.on("-s", "--serial SERIAL", "make sure the device matches this serial.") { |s| Options[:serial] = s}
|
|
6
6
|
Options.on("-d", "--device DEVICE", "make sure it is this specific device.") { |d| Options[:device] = d}
|
|
7
7
|
Options.on("-D", "--daemonize", "Daemonize this process in the background.") { |d| Options[:daemonize] = true}
|
|
8
|
-
Options.on("--save-config", "Save the device and serial to a
|
|
8
|
+
Options.on("--save-config", "Save the device and serial to a XscreenUsbUnlocker::Config file and exit.") { |d| Options[:save_config] = true}
|
|
9
9
|
Options.parse!
|
|
10
10
|
|
|
11
11
|
if !Options[:device] && !Options[:serial]
|
|
@@ -64,43 +64,41 @@ def toggle_lock
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Options.on_pry
|
|
70
|
-
|
|
71
|
-
# should we save our config and bail?
|
|
72
|
-
if Options[:save_config]
|
|
73
|
-
Config["serial"] = Options[:serial] if Options[:serial]
|
|
74
|
-
Config["device"] = Options[:device] if Options[:device]
|
|
75
|
-
Config.save!
|
|
76
|
-
puts "Saved configuration to #{Config.file}"
|
|
77
|
-
exit
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# kill a running copy of xscreensaver
|
|
81
|
-
if xscreensaver_running?
|
|
82
|
-
Log.info "xscreensaver appears to be running, killing so we can trap it."
|
|
83
|
-
%x[killall -QUIT xscreensaver]
|
|
84
|
-
end
|
|
67
|
+
# did we pry?
|
|
68
|
+
Options.on_pry
|
|
85
69
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
# should we save our config and bail?
|
|
71
|
+
if Options[:save_config]
|
|
72
|
+
XscreenUsbUnlocker::Config["serial"] = Options[:serial] if Options[:serial]
|
|
73
|
+
XscreenUsbUnlocker::Config["device"] = Options[:device] if Options[:device]
|
|
74
|
+
XscreenUsbUnlocker::Config.save!
|
|
75
|
+
puts "Saved configuration to #{Config.file}"
|
|
76
|
+
exit
|
|
77
|
+
end
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
# kill a running copy of xscreensaver
|
|
80
|
+
if xscreensaver_running?
|
|
81
|
+
Log.info "xscreensaver appears to be running, killing so we can trap it."
|
|
82
|
+
%x[killall -QUIT xscreensaver]
|
|
83
|
+
end
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
App.daemonize(:mulitple_pids => false) { Notifier.run }
|
|
103
|
-
else
|
|
104
|
-
Notifier.run
|
|
85
|
+
# grab our notifications
|
|
86
|
+
Notifier = INotify::Notifier.new
|
|
87
|
+
Dir.glob("/dev/bus/usb/*").each do |d|
|
|
88
|
+
Notifier.watch(d, :delete, :create) do
|
|
89
|
+
toggle_lock
|
|
105
90
|
end
|
|
106
91
|
end
|
|
92
|
+
|
|
93
|
+
# fire off the lock cycle once.
|
|
94
|
+
toggle_lock
|
|
95
|
+
|
|
96
|
+
# start the notifier, which will fire off callbacks as needed.
|
|
97
|
+
if Options[:daemonize] || File.file?(XscreenUsbUnlocker::Config.file)
|
|
98
|
+
Log.debug "Opening logfile."
|
|
99
|
+
Log.filename "/home/ebrodeur/.logs/xscreensaver_unlocker.log"
|
|
100
|
+
Log.debug "Daemonizing."
|
|
101
|
+
App.daemonize(:mulitple_pids => false) { Notifier.run }
|
|
102
|
+
else
|
|
103
|
+
Notifier.run
|
|
104
|
+
end
|