mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-22 06:55:51 +05:30
refactor: use different opener command for links
This commit is contained in:
@@ -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<String>,
|
||||
) -> 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<Pool<Sqlite>>>,
|
||||
@@ -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,
|
||||
|
||||
@@ -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<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() {
|
||||
<span>Get Now</span>
|
||||
</div>
|
||||
}
|
||||
onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'chrome')}
|
||||
onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
const currentPlatform = platform();
|
||||
openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : currentPlatform === "linux" ? 'google-chrome' : 'chrome');
|
||||
}}
|
||||
>
|
||||
<span className="font-semibold flex items-center gap-2">
|
||||
<svg className="size-4 fill-primary-foreground" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||
@@ -75,7 +80,10 @@ function ExtInstallSettings() {
|
||||
<span>Get Now</span>
|
||||
</div>
|
||||
}
|
||||
onClick={() => openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', 'firefox')}
|
||||
onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', isFlatpak ? null : 'firefox');
|
||||
}}
|
||||
>
|
||||
<span className="font-semibold flex items-center gap-2">
|
||||
<svg className="size-4 fill-primary-foreground" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||
@@ -87,13 +95,38 @@ function ExtInstallSettings() {
|
||||
</SlidingButton>
|
||||
</div>
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Button variant="outline" onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'msedge')}>Edge</Button>
|
||||
<Button variant="outline" onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'opera')}>Opera</Button>
|
||||
<Button variant="outline" onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'brave')}>Brave</Button>
|
||||
<Button variant="outline" onClick={() => openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', 'vivaldi')}>Vivaldi</Button>
|
||||
<Button variant="outline" onClick={() => openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', 'zen')}>Zen</Button>
|
||||
<Button variant="outline" onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : 'msedge');
|
||||
}}>
|
||||
Edge
|
||||
</Button>
|
||||
<Button variant="outline" onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : 'opera');
|
||||
}}>
|
||||
Opera
|
||||
</Button>
|
||||
<Button variant="outline" onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : 'brave');
|
||||
}}>
|
||||
Brave
|
||||
</Button>
|
||||
<Button variant="outline" onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf', isFlatpak ? null : 'vivaldi');
|
||||
}}>
|
||||
Vivaldi
|
||||
</Button>
|
||||
<Button variant="outline" onClick={async() => {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
openLink('https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus', isFlatpak ? null : 'zen');
|
||||
}}>
|
||||
Zen
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mb-2">* These links opens with coresponding browsers only. Make sure the browser is installed before clicking the link</p>
|
||||
<p className="text-xs text-muted-foreground mb-2">* These links opens with coresponding browsers only (except on flatpak). Make sure the browser is installed before clicking the link</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user