Refactor action handling to use backend communication and update process command usage
This commit is contained in:
@@ -274,29 +274,14 @@ fn run_backend(app: &AppHandle, backend: &Backend, input: &str) -> Result<Vec<u8
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn run_python_action(action: String, payload: Value) -> Result<Value, String> {
|
fn run_python_action(app: AppHandle, action: String, payload: Value) -> Result<Value, String> {
|
||||||
match action.as_str() {
|
|
||||||
"list_sessions" => {
|
|
||||||
return serde_json::to_value(list_sessions_fast()?).map_err(|err| err.to_string());
|
|
||||||
}
|
|
||||||
"load_session" => {
|
|
||||||
let title = payload.get("title").and_then(Value::as_str).unwrap_or("");
|
|
||||||
return load_session_fast(title);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
let script = repo_root().join("concept_api.py");
|
|
||||||
if !script.exists() {
|
|
||||||
return Err("concept_api.py not found".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
let req = serde_json::json!({
|
let req = serde_json::json!({
|
||||||
"action": action,
|
"action": action,
|
||||||
"payload": payload,
|
"payload": payload,
|
||||||
});
|
});
|
||||||
let input = serde_json::to_string(&req).map_err(|e| e.to_string())?;
|
let input = serde_json::to_string(&req).map_err(|e| e.to_string())?;
|
||||||
let stdout = run_python(script.to_string_lossy().as_ref(), &input)?;
|
let backend = backend(&app)?;
|
||||||
|
let stdout = run_backend(&app, &backend, &input)?;
|
||||||
let resp: Value = serde_json::from_slice(&stdout).map_err(|e| e.to_string())?;
|
let resp: Value = serde_json::from_slice(&stdout).map_err(|e| e.to_string())?;
|
||||||
if resp.get("ok") == Some(&Value::Bool(true)) {
|
if resp.get("ok") == Some(&Value::Bool(true)) {
|
||||||
Ok(resp.get("data").cloned().unwrap_or(Value::Null))
|
Ok(resp.get("data").cloned().unwrap_or(Value::Null))
|
||||||
@@ -317,15 +302,15 @@ fn open_path(path: String) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut command = if cfg!(target_os = "macos") {
|
let mut command = if cfg!(target_os = "macos") {
|
||||||
let mut command = Command::new("open");
|
let mut command = ProcessCommand::new("open");
|
||||||
command.arg(&path);
|
command.arg(&path);
|
||||||
command
|
command
|
||||||
} else if cfg!(target_os = "windows") {
|
} else if cfg!(target_os = "windows") {
|
||||||
let mut command = Command::new("cmd");
|
let mut command = ProcessCommand::new("cmd");
|
||||||
command.arg("/C").arg("start").arg("").arg(&path);
|
command.arg("/C").arg("start").arg("").arg(&path);
|
||||||
command
|
command
|
||||||
} else {
|
} else {
|
||||||
let mut command = Command::new("xdg-open");
|
let mut command = ProcessCommand::new("xdg-open");
|
||||||
command.arg(&path);
|
command.arg(&path);
|
||||||
command
|
command
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user