-
Notifications
You must be signed in to change notification settings - Fork 2
/
redshift-scheduler.vala
60 lines (46 loc) · 1.77 KB
/
redshift-scheduler.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
namespace RedshiftScheduler {
int main(string[] args) {
ApplicationConfig config;
try {
config = new ApplicationConfig.from_args(ref args);
} catch (ApplicationConfigError e) {
stderr.printf("%s\n", e.message);
return 1;
}
ILogger logger = new StandardLogger(config.debug_mode);
logger.install();
if (config.show_version) {
stdout.printf("redshift-scheduler %s\n", Application.VERSION);
return 0;
}
File rules_file = File.new_for_path(config.rules_path);
if (!rules_file.query_exists()) {
if (!create_file_from_template(rules_file, "rules.conf.dist")) {
critical("Could not create default rules file. The program is most likely installed incorrectly.");
return 1;
}
message("Created a default rules file in `%s` - you can modify it to your liking now.", config.rules_path);
}
IRulesProvider rules_provider = new LiveFileRulesProvider(new FileRulesProvider(rules_file));
ITemperatureDeterminer temperature_determiner = new RulesBasedTemperatureDeterminer(rules_provider);
// Run this early, before we set up `EnvironmentRestorer` or other such things having side-effects.
// In print mode, we'd like to print and exit without changing anything at all.
if (config.print_mode) {
try {
int temperature = temperature_determiner.determine_temperature();
stdout.printf("%dK", temperature);
} catch (TemperatureDeterminerError e) {
stderr.printf(e.message);
return 1;
}
return 0;
}
ITemperatureSetter temperature_setter = new RedshiftTemperatureSetter();
EnvironmentRestorer.setup(temperature_setter);
Application app = new Application(config, temperature_determiner, temperature_setter);
app.set_power_resume_detector(new DBusPowerResumeDetector());
app.run();
new MainLoop().run();
return 0;
}
}