Skip to main content

atomcode_telemetry/
notice.rs

1//! First-run notice.
2
3use anyhow::Result;
4use std::fs;
5use std::path::Path;
6
7pub const MARKER: &str = ".telemetry_notice_shown";
8
9pub const NOTICE_TEXT: &str = "\
10ℹ AtomCode collects anonymous usage telemetry to improve the product.
11  Opt out: `atomcode telemetry disable`  |  Details: https://atomgit.com/atomgit_atomcode/atomcode/blob/main/docs/telemetry.md
12";
13
14pub fn should_show_and_mark(atomcode_dir: &Path) -> Result<bool> {
15    let m = atomcode_dir.join(MARKER);
16    if m.exists() {
17        return Ok(false);
18    }
19    fs::create_dir_all(atomcode_dir)?;
20    fs::write(&m, "")?;
21    Ok(true)
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use tempfile::TempDir;
28
29    #[test]
30    fn first_call_true_subsequent_false() {
31        let d = TempDir::new().unwrap();
32        assert!(should_show_and_mark(d.path()).unwrap());
33        assert!(!should_show_and_mark(d.path()).unwrap());
34        assert!(d.path().join(MARKER).exists());
35    }
36}