Skip to content

Commit 13986b5

Browse files
committed
Add recent items submenu to tray and improve image handling
1 parent 3e24267 commit 13986b5

2 files changed

Lines changed: 468 additions & 34 deletions

File tree

apps/desktop/src-tauri/src/screenshot_editor.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,31 @@ impl ScreenshotEditorInstances {
141141
let rgba_img: image::RgbaImage = rgb_img.convert();
142142
(rgba_img.into_raw(), width, height)
143143
} else {
144-
let img =
145-
image::open(&path).map_err(|e| format!("Failed to open image: {e}"))?;
144+
let image_path = if path.is_dir() {
145+
let original = path.join("original.png");
146+
if original.exists() {
147+
original
148+
} else {
149+
std::fs::read_dir(&path)
150+
.ok()
151+
.and_then(|dir| {
152+
dir.flatten()
153+
.find(|e| {
154+
e.path().extension().and_then(|s| s.to_str())
155+
== Some("png")
156+
})
157+
.map(|e| e.path())
158+
})
159+
.ok_or_else(|| {
160+
format!("No PNG file found in directory: {:?}", path)
161+
})?
162+
}
163+
} else {
164+
path.clone()
165+
};
166+
167+
let img = image::open(&image_path)
168+
.map_err(|e| format!("Failed to open image: {e}"))?;
146169
let (w, h) = img.dimensions();
147170

148171
if w > MAX_DIMENSION || h > MAX_DIMENSION {
@@ -157,15 +180,22 @@ impl ScreenshotEditorInstances {
157180
}
158181
};
159182

160-
// Try to load existing meta if in a .cap directory
161-
let (recording_meta, loaded_config) = if let Some(parent) = path.parent() {
183+
let cap_dir = if path.extension().and_then(|s| s.to_str()) == Some("cap") {
184+
Some(path.clone())
185+
} else if let Some(parent) = path.parent() {
162186
if parent.extension().and_then(|s| s.to_str()) == Some("cap") {
163-
let meta = RecordingMeta::load_for_project(parent).ok();
164-
let config = ProjectConfiguration::load(parent).ok();
165-
(meta, config)
187+
Some(parent.to_path_buf())
166188
} else {
167-
(None, None)
189+
None
168190
}
191+
} else {
192+
None
193+
};
194+
195+
let (recording_meta, loaded_config) = if let Some(cap_dir) = &cap_dir {
196+
let meta = RecordingMeta::load_for_project(cap_dir).ok();
197+
let config = ProjectConfiguration::load(cap_dir).ok();
198+
(meta, config)
169199
} else {
170200
(None, None)
171201
};

0 commit comments

Comments
 (0)