54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
//! DevKit Tauri 命令
|
|
//!
|
|
//! 仅在 `devkit` feature 启用时编译。
|
|
|
|
use tauri::State;
|
|
#[cfg(feature = "devkit")]
|
|
use tauri::AppHandle;
|
|
|
|
use crate::devkit::{DevKitConfig, DevKitState, DevKitStatusSnapshot, ExportProcessResult};
|
|
|
|
#[tauri::command]
|
|
pub fn devkit_status(state: State<'_, DevKitState>) -> DevKitStatusSnapshot {
|
|
state.status()
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn devkit_start(
|
|
app: AppHandle,
|
|
state: State<'_, DevKitState>,
|
|
port: Option<u16>,
|
|
) -> Result<DevKitStatusSnapshot, String> {
|
|
let target_port = port.unwrap_or(50051);
|
|
state.start(app, target_port).await?;
|
|
Ok(state.status())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn devkit_stop(state: State<'_, DevKitState>) -> Result<DevKitStatusSnapshot, String> {
|
|
state.stop().await?;
|
|
Ok(state.status())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn devkit_get_config(state: State<'_, DevKitState>) -> DevKitConfig {
|
|
state.get_config()
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn devkit_set_config(state: State<'_, DevKitState>, config: DevKitConfig) -> Result<DevKitConfig, String> {
|
|
state.set_config(config)?;
|
|
Ok(state.get_config())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn devkit_process_export(
|
|
state: State<'_, DevKitState>,
|
|
csv_path: String,
|
|
save_as_xlsx: Option<bool>,
|
|
) -> Result<ExportProcessResult, String> {
|
|
let config = state.get_config();
|
|
let use_xlsx = save_as_xlsx.unwrap_or(config.save_as_xlsx);
|
|
state.process_export(&csv_path, use_xlsx).await
|
|
}
|