feat(builder): enable OSX sidecar from finder (#379)

This commit is contained in:
nothingismagick 2020-02-04 01:38:43 +01:00 committed by GitHub
parent aed07399d7
commit 29e2f16520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View File

@ -29,6 +29,7 @@ use std::fs::{self, File};
use std::io::prelude::*; use std::io::prelude::*;
use std::io::{self, BufWriter}; use std::io::{self, BufWriter};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> { pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let app_bundle_name = format!("{}.app", settings.bundle_name()); let app_bundle_name = format!("{}.app", settings.bundle_name());
@ -70,6 +71,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
copy_binary_to_bundle(&bundle_directory, settings) copy_binary_to_bundle(&bundle_directory, settings)
.chain_err(|| format!("Failed to copy binary from {:?}", settings.binary_path()))?; .chain_err(|| format!("Failed to copy binary from {:?}", settings.binary_path()))?;
create_path_hook(&bundle_directory, settings)
.chain_err(|| "Failed to create _boot wrapper")?;
Ok(vec![app_bundle_path]) Ok(vec![app_bundle_path])
} }
@ -81,6 +87,42 @@ fn copy_binary_to_bundle(bundle_directory: &Path, settings: &Settings) -> crate:
) )
} }
fn create_path_hook(
bundle_dir: &Path,
settings: &Settings,
) -> crate::Result<()> {
let file = &mut common::create_file(&bundle_dir.join("MacOS/__bootstrapper"))?;
// Create a shell script to bootstrap the $PATH for Tauri, so environments like node are available.
write!(
file,
"#!/usr/bin/env sh
# This bootstraps the $PATH for Tauri, so environments are available.
. ~/.bash_profile
if pidof -x \"__bootstrapper\" >/dev/null; then
exit 0
else
exec \"`dirname \\\"$0\\\"`/{}\" $@ & disown
fi
exit 0",
settings.bundle_name()
)?;
file.flush()?;
// We have to make the __bootstrapper executable, or the bundle will not work
Command::new("chmod")
.arg("+x")
.arg("__bootstrapper")
.current_dir(&bundle_dir.join("MacOS/"))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to chmod script");
Ok(())
}
fn create_info_plist( fn create_info_plist(
bundle_dir: &Path, bundle_dir: &Path,
bundle_icon_file: Option<PathBuf>, bundle_icon_file: Option<PathBuf>,
@ -108,8 +150,9 @@ fn create_info_plist(
)?; )?;
write!( write!(
file, file,
" <key>CFBundleExecutable</key>\n <string>{}</string>\n", // Here we should only use this technique if they have specified
settings.binary_name() // that they want to use the resources
" <key>CFBundleExecutable</key>\n <string>__bootstrapper</string>\n"
)?; )?;
if let Some(path) = bundle_icon_file { if let Some(path) = bundle_icon_file {
write!( write!(

View File

@ -24,6 +24,7 @@ fn main() {
.spawn() .spawn()
.expect("Failed to spawn packaged node") .expect("Failed to spawn packaged node")
.stdout.expect("Failed to get packaged node stdout"); .stdout.expect("Failed to get packaged node stdout");
let reader = std::io::BufReader::new(stdout); let reader = std::io::BufReader::new(stdout);
reader reader