keal 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.standard.yml +2 -0
- data/CHANGELOG.md +13 -1
- data/Gemfile +4 -0
- data/Gemfile.lock +73 -0
- data/README.md +28 -11
- data/Rakefile +20 -1
- data/dist/keald.local.service +12 -0
- data/dist/keald.service +12 -0
- data/exe/keal +33 -0
- data/exe/keald +17 -0
- data/ext/gsettings/extconf.rb +17 -0
- data/ext/gsettings/gsettings.c +60 -0
- data/keal.gemspec +4 -3
- data/lib/gsettings/version.rb +7 -0
- data/lib/gsettings.rb +21 -0
- data/lib/keal/setup.rb +26 -0
- data/lib/keal/shared.rb +15 -0
- data/lib/keal/teardown.rb +18 -0
- data/lib/keal/version.rb +2 -2
- data/lib/keal.rb +45 -2
- data/lib/keald/mask.rb +37 -0
- data/lib/keald/monkey.rb +27 -0
- data/lib/keald/unmask.rb +35 -0
- data/lib/keald/user.rb +10 -0
- data/lib/keald/version.rb +7 -0
- data/lib/keald.rb +38 -0
- data/lib/pref.rb +5 -0
- metadata +34 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1efec36afbfe0f9c02b29ee1c4c2196d2ec924d179d93c8a0a732cee950f4098
|
4
|
+
data.tar.gz: 93f6c00258a4b1697922e8b30796762092ee5eedc0ec00b345098ee60f09e5f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 188b2dffca57c728bb6096bd449fc311c1b940a2e7633bb13a84cb00357df8b70c45ca87eabbc734672717be059bd81954ca46fcfd13e62b1acbda8d6279e896
|
7
|
+
data.tar.gz: e799f70207b67686d6c2afb4059cc064809e9750d34a3c8bfa238e5e438f0f8e70450297b4eea3339719a8787268b37e9c407085624d80943d9876ed6356b8a7
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
system
|
data/.standard.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0] - 2023-04-14
|
4
|
+
|
5
|
+
This release gets `keal` up to spec with its uncrealeased prototype (0.0.2). There are some differences, though, primarily that the daemon handles all masking and unmasking of services and options (whereas previously these functions were split up). There is also a custom gsettings exention now, allowing relevant dconf settings to be changed programatically.
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- A gsettings extension (https://developer-old.gnome.org/glibmm/stable/classGio_1_1Settings.html).
|
10
|
+
- The `keald` daemon, which listens for connections and performs masking and unmasking of services and dconf options.
|
11
|
+
- The `keal` program, which connects to the `keald` daemon and directs it what services and dconf options to mask/unmask, as well as for how long.
|
12
|
+
- A `Preferences` module for any shared values between `keal` and `keald`.
|
13
|
+
- The systemd unit file for the `keald` daemon (cannot be installed via `gem install keal`).
|
14
|
+
|
15
|
+
## [0.1.0] - 2023-03-23
|
4
16
|
|
5
17
|
- Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
keal (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
dbus-systemd (1.1.2)
|
11
|
+
ruby-dbus (~> 0.14)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
json (2.6.3)
|
14
|
+
language_server-protocol (3.17.0.3)
|
15
|
+
parallel (1.22.1)
|
16
|
+
parser (3.2.2.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
rainbow (3.1.1)
|
19
|
+
rake (13.0.6)
|
20
|
+
rake-compiler (1.2.1)
|
21
|
+
rake
|
22
|
+
regexp_parser (2.7.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.12.0)
|
25
|
+
rspec-core (~> 3.12.0)
|
26
|
+
rspec-expectations (~> 3.12.0)
|
27
|
+
rspec-mocks (~> 3.12.0)
|
28
|
+
rspec-core (3.12.1)
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-expectations (3.12.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-mocks (3.12.5)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-support (3.12.0)
|
37
|
+
rubocop (1.48.1)
|
38
|
+
json (~> 2.3)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 3.2.0.0)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
43
|
+
rexml (>= 3.2.5, < 4.0)
|
44
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
47
|
+
rubocop-ast (1.28.0)
|
48
|
+
parser (>= 3.2.1.0)
|
49
|
+
rubocop-performance (1.16.0)
|
50
|
+
rubocop (>= 1.7.0, < 2.0)
|
51
|
+
rubocop-ast (>= 0.4.0)
|
52
|
+
ruby-dbus (0.21.0)
|
53
|
+
rexml
|
54
|
+
ruby-progressbar (1.13.0)
|
55
|
+
standard (1.26.0)
|
56
|
+
language_server-protocol (~> 3.17.0.2)
|
57
|
+
rubocop (~> 1.48.1)
|
58
|
+
rubocop-performance (~> 1.16.0)
|
59
|
+
unicode-display_width (2.4.2)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
x86_64-linux
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
dbus-systemd
|
66
|
+
keal!
|
67
|
+
rake (~> 13.0)
|
68
|
+
rake-compiler
|
69
|
+
rspec (~> 3.0)
|
70
|
+
standard (~> 1.3)
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.4.6
|
data/README.md
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# keal
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/keal`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
A keep alive program for Linux/GNOME, inspired by [caffeinate(8)](https://ss64.com/osx/caffeinate.html) on MacOS.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
You may install keal using `gem install keal`, however, this will not install the systemd unit file. So, for now, the recommended way to install `keal` is:
|
8
|
+
|
9
|
+
```sh
|
10
|
+
git clone https://github.com/pinecat/keal
|
11
|
+
cd keal
|
12
|
+
bin/setup
|
13
|
+
sudo rake install
|
14
|
+
sudo rake install:service
|
15
|
+
```
|
10
16
|
|
11
|
-
|
17
|
+
```sh
|
18
|
+
git clone https://github.com/pinecat/keal && cd keal && bin/setup && sudo rake install && sudo rake install:service # one-liner
|
19
|
+
```
|
12
20
|
|
13
|
-
|
21
|
+
### Non-RPM-based distros
|
14
22
|
|
15
|
-
|
23
|
+
Currently, `bin/setup` only supports RPM-based distros. I would like to add support for more distros in the near future, however, if you just want to try it out--on, say Ubuntu--you can run `bundle install`, and then you'll need to get the following from your package manager:
|
16
24
|
|
17
|
-
|
25
|
+
- glibmm2.4 headers
|
26
|
+
- ruby development headers
|
27
|
+
- make
|
28
|
+
- g++
|
18
29
|
|
19
30
|
## Usage
|
20
31
|
|
21
|
-
|
32
|
+
```sh
|
33
|
+
$ keal [options] [program [args]]
|
34
|
+
```
|
35
|
+
|
36
|
+
### Caveats
|
37
|
+
|
38
|
+
Right now, `keal` has two options that affect how it runs: `-i`, and `-l`. The `-i` option will disable screen idle (meaning the screen will never turn off it's display). In current versions of GNOME, this is also disable the lock-screen, as the screen will only ever lock after the display as gone blank. The `-l` option--which disables the screen from locking--may be specified alongside the `-i` option if you wish, however, it is redundant in that case.
|
22
39
|
|
23
40
|
## Development
|
24
41
|
|
@@ -28,7 +45,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
28
45
|
|
29
46
|
## Contributing
|
30
47
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pinecat/keal.
|
32
49
|
|
33
50
|
## License
|
34
51
|
|
data/Rakefile
CHANGED
@@ -6,5 +6,24 @@ require "rspec/core/rake_task"
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
8
|
require "standard/rake"
|
9
|
+
require "rake/extensiontask"
|
9
10
|
|
10
|
-
|
11
|
+
Rake::ExtensionTask.new "gsettings" do |ext|
|
12
|
+
ext.lib_dir = "lib/gsettings"
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :install do
|
16
|
+
task :service do
|
17
|
+
FileUtils.cp("./dist/keald.local.service", "/usr/lib/systemd/system/keald.service")
|
18
|
+
system("systemctl daemon-reload")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :uninstall do
|
23
|
+
task :service do
|
24
|
+
FileUtils.rm("/usr/lib/systemd/system/keald.service")
|
25
|
+
system("systemctl daemon-reload")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: %i[compile spec standard]
|
data/dist/keald.service
ADDED
data/exe/keal
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "keal"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
# Duplicate arguments before parsing options
|
7
|
+
# We will need it later for filtering out the command args
|
8
|
+
args = ARGV.dup
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |o|
|
12
|
+
o.banner = "Usage: keal [options] [command [args]]"
|
13
|
+
|
14
|
+
o.on "-V", "--version", "Print the version then quit" do
|
15
|
+
puts "keal v#{Keal::VERSION}"
|
16
|
+
exit 0
|
17
|
+
end
|
18
|
+
|
19
|
+
o.on "-i", "--idle", "Disable display idle" do |i|
|
20
|
+
options[:idle] = i
|
21
|
+
end
|
22
|
+
|
23
|
+
o.on "-l", "--lock", "Disable locking the user account" do |l|
|
24
|
+
options[:lock] = l
|
25
|
+
end
|
26
|
+
|
27
|
+
o.on "-f", "--force", "Run keal without it's daemon (requires root, not recommended)" do |f|
|
28
|
+
options[:force] = f
|
29
|
+
end
|
30
|
+
end.parse!
|
31
|
+
|
32
|
+
k = Keal.new(options, args)
|
33
|
+
k.run
|
data/exe/keald
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "keald"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |o|
|
8
|
+
o.banner = "Usage: keald [options]"
|
9
|
+
|
10
|
+
o.on "-V", "--version", "Print the version then quit" do
|
11
|
+
puts "keald v#{Keal::VERSION}"
|
12
|
+
exit 0
|
13
|
+
end
|
14
|
+
end.parse!
|
15
|
+
|
16
|
+
k = KealDaemon.new(options)
|
17
|
+
k.run
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mkmf"
|
4
|
+
|
5
|
+
# Module name
|
6
|
+
extension_name = "gsettings"
|
7
|
+
|
8
|
+
# Use C++
|
9
|
+
have_library "stdc++"
|
10
|
+
CONFIG["CC"] = "g++"
|
11
|
+
|
12
|
+
# Need extra flags for including glibmm and giomm (`pkgconf --cflags --libs glibmm-2.4 giomm-2.4`)
|
13
|
+
$CPPFLAGS << " -I/usr/include/glibmm-2.4 -I/usr/lib64/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/sigc++-2.0 -I/usr/lib64/sigc++-2.0/include -I/usr/include/giomm-2.4 -I/usr/lib64/giomm-2.4/include -I/usr/include/libmount -I/usr/include/blkid -pthread -lgiomm-2.4 -lgio-2.0 -lglibmm-2.4 -lgobject-2.0 -lglib-2.0 -lsigc-2.0"
|
14
|
+
$LDFLAGS << " -I/usr/include/glibmm-2.4 -I/usr/lib64/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/sigc++-2.0 -I/usr/lib64/sigc++-2.0/include -I/usr/include/giomm-2.4 -I/usr/lib64/giomm-2.4/include -I/usr/include/libmount -I/usr/include/blkid -pthread -lgiomm-2.4 -lgio-2.0 -lglibmm-2.4 -lgobject-2.0 -lglib-2.0 -lsigc-2.0"
|
15
|
+
|
16
|
+
# Create the Makefile
|
17
|
+
create_makefile "#{extension_name}/#{extension_name}"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
#include <giomm/init.h>
|
6
|
+
#include <giomm/settings.h>
|
7
|
+
#define HOME "HOME"
|
8
|
+
#define DBUS "DBUS_SESSION_BUS_ADDRESS"
|
9
|
+
|
10
|
+
VALUE method_get_idle_delay(VALUE self) {
|
11
|
+
uint s = Gio::Settings::create("org.gnome.desktop.session")->get_uint("idle-delay");
|
12
|
+
return UINT2NUM(s);
|
13
|
+
}
|
14
|
+
|
15
|
+
VALUE method_set_idle_delay(VALUE self, VALUE s) {
|
16
|
+
uint seconds = NUM2UINT(s);
|
17
|
+
Gio::Settings::create("org.gnome.desktop.session")->set_uint("idle-delay", seconds);
|
18
|
+
g_settings_sync();
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE method_get_lock_screen(VALUE self) {
|
23
|
+
bool l = Gio::Settings::create("org.gnome.desktop.lockdown")->get_boolean("disable-lock-screen");
|
24
|
+
return l;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE method_set_lock_screen(VALUE self, VALUE l) {
|
28
|
+
Gio::Settings::create("org.gnome.desktop.lockdown")->set_boolean("disable-lock-screen", l);
|
29
|
+
g_settings_sync();
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE method_get_env_uid(VALUE self) {
|
34
|
+
return UINT2NUM(getuid());
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE method_get_env_home(VALUE self) {
|
38
|
+
return rb_str_new_cstr(getenv("HOME"));
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE method_set_environment(VALUE self, VALUE uid, VALUE home, VALUE dbus) {
|
42
|
+
uint u = NUM2UINT(uid);
|
43
|
+
if (setuid(u) != 0) { return INT2NUM(-1); }
|
44
|
+
if (setenv(HOME, StringValueCStr(home), 1) != 0) { return INT2NUM(-2); }
|
45
|
+
if (setenv(DBUS, StringValueCStr(dbus), 1) != 0) { return INT2NUM(-3); }
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
|
49
|
+
VALUE gsettings = Qnil;
|
50
|
+
extern "C" void Init_gsettings() {
|
51
|
+
Gio::init();
|
52
|
+
gsettings = rb_const_get(rb_cObject, rb_intern("GSettings"));
|
53
|
+
rb_define_method(gsettings, "get_idle_delay", method_get_idle_delay, 0);
|
54
|
+
rb_define_method(gsettings, "set_idle_delay", method_set_idle_delay, 1);
|
55
|
+
rb_define_method(gsettings, "get_lock_screen", method_get_lock_screen, 0);
|
56
|
+
rb_define_method(gsettings, "set_lock_screen", method_set_lock_screen, 1);
|
57
|
+
rb_define_method(gsettings, "get_env_uid", method_get_env_uid, 0);
|
58
|
+
rb_define_method(gsettings, "get_env_home", method_get_env_home, 0);
|
59
|
+
rb_define_method(gsettings, "set_environment", method_set_environment, 3);
|
60
|
+
}
|
data/keal.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Rory Dudley"]
|
9
9
|
spec.email = ["rory.dudley@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "Keep alive for Linux."
|
12
|
-
spec.description = "Keep alive program for Linux, inspired by caffeinate(8) on MacOS."
|
11
|
+
spec.summary = "Keep alive program for Linux/GNOME."
|
12
|
+
spec.description = "Keep alive program for the GNOME desktop environment on Linux, inspired by caffeinate(8) on MacOS."
|
13
13
|
spec.homepage = "https://github.com/pinecat/keal"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.6.0"
|
@@ -24,12 +24,13 @@ Gem::Specification.new do |spec|
|
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
25
|
spec.files = Dir.chdir(__dir__) do
|
26
26
|
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
28
|
end
|
29
29
|
end
|
30
30
|
spec.bindir = "exe"
|
31
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
|
+
spec.extensions = %w[ext/gsettings/extconf.rb]
|
33
34
|
|
34
35
|
# Uncomment to register a new dependency of your gem
|
35
36
|
# spec.add_dependency "example-gem", "~> 1.0"
|
data/lib/gsettings.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gsettings/version"
|
4
|
+
|
5
|
+
class GSettings
|
6
|
+
def idle_delay(s = nil)
|
7
|
+
return get_idle_delay if s.nil?
|
8
|
+
set_idle_delay(s)
|
9
|
+
end
|
10
|
+
|
11
|
+
def disable_lock_screen(l = nil)
|
12
|
+
return get_lock_screen if l.nil?
|
13
|
+
set_lock_screen(l)
|
14
|
+
end
|
15
|
+
|
16
|
+
def environment(uid, home, dbus)
|
17
|
+
set_environment(uid, home, dbus)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require "gsettings/gsettings"
|
data/lib/keal/setup.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Keal
|
4
|
+
def setup
|
5
|
+
if @options[:force]
|
6
|
+
unless @kd.runas(@user, @dbus)
|
7
|
+
puts "keal: Daemon cannot switch user contexts"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
@kd.mask(@pid, @options)
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
if daemon?
|
16
|
+
unless @daemon.runas(@user, @dbus)
|
17
|
+
puts "keal: Daemon cannot switch user contexts"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
@daemon.mask(@pid, @options)
|
22
|
+
else
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/keal/shared.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Keal
|
4
|
+
def daemon?(msg = true)
|
5
|
+
unless @options[:force]
|
6
|
+
begin
|
7
|
+
return @daemon.ping
|
8
|
+
rescue DRb::DRbConnError, Errno::ECONNREFUSED
|
9
|
+
puts "keal: Please ensure 'keald.service' is running, or use the '-f' option (requires sudo, not recommended)" if msg
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Keal
|
4
|
+
def teardown
|
5
|
+
if @options[:force]
|
6
|
+
@kd.runas(@user, @dbus)
|
7
|
+
@kd.unmask(@pid)
|
8
|
+
return
|
9
|
+
end
|
10
|
+
|
11
|
+
if daemon? false
|
12
|
+
@daemon.runas(@user, @dbus)
|
13
|
+
@daemon.unmask(@pid)
|
14
|
+
else
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/keal/version.rb
CHANGED
data/lib/keal.rb
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "keal/setup"
|
4
|
+
require_relative "keal/shared"
|
5
|
+
require_relative "keal/teardown"
|
3
6
|
require_relative "keal/version"
|
7
|
+
require_relative "keald"
|
8
|
+
require_relative "pref"
|
9
|
+
require "dbus/systemd"
|
10
|
+
require "drb/drb"
|
11
|
+
require "etc"
|
4
12
|
|
5
|
-
|
13
|
+
class Keal
|
6
14
|
class Error < StandardError; end
|
7
|
-
|
15
|
+
|
16
|
+
def initialize(options, args)
|
17
|
+
@options = options
|
18
|
+
@uri = Preferences::URI
|
19
|
+
@user = Etc.getlogin
|
20
|
+
@dbus = ENV["DBUS_SESSION_BUS_ADDRESS"]
|
21
|
+
@pid = Process.pid
|
22
|
+
@daemon = DRbObject.new_with_uri(@uri)
|
23
|
+
@command = filter args
|
24
|
+
@kd = KealDaemon.new({}) if @options[:force]
|
25
|
+
end
|
26
|
+
|
27
|
+
def signals
|
28
|
+
sig = [:INT, :HUP]
|
29
|
+
sig.each do |s|
|
30
|
+
Signal.trap s do
|
31
|
+
exit 0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def filter(args)
|
37
|
+
args.each do |a|
|
38
|
+
args = args.drop(1) if a[0, 1] == "-"
|
39
|
+
break unless a[0, 1] == "-"
|
40
|
+
end
|
41
|
+
args.join(" ") unless args[0].nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
signals
|
46
|
+
setup
|
47
|
+
(@command ? system(@command) : gets)
|
48
|
+
ensure
|
49
|
+
teardown
|
50
|
+
end
|
8
51
|
end
|
data/lib/keald/mask.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class KealDaemon
|
4
|
+
def mask(pid, info)
|
5
|
+
mask_targets(pid, info)
|
6
|
+
mask_idle(info) if info[:idle]
|
7
|
+
mask_lock(info) if info[:lock]
|
8
|
+
end
|
9
|
+
|
10
|
+
def mask_targets(pid, info)
|
11
|
+
return false if @procs.has_key? pid
|
12
|
+
|
13
|
+
begin
|
14
|
+
@mgr.MaskUnitFiles(@targets, false, false) if @procs.empty?
|
15
|
+
rescue DBus::Error
|
16
|
+
puts "keal: Unable to mask targets, are you running as root?"
|
17
|
+
exit 1 if info[:force]
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
@procs[pid] = info
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def mask_idle(info)
|
26
|
+
return if @procs.idling?
|
27
|
+
info[:s] = @gsettings.idle_delay
|
28
|
+
@gsettings.idle_delay 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def mask_lock(info)
|
32
|
+
info[:l] = @procs.lock_disabled?
|
33
|
+
return unless info[:l].nil?
|
34
|
+
info[:l] = @gsettings.disable_lock_screen
|
35
|
+
@gsettings.disable_lock_screen true
|
36
|
+
end
|
37
|
+
end
|
data/lib/keald/monkey.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monkey
|
4
|
+
module Procs
|
5
|
+
def has_one?
|
6
|
+
length == 1
|
7
|
+
end
|
8
|
+
|
9
|
+
def idling?
|
10
|
+
each do |k, v|
|
11
|
+
if !v[:s].nil?
|
12
|
+
return true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def lock_disabled?
|
19
|
+
each do |k, v|
|
20
|
+
return v[:l] unless v[:l].nil?
|
21
|
+
end
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Hash.include Monkey::Procs
|
data/lib/keald/unmask.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class KealDaemon
|
4
|
+
def unmask(pid)
|
5
|
+
info = unmask_targets(pid)
|
6
|
+
return if info.nil?
|
7
|
+
unmask_idle(info) if info[:idle]
|
8
|
+
unmask_lock(info) if info[:lock]
|
9
|
+
end
|
10
|
+
|
11
|
+
def unmask_targets(pid)
|
12
|
+
return nil unless @procs.has_key? pid
|
13
|
+
|
14
|
+
begin
|
15
|
+
@mgr.UnmaskUnitFiles(@targets, false) if @procs.has_one?
|
16
|
+
rescue DBus::Error
|
17
|
+
puts "keal: Unable to unmask targets, are you running as root?"
|
18
|
+
return nil
|
19
|
+
end
|
20
|
+
|
21
|
+
info = @procs[pid]
|
22
|
+
@procs.delete pid
|
23
|
+
info
|
24
|
+
end
|
25
|
+
|
26
|
+
def unmask_idle(info)
|
27
|
+
return if @procs.idling?
|
28
|
+
@gsettings.idle_delay info[:s]
|
29
|
+
end
|
30
|
+
|
31
|
+
def unmask_lock(info)
|
32
|
+
return if @procs.lock_disabled?
|
33
|
+
@gsettings.disable_lock_screen info[:l]
|
34
|
+
end
|
35
|
+
end
|
data/lib/keald/user.rb
ADDED
data/lib/keald.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gsettings"
|
4
|
+
require_relative "keald/mask"
|
5
|
+
require_relative "keald/monkey"
|
6
|
+
require_relative "keald/unmask"
|
7
|
+
require_relative "keald/user"
|
8
|
+
require_relative "keald/version"
|
9
|
+
require_relative "pref"
|
10
|
+
require "dbus/systemd"
|
11
|
+
require "drb/drb"
|
12
|
+
|
13
|
+
class KealDaemon
|
14
|
+
def initialize(options)
|
15
|
+
@options = options
|
16
|
+
@uri = Preferences::URI
|
17
|
+
@targets = ["sleep.target", "suspend.target", "hibernate.target", "hybrid-sleep.target"]
|
18
|
+
@procs = {}
|
19
|
+
@gsettings = GSettings.new
|
20
|
+
@mgr = DBus::Systemd::Manager.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def signals
|
24
|
+
Signal.trap("SIGINT") { exit 0 }
|
25
|
+
Signal.trap("SIGHUP") { exit 0 }
|
26
|
+
end
|
27
|
+
|
28
|
+
def ping
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
signals
|
34
|
+
DRb.start_service(@uri, self)
|
35
|
+
DRb.thread.join
|
36
|
+
DRb.stop_service
|
37
|
+
end
|
38
|
+
end
|
data/lib/pref.rb
ADDED
metadata
CHANGED
@@ -1,31 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rory Dudley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Keep alive program for
|
13
|
+
description: Keep alive program for the GNOME desktop environment on Linux, inspired
|
14
|
+
by caffeinate(8) on MacOS.
|
14
15
|
email:
|
15
16
|
- rory.dudley@gmail.com
|
16
|
-
executables:
|
17
|
-
|
17
|
+
executables:
|
18
|
+
- keal
|
19
|
+
- keald
|
20
|
+
extensions:
|
21
|
+
- ext/gsettings/extconf.rb
|
18
22
|
extra_rdoc_files: []
|
19
23
|
files:
|
24
|
+
- ".ruby-version"
|
20
25
|
- ".standard.yml"
|
21
26
|
- CHANGELOG.md
|
22
27
|
- Gemfile
|
28
|
+
- Gemfile.lock
|
23
29
|
- LICENSE.txt
|
24
30
|
- README.md
|
25
31
|
- Rakefile
|
32
|
+
- dist/keald.local.service
|
33
|
+
- dist/keald.service
|
34
|
+
- exe/keal
|
35
|
+
- exe/keald
|
36
|
+
- ext/gsettings/extconf.rb
|
37
|
+
- ext/gsettings/gsettings.c
|
26
38
|
- keal.gemspec
|
39
|
+
- lib/gsettings.rb
|
40
|
+
- lib/gsettings/version.rb
|
27
41
|
- lib/keal.rb
|
42
|
+
- lib/keal/setup.rb
|
43
|
+
- lib/keal/shared.rb
|
44
|
+
- lib/keal/teardown.rb
|
28
45
|
- lib/keal/version.rb
|
46
|
+
- lib/keald.rb
|
47
|
+
- lib/keald/mask.rb
|
48
|
+
- lib/keald/monkey.rb
|
49
|
+
- lib/keald/unmask.rb
|
50
|
+
- lib/keald/user.rb
|
51
|
+
- lib/keald/version.rb
|
52
|
+
- lib/pref.rb
|
29
53
|
- sig/keal.rbs
|
30
54
|
homepage: https://github.com/pinecat/keal
|
31
55
|
licenses:
|
@@ -35,7 +59,7 @@ metadata:
|
|
35
59
|
homepage_uri: https://github.com/pinecat/keal
|
36
60
|
source_code_uri: https://github.com/pinecat/keal
|
37
61
|
changelog_uri: https://github.com/pinecat/keal
|
38
|
-
post_install_message:
|
62
|
+
post_install_message:
|
39
63
|
rdoc_options: []
|
40
64
|
require_paths:
|
41
65
|
- lib
|
@@ -50,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
74
|
- !ruby/object:Gem::Version
|
51
75
|
version: '0'
|
52
76
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
54
|
-
signing_key:
|
77
|
+
rubygems_version: 3.3.26
|
78
|
+
signing_key:
|
55
79
|
specification_version: 4
|
56
|
-
summary: Keep alive for Linux.
|
80
|
+
summary: Keep alive program for Linux/GNOME.
|
57
81
|
test_files: []
|