diff --git a/src-tauri/src/controller_binaries.rs b/src-tauri/src/controller_binaries.rs index 93934085..a2754715 100644 --- a/src-tauri/src/controller_binaries.rs +++ b/src-tauri/src/controller_binaries.rs @@ -5,7 +5,9 @@ use crate::{ download::Downloader, err, errors::{Context, Result}, - logerr, Service, SharedState, + logerr, + swarm::{create_environment, Config}, + Service, SharedState, }; use std::path::PathBuf; @@ -58,6 +60,7 @@ pub async fn download_service( #[tauri::command(async)] pub async fn start_service( + handle: tauri::AppHandle, service_id: String, state: State<'_, Arc>, app_handle: AppHandle, @@ -97,6 +100,11 @@ pub async fn start_service( ) })? .as_str(); + let is_petals_model = services_guard + .get(&service_id) + .with_context(|| format!("service_id {} doesn't exist in registry", service_id))? + .petals + .unwrap_or_default(); log::info!("serve_command: {}", serve_command); let serve_command_vec: Vec<&str> = serve_command.split_whitespace().collect(); @@ -123,9 +131,20 @@ pub async fn start_service( }) .collect(); log::info!("args: {:?}", args); + + let config = Config::new(); + let mut env_vars = HashMap::new(); + env_vars.insert("PREM_APPDIR".to_string(), config.app_data_dir); + env_vars.insert("PREM_PYTHON".to_string(), config.python); + + if is_petals_model { + create_environment(handle); + } + let child = Command::new(&binary_path) .current_dir(service_dir) .args(args) + .envs(env_vars) .stdout(std::process::Stdio::from( log_file .try_clone() diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f5f8f4c7..cf451d40 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -54,6 +54,7 @@ pub struct Service { running_port: Option, #[serde(rename = "serviceType")] service_type: Option, + petals: Option, version: Option, #[serde(rename = "weightsDirectoryUrl")] weights_directory_url: Option, diff --git a/src-tauri/src/swarm.rs b/src-tauri/src/swarm.rs index 8f08e459..9cb1b184 100644 --- a/src-tauri/src/swarm.rs +++ b/src-tauri/src/swarm.rs @@ -25,13 +25,13 @@ pub fn is_swarm_supported() -> bool { } } -struct Config { - app_data_dir: String, - python: String, +pub struct Config { + pub app_data_dir: String, + pub python: String, } impl Config { - fn new() -> Self { + pub fn new() -> Self { let mut app_data_dir = tauri::api::path::home_dir().expect("🙈 Failed to get app data directory"); app_data_dir.push(".config/prem");