Skip to content

Commit

Permalink
fix: Return empty project if json not found
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Oct 1, 2024
1 parent 342fb9e commit a172c4b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
40 changes: 23 additions & 17 deletions apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@ export default function Recordings() {
const fetchRecordings = createQuery(() => ({
queryKey: ["recordings"],
queryFn: async () => {
const result = await commands.listRecordings();
if (result.status === "ok") {
const recordings = await Promise.all(
result.data.map(async (file) => {
const [id, path, meta] = file;
const thumbnailPath = `${path}/screenshots/display.jpg`;
try {
const result = await commands.listRecordings();
if (result.status === "ok") {
const recordings = await Promise.all(
result.data.map(async (file) => {
const [id, path, meta] = file;
const thumbnailPath = `${path}/screenshots/display.jpg`;

return {
id,
path,
prettyName: meta.pretty_name,
isNew: false,
thumbnailPath,
};
})
);
return recordings;
} else {
return {
id,
path,
prettyName: meta.pretty_name,
isNew: false,
thumbnailPath,
};
})
);
return recordings;
} else {
console.error("Failed to list recordings:", result.error);
return [];
}
} catch (error) {
console.error("Error fetching recordings:", error);
return [];
}
},
Expand Down
17 changes: 16 additions & 1 deletion crates/project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ pub struct RecordingMeta {
impl RecordingMeta {
pub fn load_for_project(project_path: &PathBuf) -> Result<Self, String> {
let meta_path = project_path.join("recording-meta.json");
let meta = std::fs::read_to_string(meta_path).map_err(|e| e.to_string())?;
let meta = match std::fs::read_to_string(&meta_path) {
Ok(content) => content,
Err(_) => {
return Ok(Self {
project_path: project_path.clone(),
pretty_name: String::new(),
sharing: None,
display: Display {
path: PathBuf::new(),
},
camera: None,
audio: None,
segments: Vec::new(),
});
}
};
let mut meta: Self = serde_json::from_str(&meta).map_err(|e| e.to_string())?;
meta.project_path = project_path.clone();
Ok(meta)
Expand Down

1 comment on commit a172c4b

@vercel
Copy link

@vercel vercel bot commented on a172c4b Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.