Skip to content

Commit

Permalink
fix: reimplement path un/install for macos (#3255)
Browse files Browse the repository at this point in the history
Fixes #3254
  • Loading branch information
panekj committed May 10, 2024
1 parent c9f5f8f commit c604f51
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Update toolchain & add llvm-tools
run: |
rustup update
rustup update --no-self-update
rustup component add llvm-tools-preview
- name: Cache Rust dependencies
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:

- name: Update toolchain & add clippy
run: |
rustup update
rustup update --no-self-update
rustup component add clippy
- name: Install dependencies on Ubuntu
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: actions/checkout@v4

- name: Update rust
run: rustup update
run: rustup update --no-self-update

- name: Fetch dependencies
run: cargo fetch --locked
Expand Down
4 changes: 4 additions & 0 deletions lapce-app/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ pub enum InternalCommand {
left_path: PathBuf,
right_path: PathBuf,
},
ExecuteProcess {
program: String,
arguments: Vec<String>,
},
}

#[derive(Clone)]
Expand Down
38 changes: 35 additions & 3 deletions lapce-app/src/window_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use lapce_rpc::{
};
use lsp_types::{Diagnostic, ProgressParams, ProgressToken, ShowMessageParams};
use serde_json::Value;
use tracing::{debug, error};
use tracing::{debug, error, event, Level};

use crate::{
about::AboutData,
Expand Down Expand Up @@ -1273,9 +1273,23 @@ impl WindowTabData {

// ==== Movement ====
#[cfg(target_os = "macos")]
InstallToPATH => {}
InstallToPATH => {
self.common.internal_command.send(
InternalCommand::ExecuteProcess {
program: String::from("osascript"),
arguments: vec![String::from("-e"), format!(r#"do shell script "ln -sf '{}' /usr/local/bin/lapce" with administrator privileges"#, std::env::args().next().unwrap())],
}
)
}
#[cfg(target_os = "macos")]
UninstallFromPATH => {}
UninstallFromPATH => {
self.common.internal_command.send(
InternalCommand::ExecuteProcess {
program: String::from("osascript"),
arguments: vec![String::from("-e"), String::from(r#"do shell script "rm /usr/local/bin/lapce" with administrator privileges"#)],
}
)
}
JumpLocationForward => {
self.main_split.jump_location_forward(false);
}
Expand Down Expand Up @@ -1695,6 +1709,24 @@ impl WindowTabData {
left_path,
right_path,
} => self.main_split.open_diff_files(left_path, right_path),
InternalCommand::ExecuteProcess { program, arguments } => {
let mut cmd = match std::process::Command::new(program)
.args(arguments)
.spawn()
{
Ok(v) => v,
Err(e) => {
return event!(Level::ERROR, "Failed to spawn process: {e}")
}
};

match cmd.wait() {
Ok(v) => event!(Level::TRACE, "Process exited with status {v}"),
Err(e) => {
event!(Level::ERROR, "Proces exited with an error: {e}")
}
};
}
}
}

Expand Down

0 comments on commit c604f51

Please sign in to comment.