From 04605ae9ee840f2f3a43151227238f62dc0beda5 Mon Sep 17 00:00:00 2001 From: Kalissaac Date: Sun, 16 Oct 2022 00:28:46 -0700 Subject: [PATCH] Add URL schemes for macOS --- Readme.md | 3 +++ src/bundle/osx_bundle.rs | 20 ++++++++++++++++++++ src/bundle/settings.rs | 8 ++++++++ 3 files changed, 31 insertions(+) diff --git a/Readme.md b/Readme.md index e1a4955..9c31f46 100644 --- a/Readme.md +++ b/Readme.md @@ -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`: @@ -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 diff --git a/src/bundle/osx_bundle.rs b/src/bundle/osx_bundle.rs index 3f76c60..0bbf507 100644 --- a/src/bundle/osx_bundle.rs +++ b/src/bundle/osx_bundle.rs @@ -119,6 +119,26 @@ fn create_info_plist(bundle_dir: &Path, bundle_icon_file: Option, write!(file, " CFBundleShortVersionString\n {}\n", settings.version_string())?; + if !settings.osx_url_schemes().is_empty() { + write!(file, + " CFBundleURLTypes\n \ + \n \ + \n \ + CFBundleURLName\n \ + {}\n \ + CFBundleTypeRole\n \ + Viewer\n \ + CFBundleURLSchemes\n \ + \n", + settings.bundle_name())?; + for scheme in settings.osx_url_schemes() { + write!(file, " {}\n", scheme)?; + } + write!(file, + " \n \ + \n \ + \n")?; + } write!(file, " CFBundleVersion\n {}\n", build_number)?; diff --git a/src/bundle/settings.rs b/src/bundle/settings.rs index 2e9741e..db42125 100644 --- a/src/bundle/settings.rs +++ b/src/bundle/settings.rs @@ -79,6 +79,7 @@ struct BundleSettings { deb_depends: Option>, osx_frameworks: Option>, osx_minimum_system_version: Option, + osx_url_schemes: Option>, // Bundles for other binaries/examples: bin: Option>, example: Option>, @@ -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>,