feat: scan local models, redesign sidebar and server panel UI
This commit is contained in:
1 parent
734d01a36e
commit
18d8b03074
5 files changed
+697
-252
No files matched your search
@@ -1,3 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::process::{Child, Command};
|
||||
use std::sync::Mutex;
|
||||
use tauri::{Manager, State};
|
||||
@@ -114,6 +115,51 @@ fn server_status(state: State<ServerState>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan a directory for .gguf model files.
|
||||
/// Returns a list of { name, path } objects.
|
||||
#[tauri::command]
|
||||
fn scan_models(dir: String) -> Result<Vec<ModelFile>, String> {
|
||||
let path = Path::new(&dir);
|
||||
if !path.exists() {
|
||||
return Err(format!("Directory not found: {dir}"));
|
||||
}
|
||||
if !path.is_dir() {
|
||||
return Err(format!("Not a directory: {dir}"));
|
||||
}
|
||||
|
||||
let entries = std::fs::read_dir(path).map_err(|e| e.to_string())?;
|
||||
let mut models = Vec::new();
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let p = entry.path();
|
||||
if p.is_file() {
|
||||
if let Some(ext) = p.extension() {
|
||||
if ext.eq_ignore_ascii_case("gguf") {
|
||||
let name = p
|
||||
.file_name()
|
||||
.unwrap_or_default()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
let full_path = p.to_string_lossy().to_string();
|
||||
models.push(ModelFile {
|
||||
name,
|
||||
path: full_path,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
models.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
Ok(models)
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
pub struct ModelFile {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
@@ -121,6 +167,7 @@ pub fn run() {
|
||||
.manage(ServerState(Mutex::new(None)))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
query_gpu,
|
||||
scan_models,
|
||||
start_server,
|
||||
stop_server,
|
||||
server_status
|
||||
|
||||
Reference in new issue
Block a user