Compare commits
1 Commits
v0.1.74
...
v0.1.75-ma
| Author | SHA1 | Date | |
|---|---|---|---|
| 1aced2d860 |
@@ -1,10 +1,20 @@
|
|||||||
use tauri::State;
|
use tauri::{Emitter, State};
|
||||||
|
|
||||||
use crate::docker;
|
use crate::docker;
|
||||||
use crate::models::{container_config, AuthMode, Project, ProjectPath, ProjectStatus};
|
use crate::models::{container_config, AuthMode, Project, ProjectPath, ProjectStatus};
|
||||||
use crate::storage::secure;
|
use crate::storage::secure;
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
|
fn emit_progress(app_handle: &tauri::AppHandle, project_id: &str, message: &str) {
|
||||||
|
let _ = app_handle.emit(
|
||||||
|
"container-progress",
|
||||||
|
serde_json::json!({
|
||||||
|
"project_id": project_id,
|
||||||
|
"message": message,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Extract secret fields from a project and store them in the OS keychain.
|
/// Extract secret fields from a project and store them in the OS keychain.
|
||||||
fn store_secrets_for_project(project: &Project) -> Result<(), String> {
|
fn store_secrets_for_project(project: &Project) -> Result<(), String> {
|
||||||
if let Some(ref token) = project.git_token {
|
if let Some(ref token) = project.git_token {
|
||||||
@@ -116,6 +126,7 @@ pub async fn update_project(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn start_project_container(
|
pub async fn start_project_container(
|
||||||
project_id: String,
|
project_id: String,
|
||||||
|
app_handle: tauri::AppHandle,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<Project, String> {
|
) -> Result<Project, String> {
|
||||||
let mut project = state
|
let mut project = state
|
||||||
@@ -147,6 +158,7 @@ pub async fn start_project_container(
|
|||||||
// Wrap container operations so that any failure resets status to Stopped.
|
// Wrap container operations so that any failure resets status to Stopped.
|
||||||
let result: Result<String, String> = async {
|
let result: Result<String, String> = async {
|
||||||
// Ensure image exists
|
// Ensure image exists
|
||||||
|
emit_progress(&app_handle, &project_id, "Checking image...");
|
||||||
if !docker::image_exists(&image_name).await? {
|
if !docker::image_exists(&image_name).await? {
|
||||||
return Err(format!("Docker image '{}' not found. Please pull or build the image first.", image_name));
|
return Err(format!("Docker image '{}' not found. Please pull or build the image first.", image_name));
|
||||||
}
|
}
|
||||||
@@ -173,9 +185,11 @@ pub async fn start_project_container(
|
|||||||
if needs_recreate {
|
if needs_recreate {
|
||||||
log::info!("Container config changed for project {} — committing snapshot and recreating", project.id);
|
log::info!("Container config changed for project {} — committing snapshot and recreating", project.id);
|
||||||
// Snapshot the filesystem before destroying
|
// Snapshot the filesystem before destroying
|
||||||
|
emit_progress(&app_handle, &project_id, "Saving container state...");
|
||||||
if let Err(e) = docker::commit_container_snapshot(&existing_id, &project).await {
|
if let Err(e) = docker::commit_container_snapshot(&existing_id, &project).await {
|
||||||
log::warn!("Failed to snapshot container before recreation: {}", e);
|
log::warn!("Failed to snapshot container before recreation: {}", e);
|
||||||
}
|
}
|
||||||
|
emit_progress(&app_handle, &project_id, "Recreating container...");
|
||||||
let _ = docker::stop_container(&existing_id).await;
|
let _ = docker::stop_container(&existing_id).await;
|
||||||
docker::remove_container(&existing_id).await?;
|
docker::remove_container(&existing_id).await?;
|
||||||
|
|
||||||
@@ -197,9 +211,11 @@ pub async fn start_project_container(
|
|||||||
&settings.global_custom_env_vars,
|
&settings.global_custom_env_vars,
|
||||||
settings.timezone.as_deref(),
|
settings.timezone.as_deref(),
|
||||||
).await?;
|
).await?;
|
||||||
|
emit_progress(&app_handle, &project_id, "Starting container...");
|
||||||
docker::start_container(&new_id).await?;
|
docker::start_container(&new_id).await?;
|
||||||
new_id
|
new_id
|
||||||
} else {
|
} else {
|
||||||
|
emit_progress(&app_handle, &project_id, "Starting container...");
|
||||||
docker::start_container(&existing_id).await?;
|
docker::start_container(&existing_id).await?;
|
||||||
existing_id
|
existing_id
|
||||||
}
|
}
|
||||||
@@ -215,6 +231,7 @@ pub async fn start_project_container(
|
|||||||
image_name.clone()
|
image_name.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emit_progress(&app_handle, &project_id, "Creating container...");
|
||||||
let new_id = docker::create_container(
|
let new_id = docker::create_container(
|
||||||
&project,
|
&project,
|
||||||
&docker_socket,
|
&docker_socket,
|
||||||
@@ -225,6 +242,7 @@ pub async fn start_project_container(
|
|||||||
&settings.global_custom_env_vars,
|
&settings.global_custom_env_vars,
|
||||||
settings.timezone.as_deref(),
|
settings.timezone.as_deref(),
|
||||||
).await?;
|
).await?;
|
||||||
|
emit_progress(&app_handle, &project_id, "Starting container...");
|
||||||
docker::start_container(&new_id).await?;
|
docker::start_container(&new_id).await?;
|
||||||
new_id
|
new_id
|
||||||
};
|
};
|
||||||
@@ -252,6 +270,7 @@ pub async fn start_project_container(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn stop_project_container(
|
pub async fn stop_project_container(
|
||||||
project_id: String,
|
project_id: String,
|
||||||
|
app_handle: tauri::AppHandle,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let project = state
|
let project = state
|
||||||
@@ -263,6 +282,7 @@ pub async fn stop_project_container(
|
|||||||
|
|
||||||
if let Some(ref container_id) = project.container_id {
|
if let Some(ref container_id) = project.container_id {
|
||||||
// Close exec sessions for this project
|
// Close exec sessions for this project
|
||||||
|
emit_progress(&app_handle, &project_id, "Stopping container...");
|
||||||
state.exec_manager.close_sessions_for_container(container_id).await;
|
state.exec_manager.close_sessions_for_container(container_id).await;
|
||||||
|
|
||||||
if let Err(e) = docker::stop_container(container_id).await {
|
if let Err(e) = docker::stop_container(container_id).await {
|
||||||
@@ -277,6 +297,7 @@ pub async fn stop_project_container(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn rebuild_project_container(
|
pub async fn rebuild_project_container(
|
||||||
project_id: String,
|
project_id: String,
|
||||||
|
app_handle: tauri::AppHandle,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<Project, String> {
|
) -> Result<Project, String> {
|
||||||
let project = state
|
let project = state
|
||||||
@@ -301,7 +322,7 @@ pub async fn rebuild_project_container(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start fresh
|
// Start fresh
|
||||||
start_project_container(project_id, state).await
|
start_project_container(project_id, app_handle, state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_docker_socket() -> String {
|
fn default_docker_socket() -> String {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { open } from "@tauri-apps/plugin-dialog";
|
import { open } from "@tauri-apps/plugin-dialog";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import type { Project, ProjectPath, AuthMode, BedrockConfig, BedrockAuthMethod } from "../../lib/types";
|
import type { Project, ProjectPath, AuthMode, BedrockConfig, BedrockAuthMethod } from "../../lib/types";
|
||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import { useTerminal } from "../../hooks/useTerminal";
|
import { useTerminal } from "../../hooks/useTerminal";
|
||||||
@@ -23,6 +24,7 @@ export default function ProjectCard({ project }: Props) {
|
|||||||
const [showEnvVarsModal, setShowEnvVarsModal] = useState(false);
|
const [showEnvVarsModal, setShowEnvVarsModal] = useState(false);
|
||||||
const [showPortMappingsModal, setShowPortMappingsModal] = useState(false);
|
const [showPortMappingsModal, setShowPortMappingsModal] = useState(false);
|
||||||
const [showClaudeInstructionsModal, setShowClaudeInstructionsModal] = useState(false);
|
const [showClaudeInstructionsModal, setShowClaudeInstructionsModal] = useState(false);
|
||||||
|
const [progressMsg, setProgressMsg] = useState<string | null>(null);
|
||||||
const isSelected = selectedProjectId === project.id;
|
const isSelected = selectedProjectId === project.id;
|
||||||
const isStopped = project.status === "stopped" || project.status === "error";
|
const isStopped = project.status === "stopped" || project.status === "error";
|
||||||
|
|
||||||
@@ -64,6 +66,26 @@ export default function ProjectCard({ project }: Props) {
|
|||||||
setBedrockModelId(project.bedrock_config?.model_id ?? "");
|
setBedrockModelId(project.bedrock_config?.model_id ?? "");
|
||||||
}, [project]);
|
}, [project]);
|
||||||
|
|
||||||
|
// Listen for container progress events
|
||||||
|
useEffect(() => {
|
||||||
|
const unlisten = listen<{ project_id: string; message: string }>(
|
||||||
|
"container-progress",
|
||||||
|
(event) => {
|
||||||
|
if (event.payload.project_id === project.id) {
|
||||||
|
setProgressMsg(event.payload.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return () => { unlisten.then((f) => f()); };
|
||||||
|
}, [project.id]);
|
||||||
|
|
||||||
|
// Clear progress when status settles
|
||||||
|
useEffect(() => {
|
||||||
|
if (project.status === "running" || project.status === "stopped" || project.status === "error") {
|
||||||
|
setProgressMsg(null);
|
||||||
|
}
|
||||||
|
}, [project.status]);
|
||||||
|
|
||||||
const handleStart = async () => {
|
const handleStart = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -317,7 +339,7 @@ export default function ProjectCard({ project }: Props) {
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<span className="text-xs text-[var(--text-secondary)]">
|
<span className="text-xs text-[var(--text-secondary)]">
|
||||||
{project.status}...
|
{progressMsg ?? `${project.status}...`}
|
||||||
</span>
|
</span>
|
||||||
<ActionButton onClick={handleStop} disabled={loading} label="Force Stop" danger />
|
<ActionButton onClick={handleStop} disabled={loading} label="Force Stop" danger />
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user