fidget 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/bin/fidget +8 -1
- data/lib/fidget.rb +33 -3
- data/lib/fidget/logger.rb +28 -0
- data/lib/fidget/platform/darwin.rb +10 -1
- data/lib/fidget/platform/linux.rb +22 -2
- data/lib/fidget/platform/null.rb +24 -0
- data/lib/fidget/platform/windows.rb +8 -15
- data/lib/fidget/version.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad59e6d764cbf2bc8910fe3905b909f7efb25c1d
|
4
|
+
data.tar.gz: 675e1df0a3eb686dd15ee958ecd5e82de9c02043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec59b3d504006e39b0e881db51b7be974d4897bcb8de11dadc433658773c5d10e5f9cd0b25c80fbdb881586dc55c5ea1f83235211756447a89c02c0c0acac93d
|
7
|
+
data.tar.gz: e1a8fb990e49593ce2f141a183e7715b570db26b854d601385a28ba89553c4fc0c2f55cbb0b9abd65271ffd2a0997204d453da8fec2f0cdaebfa82254db8f259
|
data/README.md
CHANGED
@@ -30,6 +30,8 @@ Additional OS X options:
|
|
30
30
|
|
31
31
|
* `idle` will prevent the system from idle sleeping.
|
32
32
|
* `disk` will prevent the disk from sleeping.
|
33
|
+
* 'user' will assert that the user is active. This keeps the display
|
34
|
+
on and prevents idle sleep.
|
33
35
|
|
34
36
|
Additional Windows options:
|
35
37
|
|
@@ -40,6 +42,11 @@ Additional Linux options:
|
|
40
42
|
|
41
43
|
* `blanking` disables terminal blanking on Linux.
|
42
44
|
|
45
|
+
Default options for each platform:
|
46
|
+
* OS X: `user`
|
47
|
+
* Linux: `display`
|
48
|
+
* Windows: `display`,`sleep`
|
49
|
+
|
43
50
|
If you pass a command, then Fidget will execute that command and prevent the
|
44
51
|
system from sleeping until that command terminates. If you do not provide a
|
45
52
|
command, then Fidget will prevent sleeping until you press Ctrl-C to terminate.
|
@@ -83,7 +90,7 @@ Default options, with a block:
|
|
83
90
|
|
84
91
|
#! /usr/bin/env ruby
|
85
92
|
require 'fidget'
|
86
|
-
|
93
|
+
|
87
94
|
Fidget.prevent_sleep do
|
88
95
|
100.times do
|
89
96
|
print '.'
|
@@ -109,12 +116,12 @@ No block, just calling methods:
|
|
109
116
|
require 'fidget'
|
110
117
|
|
111
118
|
Fidget.prevent_sleep(:display, :sleep)
|
112
|
-
|
119
|
+
|
113
120
|
100.times do
|
114
121
|
print '.'
|
115
122
|
sleep 1
|
116
123
|
end
|
117
|
-
|
124
|
+
|
118
125
|
Fidget.allow_sleep
|
119
126
|
|
120
127
|
Simply prevent the computer from sleeping while the current process is running:
|
@@ -123,12 +130,12 @@ Simply prevent the computer from sleeping while the current process is running:
|
|
123
130
|
require 'fidget'
|
124
131
|
|
125
132
|
Fidget.current_process
|
126
|
-
|
133
|
+
|
127
134
|
100.times do
|
128
135
|
print '.'
|
129
136
|
sleep 1
|
130
137
|
end
|
131
|
-
|
138
|
+
|
132
139
|
|
133
140
|
## Limitations
|
134
141
|
|
data/bin/fidget
CHANGED
@@ -19,6 +19,8 @@ the following core options:
|
|
19
19
|
Additional OS X options:
|
20
20
|
* 'idle' will prevent the system from idle sleeping.
|
21
21
|
* 'disk' will prevent the disk from sleeping.
|
22
|
+
* 'user' will assert that the user is active. This keeps the display
|
23
|
+
on and prevents idle sleep.
|
22
24
|
|
23
25
|
Additional Windows options:
|
24
26
|
* 'away' enables a low-power, but not sleeping, mode on Windows.
|
@@ -27,6 +29,11 @@ Additional Windows options:
|
|
27
29
|
Additional Linux options:
|
28
30
|
* 'blanking' disables terminal blanking on Linux.
|
29
31
|
|
32
|
+
Default options for each platform:
|
33
|
+
* OS X: `user`
|
34
|
+
* Linux: `display`
|
35
|
+
* Windows: `display,sleep`
|
36
|
+
|
30
37
|
If you pass the a command, then Fidget will execute that command and prevent
|
31
38
|
the system from sleeping until that command terminates. If you do not provide a
|
32
39
|
command, then Fidget will prevent sleeping until you press Ctrl-C to terminate.
|
@@ -37,7 +44,7 @@ command, then Fidget will prevent sleeping until you press Ctrl-C to terminate.
|
|
37
44
|
end
|
38
45
|
|
39
46
|
opts.on("-d", "--debug", "Display debugging messages") do
|
40
|
-
|
47
|
+
Fidget.debuglevel = Logger::DEBUG
|
41
48
|
end
|
42
49
|
|
43
50
|
opts.on("-v", "--version", "Display the version of Fidget") do
|
data/lib/fidget.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Fidget
|
2
2
|
require 'fidget/version'
|
3
|
+
require 'fidget/logger'
|
3
4
|
|
4
5
|
case Gem::Platform.local.os
|
5
6
|
when /darwin/
|
@@ -12,18 +13,24 @@ class Fidget
|
|
12
13
|
require 'fidget/platform/windows'
|
13
14
|
|
14
15
|
when 'java'
|
15
|
-
|
16
|
+
logger.error 'When running under jRuby, we cannot reliably manage power settings.'
|
16
17
|
require 'fidget/platform/null'
|
17
18
|
|
18
19
|
else
|
19
20
|
raise "Unknown platform: #{Gem::Platform.local.os}"
|
20
21
|
end
|
21
22
|
|
22
|
-
def self.current_process(options
|
23
|
+
def self.current_process(*options)
|
24
|
+
simulator(options)
|
25
|
+
options.delete :simulate
|
26
|
+
|
23
27
|
Fidget::Platform.current_process(options)
|
24
28
|
end
|
25
29
|
|
26
|
-
def self.prevent_sleep(options
|
30
|
+
def self.prevent_sleep(*options)
|
31
|
+
simulator(options)
|
32
|
+
options.delete :simulate
|
33
|
+
|
27
34
|
if block_given?
|
28
35
|
Fidget::Platform.prevent_sleep(options) do
|
29
36
|
yield
|
@@ -31,10 +38,33 @@ class Fidget
|
|
31
38
|
else
|
32
39
|
Fidget::Platform.prevent_sleep(options)
|
33
40
|
end
|
41
|
+
|
34
42
|
end
|
35
43
|
|
36
44
|
def self.allow_sleep
|
45
|
+
Thread.kill @@simulator if @@simulator
|
37
46
|
Fidget::Platform.allow_sleep
|
38
47
|
end
|
39
48
|
|
49
|
+
def self.simulator(options)
|
50
|
+
# if :all or :simulate were passed, start up the action simulator
|
51
|
+
unless (options & [:all, :simulate]).empty?
|
52
|
+
@@simulator = Thread.new do
|
53
|
+
loop do
|
54
|
+
Fidget::Platform.simulate
|
55
|
+
sleep 30
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# if this is still running, make sure it gets cleaned up
|
60
|
+
at_exit do
|
61
|
+
return unless @@simulator
|
62
|
+
return unless @@simulator.alive?
|
63
|
+
Thread.kill @@simulator
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
private_class_method :simulator
|
69
|
+
|
40
70
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Fidget
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
def self.logger
|
5
|
+
unless @logger
|
6
|
+
@logger = Logger.new(STDERR)
|
7
|
+
@logger.level = Logger::WARN
|
8
|
+
end
|
9
|
+
@logger
|
10
|
+
end
|
11
|
+
private_class_method :logger
|
12
|
+
|
13
|
+
def self.error(message)
|
14
|
+
logger.error(message)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.warn(message)
|
18
|
+
logger.warn(message)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.debug(message)
|
22
|
+
logger.debug(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.debuglevel=(level)
|
26
|
+
logger.level = level
|
27
|
+
end
|
28
|
+
end
|
@@ -29,9 +29,17 @@ class Fidget::Platform
|
|
29
29
|
@@pids = nil
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.
|
32
|
+
def self.simulate
|
33
|
+
# osx needs accessibilty access to do this, along with a big scary prompt.
|
34
|
+
# But it's not really needed anyway. Caffeinate works really well.
|
35
|
+
# Should we want to at some point..., https://github.com/AXElements/AXElements
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def self.arguments(options)
|
33
40
|
options.flatten!
|
34
41
|
options.compact!
|
42
|
+
return '-u' if options.empty?
|
35
43
|
return '-dism' if options == [:all]
|
36
44
|
|
37
45
|
terms = {
|
@@ -39,6 +47,7 @@ class Fidget::Platform
|
|
39
47
|
:idle => 'i',
|
40
48
|
:disk => 'm',
|
41
49
|
:sleep => 's',
|
50
|
+
:user => 'u',
|
42
51
|
}
|
43
52
|
options.each do |opt|
|
44
53
|
STDERR.puts "Fidget: option #{opt} is not supported on OS X" unless terms.include? opt
|
@@ -2,6 +2,7 @@ class Fidget::Platform
|
|
2
2
|
require "dbus"
|
3
3
|
|
4
4
|
def self.current_process(options)
|
5
|
+
return false unless required_binaries
|
5
6
|
options = munge(options)
|
6
7
|
suspend(options)
|
7
8
|
|
@@ -11,6 +12,7 @@ class Fidget::Platform
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.prevent_sleep(options)
|
15
|
+
return false unless required_binaries
|
14
16
|
options = munge(options)
|
15
17
|
suspend(options)
|
16
18
|
|
@@ -23,11 +25,17 @@ class Fidget::Platform
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def self.allow_sleep
|
28
|
+
return false unless required_binaries
|
26
29
|
options = munge(options)
|
27
30
|
resume(options)
|
28
31
|
end
|
29
32
|
|
30
|
-
def self.
|
33
|
+
def self.simulate
|
34
|
+
return false unless required_binaries('xset')
|
35
|
+
system('xset reset')
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.munge(options)
|
31
39
|
options.flatten!
|
32
40
|
options.compact!
|
33
41
|
options = [:display] if options.empty?
|
@@ -65,7 +73,7 @@ class Fidget::Platform
|
|
65
73
|
rescue => e
|
66
74
|
STDERR.puts 'Fidget: DBus action failed.'
|
67
75
|
STDERR.puts e.message
|
68
|
-
STDERR.puts e.backtrace.
|
76
|
+
STDERR.puts e.backtrace.first
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
@@ -101,4 +109,16 @@ class Fidget::Platform
|
|
101
109
|
end
|
102
110
|
private_class_method :dbus_screensaver
|
103
111
|
|
112
|
+
def self.required_binaries(*list)
|
113
|
+
list = ['xset', 'xdg-screensaver', 'xwininfo'] if list.empty?
|
114
|
+
found = true
|
115
|
+
list.each do |command|
|
116
|
+
unless system("which #{command} > /dev/null 2>&1")
|
117
|
+
found = false
|
118
|
+
Fidget.debug "Fidget: required binary (#{command}) not found."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
found
|
122
|
+
end
|
123
|
+
private_class_method :required_binaries
|
104
124
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Fidget::Platform
|
2
|
+
def self.current_process(options)
|
3
|
+
false
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.prevent_sleep(options)
|
7
|
+
return false
|
8
|
+
|
9
|
+
# prevent sleep
|
10
|
+
if block_given?
|
11
|
+
yield
|
12
|
+
# allow sleep
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.allow_sleep
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.simulate
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -33,10 +33,17 @@ class Fidget::Platform
|
|
33
33
|
set_state(nil)
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.simulate
|
37
|
+
# memoized so we don't keep loading the library every few seconds
|
38
|
+
@@kb ||= Win32API.new('user32.dll', 'keybd_event', 'IILL', 'V')
|
39
|
+
@@kb.call(KB_KEY_F24, 0, KB_EVENT_KEYPRESS, 0)
|
40
|
+
@@kb.call(KB_KEY_F24, 0, KB_EVENT_KEYUP, 0)
|
41
|
+
end
|
42
|
+
|
36
43
|
# Set thread execution state, using information from
|
37
44
|
# https://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx
|
38
45
|
# http://stackoverflow.com/questions/4126136/stop-a-windows-7-pc-from-going-to-sleep-while-a-ruby-program-executes
|
39
|
-
def self.set_state(
|
46
|
+
def self.set_state(options)
|
40
47
|
options.flatten!
|
41
48
|
options.compact!
|
42
49
|
options = [:display, :sleep] if options.empty?
|
@@ -57,20 +64,6 @@ class Fidget::Platform
|
|
57
64
|
state = Win32API.new('kernel32','SetThreadExecutionState','L')
|
58
65
|
state.call(ES_CONTINUOUS|mode)
|
59
66
|
|
60
|
-
if options.include? :simulate
|
61
|
-
@@kb_poker = Thread.new do
|
62
|
-
kb = Win32API.new('user32.dll', 'keybd_event', 'nnnn', 'v')
|
63
|
-
loop do
|
64
|
-
kb.call(KB_KEY_F24, 0, KB_EVENT_KEYPRESS, nil)
|
65
|
-
kb.call(KB_KEY_F24, 0, KB_EVENT_KEYUP, nil)
|
66
|
-
sleep 30
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
if options.nil?
|
72
|
-
Thread.kill @@kb_poker if @@kb_poker
|
73
|
-
end
|
74
67
|
end
|
75
68
|
private_class_method :set_state
|
76
69
|
|
data/lib/fidget/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
class Fidget
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.4'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fidget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-dbus
|
@@ -42,8 +42,10 @@ files:
|
|
42
42
|
- README.md
|
43
43
|
- LICENSE
|
44
44
|
- bin/fidget
|
45
|
+
- lib/fidget/logger.rb
|
45
46
|
- lib/fidget/platform/darwin.rb
|
46
47
|
- lib/fidget/platform/linux.rb
|
48
|
+
- lib/fidget/platform/null.rb
|
47
49
|
- lib/fidget/platform/windows.rb
|
48
50
|
- lib/fidget/version.rb
|
49
51
|
- lib/fidget.rb
|