Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make macOS bundle ID match the directories crate #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27,15 +27,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 @@ -55,7 +55,7 @@ impl super::AppStrategy for Apple {
fn new(args: super::AppStrategyArgs) -> Result<Self, Self::CreationError> {
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