refactor: renamed quick download as quick search

This commit is contained in:
2025-11-09 20:48:31 +05:30
parent a2c29e87fd
commit cea4fcefae
4 changed files with 54 additions and 54 deletions

View File

@@ -17,7 +17,7 @@ NeoDLP (Neo Downloader Plus) Browser Integration
#### Direct Installation from Official Web Store Listing
[link-chrome]: https://chromewebstore.google.com/detail/neo-downloader-plus/mehopeailfjmiloiiohgicphlcgpompf "Version published on Chrome Web Store"
[link-firefox]: https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus/ "Version published on Mozilla Add-ons"
[link-firefox]: https://addons.mozilla.org/en-US/firefox/addon/neo-downloader-plus "Version published on Mozilla Add-ons"
[<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/chrome/chrome.svg" width="48" alt="Chrome" valign="middle">][link-chrome] [<img valign="middle" src="https://img.shields.io/chrome-web-store/v/mehopeailfjmiloiiohgicphlcgpompf.svg?label=%20">][link-chrome] also compatible with [<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/edge/edge.svg" width="24" alt="Edge" valign="middle">][link-chrome] [<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/opera/opera.svg" width="24" alt="Opera" valign="middle">][link-chrome]

View File

@@ -35,13 +35,13 @@ export default defineBackground(() => {
// Listen for the keyboard commands
browser.commands.onCommand.addListener(async (command) => {
if (command === "neodlp:quick-download") {
if (command === "neodlp:quick-search") {
try {
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
const activeTab = tabs[0];
if (activeTab && activeTab.url) {
console.log("Quick download triggered for URL:", activeTab.url);
console.log("Quick search triggered for URL:", activeTab.url);
const response = await sendMessageToNativeHost({
url: activeTab.url,
@@ -49,12 +49,12 @@ export default defineBackground(() => {
argument: ''
});
console.log("Quick download response:", response);
console.log("Quick search response:", response);
} else {
console.error("No active tab or URL found for quick download");
console.error("No active tab or URL found for quick search");
}
} catch (error) {
console.error("Error in quick download:", error);
console.error("Error in quick search:", error);
}
}
});
@@ -63,50 +63,50 @@ export default defineBackground(() => {
browser.contextMenus.removeAll().then(() => {
// Context menu for quick download
browser.contextMenus.create({
id: "quick-download:page",
title: "Download with Neo Downloader Plus",
id: "quick-search:page",
title: "Search with Neo Downloader Plus",
contexts: ["page"]
});
browser.contextMenus.create({
id: "quick-download:link",
title: "Download Link with Neo Downloader Plus",
id: "quick-search:link",
title: "Search with Neo Downloader Plus (Link)",
contexts: ["link"]
});
browser.contextMenus.create({
id: "quick-download:media",
title: "Download Media with Neo Downloader Plus",
id: "quick-search:media",
title: "Search with Neo Downloader Plus (Media Source)",
contexts: ["video", "audio"]
});
browser.contextMenus.create({
id: "quick-download:selection",
title: "Download Selection with Neo Downloader Plus",
id: "quick-search:selection",
title: "Search with Neo Downloader Plus (Selected Text)",
contexts: ["selection"]
});
});
browser.contextMenus.onClicked.addListener((info, tab) => {
let url = '';
if (info.menuItemId === "quick-download:page") {
if (info.menuItemId === "quick-search:page") {
if(!info.pageUrl) return;
url = info.pageUrl;
} else if (info.menuItemId === "quick-download:link") {
} else if (info.menuItemId === "quick-search:link") {
if(!info.linkUrl) return;
url = info.linkUrl;
} else if (info.menuItemId === "quick-download:media") {
} else if (info.menuItemId === "quick-search:media") {
if(!info.srcUrl) return;
url = info.srcUrl;
} else if (info.menuItemId === "quick-download:selection") {
} else if (info.menuItemId === "quick-search:selection") {
if(!info.selectionText) return;
url = info.selectionText;
}
if (!url) return;
sendMessageToNativeHost({url: url, command: 'download', argument: ''}).then(response => {
console.log("Context menu download response:", response);
console.log("Context menu search response:", response);
}).catch(error => {
console.error("Error in context menu download:", error);
console.error("Error in context menu search:", error);
});
});
});

View File

@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
import { AlertCircle, Download, Loader2, LucideIcon, Monitor, Moon, Sun } from "lucide-react";
import { AlertCircle, Loader2, LucideIcon, Monitor, Moon, Search, Sun } from "lucide-react";
import { type Browser } from 'wxt/browser';
import { Textarea } from "@/components/ui/textarea";
import { z } from "zod";
@@ -16,7 +16,7 @@ import { useTheme } from "@/components/theme-provider";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Kbd, KbdGroup } from "@/components/ui/kbd";
const downloadFormSchema = z.object({
const searchFormSchema = z.object({
url: z.url({
error: (issue) => issue.input === undefined || issue.input === null || issue.input === ""
? "URL is required"
@@ -26,7 +26,7 @@ const downloadFormSchema = z.object({
export default function HomePage() {
const { setTheme } = useTheme();
const [isDownloading, setIsDownloading] = useState(false);
const [isSearching, setIsSearching] = useState(false);
const [isLoadingSettings, setIsLoadingSettings] = useState(true);
const [isUpdatingSettings, setIsUpdatingSettings] = useState(false);
const [showNotRunningAlert, setShowNotRunningAlert] = useState(false);
@@ -42,17 +42,17 @@ export default function HomePage() {
{ value: 'system', icon: Monitor, label: 'System' },
];
const downloadForm = useForm<z.infer<typeof downloadFormSchema>>({
resolver: zodResolver(downloadFormSchema),
const searchForm = useForm<z.infer<typeof searchFormSchema>>({
resolver: zodResolver(searchFormSchema),
defaultValues: {
url: '',
},
mode: "onChange",
});
const watchedUrl = downloadForm.watch("url");
const watchedUrl = searchForm.watch("url");
const handleDownload = async (url?: string) => {
setIsDownloading(true);
const handleSearch = async (url?: string) => {
setIsSearching(true);
setShowNotRunningAlert(false); // Reset alert status at the beginning
// Create a timeout reference with undefined type
@@ -85,7 +85,7 @@ export default function HomePage() {
console.log('Response from background script:', response);
}
} catch (error) {
console.error("Download failed", error);
console.error("Search failed", error);
// Check if this was a timeout error
if (error instanceof Error && error.message === 'TIMEOUT') {
@@ -95,12 +95,12 @@ export default function HomePage() {
// Clear the timeout if it was some other error
if (timeoutId) clearTimeout(timeoutId);
} finally {
setIsDownloading(false);
setIsSearching(false);
}
};
const handleDownloadSubmit = async (values: z.infer<typeof downloadFormSchema>) => {
await handleDownload(values.url);
const handleSearchSubmit = async (values: z.infer<typeof searchFormSchema>) => {
await handleSearch(values.url);
}
const saveSettings = async <K extends keyof Settings>(key: K, value: Settings[K]) => {
@@ -171,8 +171,8 @@ export default function HomePage() {
});
const activeTab = tabs[0];
if (activeTab && activeTab.url) {
downloadForm.setValue("url", activeTab.url);
await downloadForm.trigger("url");
searchForm.setValue("url", activeTab.url);
await searchForm.trigger("url");
}
}
if (!isLoadingSettings && settings.autofill_url) {
@@ -187,8 +187,8 @@ export default function HomePage() {
if (changeInfo.status === "complete") {
browser.tabs.get(tabId).then(async (tab) => {
if (tab.active && tab.url) {
downloadForm.setValue("url", tab.url);
await downloadForm.trigger("url");
searchForm.setValue("url", tab.url);
await searchForm.trigger("url");
}
});
}
@@ -236,12 +236,12 @@ export default function HomePage() {
/>
<Label htmlFor="autofill-url">AutoFill Page URL</Label>
</div>
<Form {...downloadForm}>
<form onSubmit={downloadForm.handleSubmit(handleDownloadSubmit)} className="flex flex-col gap-4 w-full" autoComplete="off">
<Form {...searchForm}>
<form onSubmit={searchForm.handleSubmit(handleSearchSubmit)} className="flex flex-col gap-4 w-full" autoComplete="off">
<FormField
control={downloadForm.control}
control={searchForm.control}
name="url"
disabled={isDownloading || isLoadingSettings || isUpdatingSettings}
disabled={isSearching || isLoadingSettings || isUpdatingSettings}
render={({ field }) => (
<FormItem className="w-full">
<FormControl>
@@ -265,16 +265,16 @@ export default function HomePage() {
</FormItem>
)}
/>
<Button className="w-full cursor-pointer" type="submit" disabled={isDownloading || isLoadingSettings || isUpdatingSettings || !watchedUrl || downloadForm.getFieldState("url").invalid}>
{isDownloading ? (
<Button className="w-full cursor-pointer" type="submit" disabled={isSearching || isLoadingSettings || isUpdatingSettings || !watchedUrl || searchForm.getFieldState("url").invalid}>
{isSearching ? (
<>
<Loader2 className="w-4 h-4 animate-spin" />
Starting
Initiating
</>
) : (
<>
<Download className="w-4 h-4" />
Download
<Search className="w-4 h-4" />
Search
</>
)}
</Button>
@@ -285,12 +285,12 @@ export default function HomePage() {
OR
</span>
</div>
<div className="quick-download-suggestion flex flex-col items-center justify-center space-y-2">
<div className="quick-search-suggestion flex flex-col items-center justify-center space-y-2">
<p className="text-sm flex items-center gap-2"><span className="">Use, Shortcut</span>
{
shortcuts.find(cmd => cmd.name === "neodlp:quick-download")?.shortcut ? (
shortcuts.find(cmd => cmd.name === "neodlp:quick-search")?.shortcut ? (
<KbdGroup>
{shortcuts.find(cmd => cmd.name === "neodlp:quick-download")?.shortcut?.split('+').map((key, index, arr) => (
{shortcuts.find(cmd => cmd.name === "neodlp:quick-search")?.shortcut?.split('+').map((key, index, arr) => (
<span key={index} className="flex items-center">
<Kbd>{formatKeySymbol(key.trim())}</Kbd>
{index < arr.length - 1 && <span className="ml-1">+</span>}

View File

@@ -33,8 +33,8 @@ export default defineConfig({
default: "Alt+Shift+N",
}
},
"neodlp:quick-download": {
description: "Quick Download",
"neodlp:quick-search": {
description: "Quick Search",
suggested_key: {
default: "Alt+Shift+Q"
}
@@ -55,8 +55,8 @@ export default defineConfig({
default: "Alt+Shift+N",
}
},
"neodlp:quick-download": {
description: "Quick Download",
"neodlp:quick-search": {
description: "Quick Search",
suggested_key: {
default: "Alt+Shift+Q"
}
@@ -72,8 +72,8 @@ export default defineConfig({
default: "Alt+Shift+N",
}
},
"neodlp:quick-download": {
description: "Quick Download",
"neodlp:quick-search": {
description: "Quick Search",
suggested_key: {
default: "Alt+Shift+Q"
}