Add modulo app stub auto-generation draft. #430

This commit is contained in:
Federico Terzi 2020-09-08 21:40:35 +02:00
parent 66f4d0964b
commit e94567b37b
3 changed files with 77 additions and 0 deletions

28
src/res/mac/modulo.plist Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>{{{modulo_path}}}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.federicoterzi.modulo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Modulo</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

38
src/ui/modulo/mac.rs Normal file
View File

@ -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<PathBuf, std::io::Error> {
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)
}

View File

@ -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<String>,
}
@ -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);
}