Skip to content

Commit

Permalink
create launchagents dir if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
danitt committed Sep 26, 2023
1 parent 6a96517 commit d000d51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "monmon"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
16 changes: 10 additions & 6 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::env;
use std::fs::create_dir_all;
use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -44,12 +45,15 @@ pub fn run(path_to_binary: &str) -> std::io::Result<()> {
SERVICE_NAME, path_to_binary, output_log, error_log, blacklisted_displays_str
);

// Ensure the LaunchAgents directory exists
create_dir_all(&get_plist_dir()).expect("Failed to create LaunchAgents directory");

// Write plist to file
let mut file = NamedTempFile::new()?;
file.write_all(plist_content.as_bytes())?;
let temp_file_path = file.path().to_str().unwrap();

// Move plist file to the correct location
// Move plist file to launch agents directory
Command::new("mv")
.args(&[temp_file_path, &get_plist_path()])
.output()
Expand All @@ -69,14 +73,14 @@ fn get_home_dir() -> String {
std::env::var("HOME").expect("Home directory not found")
}

fn get_plist_dir() -> String {
format!("{}/Library/LaunchAgents", get_home_dir())
}

fn get_plist_name() -> String {
format!("{}.plist", SERVICE_NAME)
}

pub fn get_plist_path() -> String {
format!(
"{}/Library/LaunchAgents/{}",
get_home_dir(),
get_plist_name()
)
format!("{}/{}", get_plist_dir(), get_plist_name())
}

0 comments on commit d000d51

Please sign in to comment.