Skip to content

Commit

Permalink
Merge pull request #22 from valadaptive/bundle-id
Browse files Browse the repository at this point in the history
Make macOS bundle ID match the `directories` crate
  • Loading branch information
utkarshgupta137 authored Feb 27, 2025
2 parents c65b9c4 + dbb18c5 commit 6cc955a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Etcetera has 2 modes of operation: `BaseStrategy` & `AppStrategy`:
For eg. if you provide the following details: `{ top_level_domain: "org", author: "Acme Corp", app_name: "Frobnicator Plus" }`, you'll get:
- XDG: `~/.config/frobnicator-plus`
- Unix: `~/.frobnicator-plus`
- Apple: `~/Library/Preferences/org.acmecorp.FrobnicatorPlus`
- Apple: `~/Library/Preferences/org.acme-corp.Frobnicator-Plus`
- Windows: `~\AppData\Roaming\Acme Corp\Frobnicator Plus`

Note: the location of the home (~) is determined by the [`home`](https://docs.rs/home/0.5.4/home/fn.home_dir.html) crate.
Expand Down
17 changes: 10 additions & 7 deletions src/app_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ impl AppStrategyArgs {
/// app_name: "Frobnicator Plus".to_string(),
/// };
///
/// assert_eq!(strategy_args.bundle_id().replace(' ', ""), "org.acmecorp.FrobnicatorPlus".to_string());
/// assert_eq!(strategy_args.bundle_id(), "org.acme-corp.Frobnicator-Plus".to_string());
/// ```
pub fn bundle_id(&self) -> String {
format!(
"{}.{}.{}",
self.top_level_domain,
self.author.to_lowercase(),
self.app_name
)
let author = self.author.to_lowercase().replace(' ', "-");
let app_name = self.app_name.replace(' ', "-");
let mut parts = vec![
self.top_level_domain.as_str(),
author.as_str(),
app_name.as_str(),
];
parts.retain(|part| !part.is_empty());
parts.join(".")
}

/// Returns a ‘unixy’ version of the application’s name, akin to what would usually be used as a binary name.
Expand Down
8 changes: 4 additions & 4 deletions src/app_strategy/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ use std::path::{Path, PathBuf};
/// );
/// assert_eq!(
/// app_strategy.config_dir().strip_prefix(&home_dir),
/// Ok(Path::new("Library/Preferences/org.acmecorp.FrobnicatorPlus/"))
/// Ok(Path::new("Library/Preferences/org.acme-corp.Frobnicator-Plus/"))
/// );
/// assert_eq!(
/// app_strategy.data_dir().strip_prefix(&home_dir),
/// Ok(Path::new("Library/Application Support/org.acmecorp.FrobnicatorPlus/"))
/// Ok(Path::new("Library/Application Support/org.acme-corp.Frobnicator-Plus/"))
/// );
/// assert_eq!(
/// app_strategy.cache_dir().strip_prefix(&home_dir),
/// Ok(Path::new("Library/Caches/org.acmecorp.FrobnicatorPlus/"))
/// Ok(Path::new("Library/Caches/org.acme-corp.Frobnicator-Plus/"))
/// );
/// assert_eq!(
/// app_strategy.state_dir(),
Expand All @@ -54,7 +54,7 @@ impl Apple {
pub fn new(args: super::AppStrategyArgs) -> Result<Self, HomeDirError> {
Ok(Self {
base_strategy: base_strategy::Apple::new()?,
bundle_id: args.bundle_id().replace(' ', ""),
bundle_id: args.bundle_id(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! Let’s take an application created by `Acme Corp` with the name `Frobnicator Plus` and the top-level domain of `jrg` as an example.
//! - XDG strategy would place these in `~/.config/frobnicator-plus`.
//! - Unix strategy would place these in `~/.frobnicator-plus`.
//! - Apple strategy would place these in `~/Library/Preferences/org.acmecorp.FrobnicatorPlus`.
//! - Apple strategy would place these in `~/Library/Preferences/org.acme-corp.Frobnicator-Plus`.
//! - Windows strategy would place these in `~\AppData\Roaming\Acme Corp\Frobnicator Plus`.
//!
//! ```
Expand Down

0 comments on commit 6cc955a

Please sign in to comment.