Skip to content

Commit 387f0b9

Browse files
committed
Chore: Let's not overdo it on checking if the phpstorm binary exists and then enabling the IDE. We'll use the same pattern the author intended
1 parent 41d8bb3 commit 387f0b9

4 files changed

Lines changed: 20 additions & 130 deletions

File tree

src-tauri/src/shared/settings_core.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ use std::path::PathBuf;
33
use tokio::sync::Mutex;
44

55
use crate::codex::config as codex_config;
6-
use crate::types::OpenAppTarget;
7-
use crate::shared::workspaces_core::optional_open_app_targets_core;
86
use crate::storage::write_settings;
97
use crate::types::AppSettings;
108

11-
const OPTIONAL_OPEN_APP_TARGET_IDS: &[&str] = &["phpstorm"];
12-
139
fn normalize_personality(value: &str) -> Option<&'static str> {
1410
match value.trim() {
1511
"friendly" => Some("friendly"),
@@ -40,7 +36,6 @@ pub(crate) async fn get_app_settings_core(app_settings: &Mutex<AppSettings>) ->
4036
.unwrap_or("friendly")
4137
.to_string();
4238
}
43-
inject_optional_open_app_targets(&mut settings);
4439
settings
4540
}
4641

@@ -57,9 +52,7 @@ pub(crate) async fn update_app_settings_core(
5752
write_settings(settings_path, &settings)?;
5853
let mut current = app_settings.lock().await;
5954
*current = settings.clone();
60-
let mut response = settings;
61-
inject_optional_open_app_targets(&mut response);
62-
Ok(response)
55+
Ok(settings)
6356
}
6457

6558
pub(crate) fn get_codex_config_path_core() -> Result<String, String> {
@@ -71,50 +64,3 @@ pub(crate) fn get_codex_config_path_core() -> Result<String, String> {
7164
.ok_or_else(|| "Unable to resolve CODEX_HOME".to_string())
7265
})
7366
}
74-
75-
fn inject_optional_open_app_targets(settings: &mut AppSettings) {
76-
let optional_targets = optional_open_app_targets_core();
77-
let mut available_optional_targets_by_id = optional_targets
78-
.into_iter()
79-
.map(|target| (target.id.clone(), target))
80-
.collect::<std::collections::HashMap<String, OpenAppTarget>>();
81-
let mut existing_targets = std::mem::take(&mut settings.open_app_targets);
82-
existing_targets.retain(|target| {
83-
!OPTIONAL_OPEN_APP_TARGET_IDS.contains(&target.id.as_str())
84-
|| available_optional_targets_by_id.contains_key(&target.id)
85-
});
86-
87-
let mut merged_targets =
88-
Vec::with_capacity(existing_targets.len() + available_optional_targets_by_id.len());
89-
let mut inserted_optional = false;
90-
91-
for target in existing_targets {
92-
if OPTIONAL_OPEN_APP_TARGET_IDS.contains(&target.id.as_str()) {
93-
available_optional_targets_by_id.remove(&target.id);
94-
}
95-
if !inserted_optional && target.kind == "finder" {
96-
merged_targets.extend(available_optional_targets_by_id.into_values());
97-
available_optional_targets_by_id = std::collections::HashMap::new();
98-
inserted_optional = true;
99-
}
100-
merged_targets.push(target);
101-
}
102-
103-
if !inserted_optional {
104-
merged_targets.extend(available_optional_targets_by_id.into_values());
105-
}
106-
107-
settings.open_app_targets = merged_targets;
108-
109-
if !settings
110-
.open_app_targets
111-
.iter()
112-
.any(|target| target.id == settings.selected_open_app_id)
113-
{
114-
settings.selected_open_app_id = settings
115-
.open_app_targets
116-
.first()
117-
.map(|target| target.id.clone())
118-
.unwrap_or_default();
119-
}
120-
}

