From 1347bea868a000a250a4a873e53ca011e9e75be5 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Mon, 2 Mar 2026 14:24:30 +0530 Subject: [PATCH] refactor: use different opener command for links --- src-tauri/src/lib.rs | 24 ++++++++- .../pages/settings/extensionSettings.tsx | 53 +++++++++++++++---- 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4441e34..e2c6971 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -358,7 +358,7 @@ async fn open_file_with_app( ) -> Result<(), String> { if let Some(name) = &app_name { if name == "explorer" { - println!("Revealing file: {} in explorer", file_path); + info!("Revealing file: {} in explorer", file_path); return app_handle .opener() .reveal_item_in_dir(file_path) @@ -381,6 +381,27 @@ async fn open_file_with_app( }) } +#[tauri::command] +async fn open_link_with_app( + app_handle: tauri::AppHandle, + url: String, + app_name: Option, +) -> Result<(), String> { + if let Some(name) = &app_name { + info!("Opening link: {} with app: {}", url, name); + } else { + info!("Opening link: {} with default app", url); + } + + app_handle + .opener() + .open_url(url, app_name) + .map_err(|e| { + error!("Failed to open link: {}", e); + e.to_string() + }) +} + #[tauri::command] async fn list_ongoing_downloads( state_mutex: State<'_, StdMutex>>, @@ -626,6 +647,7 @@ pub async fn run() { kill_all_process, fetch_image, open_file_with_app, + open_link_with_app, list_ongoing_downloads, pause_ongoing_downloads, send_to_extension, diff --git a/src/components/pages/settings/extensionSettings.tsx b/src/components/pages/settings/extensionSettings.tsx index afd08b5..731f6d1 100644 --- a/src/components/pages/settings/extensionSettings.tsx +++ b/src/components/pages/settings/extensionSettings.tsx @@ -15,6 +15,7 @@ import { invoke } from "@tauri-apps/api/core"; import { SlidingButton } from "@/components/custom/slidingButton"; import clsx from "clsx"; import { NumberInput } from "@/components/custom/numberInput"; +import { platform } from "@tauri-apps/plugin-os"; const websocketPortSchema = z.object({ port: z.coerce.number({ @@ -31,9 +32,9 @@ const websocketPortSchema = z.object({ }); function ExtInstallSettings() { - const openLink = async (url: string, app: string | undefined) => { + const openLink = async (url: string, app: string | null) => { try { - await invoke('open_file_with_app', { filePath: url, appName: app }).then(() => { + await invoke('open_link_with_app', { url: url, appName: app }).then(() => { toast.info("Opening link", { description: `Opening link with ${app ? app : 'default app'}.`, }) @@ -58,7 +59,11 @@ function ExtInstallSettings() { Get Now } - onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'chrome')} + onClick={async() => { + const isFlatpak = await invoke('is_flatpak'); + const currentPlatform = platform(); + openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : currentPlatform === "linux" ? 'google-chrome' : 'chrome'); + }} > @@ -75,7 +80,10 @@ function ExtInstallSettings() { Get Now } - onClick={() => openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', 'firefox')} + onClick={async() => { + const isFlatpak = await invoke('is_flatpak'); + openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', isFlatpak ? null : 'firefox'); + }} > @@ -87,13 +95,38 @@ function ExtInstallSettings() {
- - - - - + + + + +
-

* These links opens with coresponding browsers only. Make sure the browser is installed before clicking the link

+

* These links opens with coresponding browsers only (except on flatpak). Make sure the browser is installed before clicking the link

); }