Skip to content

Commit 194e71c

Browse files
Fix: Open Original File button not working in Image Details panel #688
1 parent c37d8df commit 194e71c

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

frontend/src-tauri/src/main.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ mod services;
55

66
use tauri::path::BaseDirectory;
77
use tauri::Manager;
8+
9+
// Correct Tauri v2 opener command
10+
#[tauri::command]
11+
async fn open_original_file(path: String) -> Result<(), String> {
12+
println!("Tauri received path: {}", path);
13+
14+
match tauri_plugin_opener::open_path(&path, None::<String>) {
15+
Ok(_) => {
16+
println!("File opened successfully");
17+
Ok(())
18+
}
19+
Err(e) => {
20+
eprintln!("Failed to open file: {}", e);
21+
Err(e.to_string())
22+
}
23+
}
24+
}
25+
826

927
fn main() {
1028
tauri::Builder::default()
@@ -22,7 +40,10 @@ fn main() {
2240
println!("Resource path: {:?}", resource_path);
2341
Ok(())
2442
})
25-
.invoke_handler(tauri::generate_handler![services::get_server_path,])
43+
.invoke_handler(tauri::generate_handler![
44+
services::get_server_path,
45+
open_original_file, // ⭐ Register command
46+
])
2647
.run(tauri::generate_context!())
2748
.expect("error while running tauri application");
2849
}

frontend/src/components/Media/MediaInfoPanel.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { open } from '@tauri-apps/plugin-shell';
2+
import { invoke } from '@tauri-apps/api/core'; // Correct Tauri v2 import
3+
34
import {
45
X,
56
ImageIcon as ImageLucide,
@@ -42,7 +43,6 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
4243

4344
const getImageName = () => {
4445
if (!currentImage) return 'Image';
45-
// Handle both Unix (/) and Windows (\) path separators
4646
return currentImage.path?.split(/[/\\]/).pop() || 'Image';
4747
};
4848

@@ -51,7 +51,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
5151
const { latitude, longitude } = currentImage.metadata;
5252
const url = `https://maps.google.com/?q=${latitude},${longitude}`;
5353
try {
54-
await open(url);
54+
await invoke('open_original_file', { path: url });
5555
} catch (error) {
5656
console.error('Failed to open map URL:', error);
5757
}
@@ -74,6 +74,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
7474
</div>
7575

7676
<div className="space-y-4 text-sm">
77+
{/* Name */}
7778
<div className="flex items-start gap-3">
7879
<div className="rounded-lg bg-white/10 p-2">
7980
<ImageLucide className="h-5 w-5 text-blue-400" />
@@ -89,6 +90,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
8990
</div>
9091
</div>
9192

93+
{/* Date */}
9294
<div className="flex items-start gap-3">
9395
<div className="rounded-lg bg-white/10 p-2">
9496
<Calendar className="h-5 w-5 text-emerald-400" />
@@ -99,6 +101,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
99101
</div>
100102
</div>
101103

104+
{/* Location */}
102105
<div className="flex items-start gap-3">
103106
<div className="rounded-lg bg-white/10 p-2">
104107
<MapPin className="h-5 w-5 text-red-400" />
@@ -122,6 +125,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
122125
</div>
123126
</div>
124127

128+
{/* Tags */}
125129
<div className="flex items-start gap-3">
126130
<div className="rounded-lg bg-white/10 p-2">
127131
<Tag className="h-5 w-5 text-purple-400" />
@@ -145,6 +149,7 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
145149
</div>
146150
</div>
147151

152+
{/* Position */}
148153
<div className="flex items-start gap-3">
149154
<div className="rounded-lg bg-white/10 p-2">
150155
<Info className="h-5 w-5 text-amber-400" />
@@ -157,13 +162,17 @@ export const MediaInfoPanel: React.FC<MediaInfoPanelProps> = ({
157162
</div>
158163
</div>
159164

165+
{/* OPEN ORIGINAL FILE — FIXED */}
160166
<div className="mt-4 border-t border-white/10 pt-3">
161167
<button
162168
className="w-full cursor-pointer rounded-lg bg-white/10 py-2 text-white transition-colors hover:bg-white/20"
163169
onClick={async () => {
164170
if (currentImage?.path) {
165171
try {
166-
await open(currentImage.path);
172+
console.log('Sending path to Tauri:', currentImage.path);
173+
await invoke('open_original_file', {
174+
path: currentImage.path,
175+
});
167176
} catch (error) {
168177
console.error('Failed to open file:', error);
169178
}

0 commit comments

Comments
 (0)