generated from nhcarrigan/template
feat: surface memory file last-modified timestamps in MemoryBrowserPanel (#230)
Extends MemoryFileInfo with last_modified (Unix timestamp) populated via fs::metadata on native platforms, and displays a formatted date in the file list as secondary text.
This commit is contained in:
@@ -1464,6 +1464,7 @@ pub async fn close_application(app_handle: AppHandle) -> Result<(), String> {
|
||||
pub struct MemoryFileInfo {
|
||||
pub path: String,
|
||||
pub heading: Option<String>,
|
||||
pub last_modified: Option<String>, // Unix timestamp in seconds as a string
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@@ -1535,7 +1536,11 @@ async fn list_memory_files_via_wsl() -> Result<MemoryFilesResponse, String> {
|
||||
let mut files = Vec::new();
|
||||
for path in paths {
|
||||
let heading = read_wsl_file_first_heading(&path);
|
||||
files.push(MemoryFileInfo { path, heading });
|
||||
files.push(MemoryFileInfo {
|
||||
path,
|
||||
heading,
|
||||
last_modified: None,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(MemoryFilesResponse { files })
|
||||
@@ -1605,14 +1610,23 @@ async fn list_memory_files_native() -> Result<MemoryFilesResponse, String> {
|
||||
// Sort files alphabetically
|
||||
memory_paths.sort();
|
||||
|
||||
// Read first heading from each file
|
||||
// Read first heading and modification time from each file
|
||||
let files = memory_paths
|
||||
.into_iter()
|
||||
.map(|path| {
|
||||
let heading = fs::read_to_string(&path)
|
||||
.ok()
|
||||
.and_then(|content| extract_first_heading(&content));
|
||||
MemoryFileInfo { path, heading }
|
||||
let last_modified = fs::metadata(&path)
|
||||
.ok()
|
||||
.and_then(|m| m.modified().ok())
|
||||
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
||||
.map(|d| d.as_secs().to_string());
|
||||
MemoryFileInfo {
|
||||
path,
|
||||
heading,
|
||||
last_modified,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user