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

Add support for URL schemes for macOS #123

Merged
merged 1 commit into from
Nov 19, 2022
Merged
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
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ These settings are used only when bundling `osx` packages.
this config field, you may also want have your `build.rs` script emit
`cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.11` (or whatever version number
you want) to ensure that the compiled binary has the same minimum version.
* `osx_url_schemes`: A list of strings indicating the URL schemes that the app
handles.

### Example `Cargo.toml`:

Expand All @@ -132,6 +134,7 @@ nisi ut aliquip ex ea commodo consequat.
"""
deb_depends = ["libgl1-mesa-glx", "libsdl2-2.0-0 (>= 2.0.5)"]
osx_frameworks = ["SDL2"]
osx_url_schemes = ["com.doe.exampleapplication"]
```

## Contributing
Expand Down
20 changes: 20 additions & 0 deletions src/bundle/osx_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ fn create_info_plist(bundle_dir: &Path, bundle_icon_file: Option<PathBuf>,
write!(file,
" <key>CFBundleShortVersionString</key>\n <string>{}</string>\n",
settings.version_string())?;
if !settings.osx_url_schemes().is_empty() {
write!(file,
" <key>CFBundleURLTypes</key>\n \
<array>\n \
<dict>\n \
<key>CFBundleURLName</key>\n \
<string>{}</string>\n \
<key>CFBundleTypeRole</key>\n \
<string>Viewer</string>\n \
<key>CFBundleURLSchemes</key>\n \
<array>\n",
settings.bundle_name())?;
for scheme in settings.osx_url_schemes() {
write!(file, " <string>{}</string>\n", scheme)?;
}
write!(file,
" </array>\n \
</dict>\n \
</array>\n")?;
}
write!(file,
" <key>CFBundleVersion</key>\n <string>{}</string>\n",
build_number)?;
Expand Down
8 changes: 8 additions & 0 deletions src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct BundleSettings {
deb_depends: Option<Vec<String>>,
osx_frameworks: Option<Vec<String>>,
osx_minimum_system_version: Option<String>,
osx_url_schemes: Option<Vec<String>>,
// Bundles for other binaries/examples:
bin: Option<HashMap<String, BundleSettings>>,
example: Option<HashMap<String, BundleSettings>>,
Expand Down Expand Up @@ -433,6 +434,13 @@ impl Settings {
pub fn osx_minimum_system_version(&self) -> Option<&str> {
self.bundle_settings.osx_minimum_system_version.as_ref().map(String::as_str)
}

pub fn osx_url_schemes(&self) -> &[String] {
match self.bundle_settings.osx_url_schemes {
Some(ref urlosx_url_schemes) => urlosx_url_schemes.as_slice(),
None => &[],
}
}
}

fn bundle_settings_from_table(opt_map: &Option<HashMap<String, BundleSettings>>,
Expand Down