src-tauri/src/shared/workspaces_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) use git_orchestration::{apply_worktree_changes_core, run_git_command_
1515
pub(crate) use helpers::{is_workspace_path_dir_core, list_workspaces_core};
1616
pub(crate) use io::{
1717
get_open_app_icon_core, list_workspace_files_core, open_workspace_in_core,
18-
optional_open_app_targets_core, read_workspace_file_core,
18+
read_workspace_file_core,
1919
};
2020
pub(crate) use runtime_codex_args::{
2121
set_workspace_runtime_codex_args_core, WorkspaceRuntimeCodexArgsResult,

src-tauri/src/shared/workspaces_core/io.rs

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
use std::env;
32
use std::path::{Path, PathBuf};
43

@@ -107,76 +106,6 @@ fn normalize_app_identifier(app: &str) -> String {
107106
.join(" ")
108107
}
109108

110-
fn find_executable_in_path(program: &str) -> Option<PathBuf> {
111-
let trimmed = program.trim();
112-
if trimmed.is_empty() {
113-
return None;
114-
}
115-
116-
let path = PathBuf::from(trimmed);
117-
if path.is_file() {
118-
return Some(path);
119-
}
120-
121-
let path_var = env::var_os("PATH")?;
122-
for dir in env::split_paths(&path_var) {
123-
let candidate = dir.join(trimmed);
124-
if candidate.is_file() {
125-
return Some(candidate);
126-
}
127-
}
128-
129-
None
130-
}
131-
132-
#[cfg(target_os = "windows")]
133-
fn first_available_command(candidates: &[&str]) -> Option<String> {
134-
candidates
135-
.iter()
136-
.copied()
137-
.find(|candidate| resolve_windows_executable(candidate, None).is_some())
138-
.map(str::to_string)
139-
}
140-
141-
#[cfg(not(target_os = "windows"))]
142-
fn first_available_command(candidates: &[&str]) -> Option<String> {
143-
candidates
144-
.iter()
145-
.copied()
146-
.find(|candidate| find_executable_in_path(candidate).is_some())
147-
.map(str::to_string)
148-
}
149-
150-
#[cfg(target_os = "windows")]
151-
fn phpstorm_command_candidates() -> &'static [&'static str] {
152-
&["phpstorm64.exe", "phpstorm.bat", "phpstorm"]
153-
}
154-
155-
#[cfg(target_os = "macos")]
156-
fn phpstorm_command_candidates() -> &'static [&'static str] {
157-
&["phpstorm"]
158-
}
159-
160-
#[cfg(all(not(target_os = "windows"), not(target_os = "macos")))]
161-
fn phpstorm_command_candidates() -> &'static [&'static str] {
162-
&["phpstorm", "phpstorm.sh"]
163-
}
164-
165-
pub(crate) fn optional_open_app_targets_core() -> Vec<OpenAppTarget> {
166-
let Some(command) = first_available_command(phpstorm_command_candidates()) else {
167-
return Vec::new();
168-
};
169-
170-
vec![OpenAppTarget {
171-
id: "phpstorm".to_string(),
172-
label: "PHPStorm".to_string(),
173-
kind: "command".to_string(),
174-
app_name: None,
175-
command: Some(command),
176-
args: Vec::new(),
177-
}]
178-
}
179-
180109
fn build_launch_args(
181110
path: &str,
182111
args: &[String],
@@ -300,8 +229,7 @@ pub(crate) async fn open_workspace_in_core(
300229
if let (Some(strategy), Some(cli_program)) = (
301230
app_strategy,
302231
normalize_open_location(line, column)
303-
.and_then(|_| app_cli_command(trimmed))
304-
.and_then(find_executable_in_path),
232+
.and_then(|_| app_cli_command(trimmed)),
305233
) {
306234
let launch_args = build_launch_args(&path, &args, line, column, Some(strategy));
307235
let mut cmd = tokio_command(cli_program);

src-tauri/src/types.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,14 @@ fn default_open_app_targets() -> Vec<OpenAppTarget> {
10431043
command: None,
10441044
args: Vec::new(),
10451045
},
1046+
OpenAppTarget {
1047+
id: "phpstorm".to_string(),
1048+
label: "PHPStorm".to_string(),
1049+
kind: "command".to_string(),
1050+
app_name: None,
1051+
command: Some("phpstorm".to_string()),
1052+
args: Vec::new(),
1053+
},
10461054
OpenAppTarget {
10471055
id: "finder".to_string(),
10481056
label: "Finder".to_string(),
@@ -1101,6 +1109,14 @@ fn default_open_app_targets() -> Vec<OpenAppTarget> {
11011109
command: Some("antigravity".to_string()),
11021110
args: Vec::new(),
11031111
},
1112+
OpenAppTarget {
1113+
id: "phpstorm".to_string(),
1114+
label: "PHPStorm".to_string(),
1115+
kind: "command".to_string(),
1116+
app_name: None,
1117+
command: Some("phpstorm".to_string()),
1118+
args: Vec::new(),
1119+
},
11041120
OpenAppTarget {
11051121
id: "finder".to_string(),
11061122
label: file_manager_label.to_string(),
@@ -1364,7 +1380,7 @@ mod tests {
13641380
"vscode"
13651381
};
13661382
assert_eq!(settings.selected_open_app_id, expected_open_id);
1367-
assert_eq!(settings.open_app_targets.len(), 6);
1383+
assert_eq!(settings.open_app_targets.len(), 7);
13681384
assert_eq!(settings.open_app_targets[0].id, "vscode");
13691385
}
13701386

0 commit comments

Comments
 (0)