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
extern crate dconf_rs;

static DCONF_KEY: &'static str = "/org/gnome/shell/extensions/kylecorry31-do-not-disturb/do-not-disturb";


pub struct DoNotDisturb;

impl DoNotDisturb {

	pub fn new() -> Result<Self, String> {
		let dconf_str = dconf_rs::get_string(DCONF_KEY);

		match dconf_str {
			Ok(val) => {
				if val.is_empty() {
					Err("Do not disturb extension not installed".to_string())
				} else {
					Ok(DoNotDisturb {})
				}
			},
			Err(why) => Err(why)
		}
	}

	/// Activate the do not disturb mode
	pub fn activate(&self) -> Result<(), String> {
		dconf_rs::set_boolean(DCONF_KEY, true)
	}

	/// Deactivate the do not disturb mode
	pub fn deactivate(&self) -> Result<(), String> {
		dconf_rs::set_boolean(DCONF_KEY, false)
	}

	/// Determines if the do not disturb mode is active. Returns true if DND is active, false otherwise.
	pub fn is_active(&self) -> Result<bool, String> {
		dconf_rs::get_boolean(DCONF_KEY)
	}
}