Files
review-videos/src-tauri/src/lib.rs
Julian Freeman a55bf42263 prepare
2025-12-07 18:50:18 -04:00

44 lines
1.4 KiB
Rust

use std::path::Path;
use fs_extra::dir::CopyOptions;
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
fn copy_directory(template_path: String, target_path: String, new_folder_name: String) -> Result<String, String> {
let template = Path::new(&template_path);
let target_parent = Path::new(&target_path);
let destination = target_parent.join(&new_folder_name);
if !template.exists() {
return Err("Template directory does not exist".to_string());
}
if destination.exists() {
return Err(format!("Destination directory already exists: {:?}", destination));
}
// Create the destination directory first
std::fs::create_dir_all(&destination).map_err(|e| e.to_string())?;
let mut options = CopyOptions::new();
options.content_only = true;
fs_extra::dir::copy(template, &destination, &options)
.map_err(|e| e.to_string())?;
Ok(destination.to_string_lossy().to_string())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![greet, copy_directory])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}