diff options
| author | Christopher Warner <cwarner@kernelcode.com> | 2026-10-10 18:47:24 -0400 |
|---|---|---|
| committer | Christopher Warner <cwarner@kernelcode.com> | 2026-10-10 18:47:24 -0400 |
| commit | 5c61196f27b9342e5f25414c11df5710f956f406 (patch) | |
| tree | c81f15f54c9baa35f61ce3c71b81f1c1e7b5f590 /src/config.rs | |
| parent | 78862ba855c6e66cac64a86c25dca6149d8fb2fd (diff) | |
| download | iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.gz iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.bz2 iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.xz iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.zip | |
feat!: rewrite icloud-note CLI in Rust with chromiumoxide
Replace the Node/Playwright driver with a single Rust binary so create/status
stay headless without a visible browser. Move the previous implementation to
legacy/nodejs for reference.
BREAKING CHANGE: the supported CLI is the Rust `icloud-note` binary; the
Node entrypoint is no longer installed by setup.sh.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..dbd2136 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,51 @@ +use std::path::PathBuf; + +#[derive(Debug, Clone)] +pub struct Paths { + pub config_dir: PathBuf, + pub profile_dir: PathBuf, + pub marker_path: PathBuf, +} + +impl Paths { + pub fn resolve() -> Self { + let config_dir = std::env::var_os("ICLOUD_NOTES_CONFIG") + .map(PathBuf::from) + .unwrap_or_else(|| { + dirs::config_dir() + .unwrap_or_else(|| PathBuf::from(".").join(".config")) + .join("icloud-notes") + }); + Self { + profile_dir: config_dir.join("browser-profile"), + marker_path: config_dir.join("session.ok"), + config_dir, + } + } + + pub fn ensure(&self) -> std::io::Result<()> { + std::fs::create_dir_all(&self.config_dir)?; + std::fs::create_dir_all(&self.profile_dir)?; + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let _ = std::fs::set_permissions(&self.config_dir, std::fs::Permissions::from_mode(0o700)); + let _ = std::fs::set_permissions(&self.profile_dir, std::fs::Permissions::from_mode(0o700)); + } + Ok(()) + } + + pub fn has_session(&self) -> bool { + self.marker_path.is_file() + || self.profile_dir.join("Default").is_dir() + || self.profile_dir.join("Cookies").is_file() + } +} + +pub fn dry_run() -> bool { + matches!(std::env::var("ICLOUD_NOTES_DRY_RUN").as_deref(), Ok("1")) +} + +pub fn notes_url() -> &'static str { + "https://www.icloud.com/notes/" +} |
