diff --git a/src/res/mac/modulo.plist b/src/res/mac/modulo.plist new file mode 100644 index 0000000..dd37ecd --- /dev/null +++ b/src/res/mac/modulo.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + {{{modulo_path}}} + CFBundleIconFile + + CFBundleIdentifier + com.federicoterzi.modulo + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Modulo + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/src/ui/modulo/mac.rs b/src/ui/modulo/mac.rs new file mode 100644 index 0000000..1fc150b --- /dev/null +++ b/src/ui/modulo/mac.rs @@ -0,0 +1,38 @@ +use log::info; +use std::os::unix::fs::symlink; + +const MODULO_APP_BUNDLE_NAME: &str = "Modulo.app"; +const MODULO_APP_BUNDLE_PLIST_CONTENT: &'static str = include_str!("../../res/mac/modulo.plist"); + +pub fn generate_modulo_app_bundle(modulo_path: &str) -> Result { + let data_dir = crate::context::get_data_dir(); + + let modulo_app_dir = data_dir.join(MODULO_APP_BUNDLE_NAME); + + // Remove previous bundle if present + if modulo_app_dir.exists() { + std::fs::remove_dir_all(&modulo_app_dir)?; + } + + // Recreate the App bundle stub + std::fs::create_dir(&modulo_app_dir)?; + + let contents_dir = modulo_app_dir.join("Contents"); + std::fs::create_dir(&contents_dir)?; + + let macos_dir = contents_dir.join("MacOS"); + std::fs::create_dir(&macos_dir)?; + + // Generate the Plist file + let plist_content = MODULO_APP_BUNDLE_PLIST_CONTENT.replace("{{{modulo_path}}}", modulo_path); + let plist_file = contents_dir.join("Info.plist"); + std::fs::write(plist_file, plist_content)?; + + // Generate the symbolic link to the modulo binary + let target_link = macos_dir.join("modulo"); + symlink(modulo_path, &target_link)?; + + info!("Created Modulo APP stub at: {:?}", &target_link); + + Ok(target_link) +} \ No newline at end of file diff --git a/src/ui/modulo/mod.rs b/src/ui/modulo/mod.rs index 1a19d2d..279f00d 100644 --- a/src/ui/modulo/mod.rs +++ b/src/ui/modulo/mod.rs @@ -3,6 +3,9 @@ use log::{error, info}; use std::io::{Error, Write}; use std::process::{Child, Command, Output}; +#[cfg(target_os = "macos")] +mod mac; + pub struct ModuloManager { modulo_path: Option, } @@ -41,6 +44,14 @@ impl ModuloManager { } } + // TODO: explain why + #[cfg(target_os = "macos")] + { + modulo_path = generate_modulo_app_bundle(&modulo_path).expect("unable to generate modulo app stub") + .to_string_lossy().to_string(); + } + + if let Some(ref modulo_path) = modulo_path { info!("Using modulo at {:?}", modulo_path); }