This repository has been archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.vala
67 lines (59 loc) · 2.01 KB
/
config.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Gee;
namespace PamBio {
errordomain ConfigError {
INVALID_KEY
}
class Config : GLib.Object {
public bool debug = false;
public bool enable_ssh = false;
public bool enable_closed_lid = false;
public Set<string> modules = new HashSet<string>();
public bool enable {
get {
var envp = Environ.get();
if (!enable_ssh) {
if (
Environ.get_variable(envp, "SSH_CONNECTION") != null ||
Environ.get_variable(envp, "SSH_CLIENT") != null ||
Environ.get_variable(envp, "SSHD_OPTS") != null
) {
return false;
}
}
if (!enable_closed_lid) {
var g = Posix.Glob();
g.glob("/proc/acpi/button/lid/*/state");
foreach (var path in g.pathv) {
if (path.contains("closed")) {
return false;
}
}
}
return true;
}
}
public void from_argv(string[] argv) throws ConfigError {
foreach (var arg in argv) {
string[] kv = arg.split("=", 2);
string key = kv[0];
string? value = kv.length > 1 ? kv[1] : null;
switch (key) {
case "debug":
debug = true;
break;
case "enable_ssh":
enable_ssh = true;
break;
case "enable_closed_lid":
enable_closed_lid = true;
break;
case "modules":
modules.add_all_array(value.split(","));
break;
default:
throw new ConfigError.INVALID_KEY(@"unknow key: $key");
}
}
}
}
}