Skip to content

Commit

Permalink
Merge pull request #3 from leo-drive/bugfix/calibration-tool+build-bu…
Browse files Browse the repository at this point in the history
…ttons

Bugfix/calibration-tool+build-buttons
  • Loading branch information
KhalilSelyan authored Nov 28, 2023
2 parents a74329c + 8c6728c commit a62ed83
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
42 changes: 40 additions & 2 deletions src-tauri/src/build_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,55 @@ pub async fn update_autoware_workspace(path: String) -> Result<String, String> {
}

#[tauri::command]
pub async fn get_and_build_calibration_tools(path: String) -> Result<(), String> {
pub async fn get_and_build_calibration_tools(
path: String,
window: tauri::Window<tauri::Wry>,
) -> Result<String, String> {
let cloned_path = path.clone();
let path = Path::new(&cloned_path);
// if the directory is empty then we clone the repositories
let mut output = std::process::Command::new("bash")
.current_dir(path)
.arg("-c")
.arg("wget https://raw.githubusercontent.com/tier4/CalibrationTools/tier4/universe/calibration_tools.repos && vcs import src < calibration_tools.repos")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to spawn child process");

let stdout = BufReader::new(output.stdout.take().expect("Failed to capture stdout"));
let stderr = BufReader::new(output.stderr.take().expect("Failed to capture stderr"));

// we send the output to the frontend
let window1 = window.clone();
std::thread::spawn(move || {
for line in stdout.lines() {
match line {
Ok(line) => {
if let Err(e) = window1.emit("build_log", line) {
eprintln!("Failed to emit build_log: {}", e);
}
}
Err(e) => eprintln!("Failed to read line from stdout: {}", e),
}
}
});

let window2 = window.clone();

std::thread::spawn(move || {
for line in stderr.lines() {
match line {
Ok(line) => {
if let Err(e) = window2.emit("build_log", line) {
eprintln!("Failed to emit build_log: {}", e);
}
}
Err(e) => eprintln!("Failed to read line from stderr: {}", e),
}
}
});

let status = output.wait().expect("Failed to wait on child process");
if status.success() {
println!("Cloning Successful");
Expand Down Expand Up @@ -491,5 +529,5 @@ pub async fn get_and_build_calibration_tools(path: String) -> Result<(), String>
return Err(String::from_utf8_lossy(&output.stderr).to_string());
}

Ok(())
Ok("Cloning and installing Successful".to_string())
}
16 changes: 16 additions & 0 deletions src/components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { AboutDialog } from "./about-dialog";
import { Button } from "./ui/button";
import { Dialog, DialogContent, DialogTrigger } from "./ui/dialog";
import { toast } from "./ui/use-toast";

export function Menu() {
const closeWindow = useCallback(async () => {
Expand Down Expand Up @@ -69,6 +70,10 @@ export function Menu() {
setBuildLogs([]);

setUpdatingWorkspace(false);
toast({
title: "Workspace Updated",
description: "Workspace has been updated successfully",
});
}}
variant="ghost"
>
Expand All @@ -95,7 +100,18 @@ export function Menu() {

if (res) {
console.log("Calibration tools added successfully");
toast({
title: "Workspace Updated",
description:
"Workspace has been updated successfully with calibration tools",
});
} else {
toast({
title: "Failed to add calibration tools",
description:
"Failed to add calibration tools to the workspace. Please check the logs",
variant: "destructive",
});
console.log("Failed to add calibration tools");
}
}}
Expand Down
6 changes: 2 additions & 4 deletions src/components/rightPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,8 @@ const RightPane = () => {
(buildLogs.length === 1 &&
!buildLogs.some((log) => log.includes("Build logs cleared"))) ||
(buildLogs.length > 1 &&
!buildLogs.some(
(log) =>
log.includes("Build Failed") || log.includes("Build Finished")
)) ||
buildLogs[0].includes("Build Started") &&
!buildLogs.some((log) => log.includes("Summary"))) ||
packages.every((packageItem) => !packageItem.status) ||
buildType.value === ""
}
Expand Down

0 comments on commit a62ed83

Please sign in to comment.