feat(web): icon support for win

This commit is contained in:
arkohut 2024-10-16 14:42:40 +08:00
parent 2a25a7ee07
commit b52f66073c
3 changed files with 64 additions and 35 deletions

View File

@ -5,7 +5,7 @@
import OCRTable from './OCRTable.svelte';
import { marked } from 'marked';
import { ChevronLeft, ChevronRight, X, Hash, Library, Folder, FileClock } from 'lucide-svelte';
import { appIconMap } from '$lib/utils';
import { translateAppName } from '$lib/utils';
import LucideIcon from '$lib/components/LucideIcon.svelte';
/**
@ -127,7 +127,7 @@
<div class="flex-none w-full md:w-1/2 flex flex-col">
<div class="mb-4">
<div class="flex items-center space-x-2 text-lg leading-tight font-medium text-black hover:underline">
<LucideIcon name={appIconMap[app_name] || 'Image'} size={24} />
<LucideIcon name={translateAppName(app_name) || "Image"} size={24} />
<p>{title}</p>
</div>
</div>

View File

@ -61,30 +61,59 @@ export const flyAndScale = (
};
};
export const appIconMap: Record<string, string> = {
"Cursor": "Code",
"Google Chrome": "Chrome",
"IINA": "Youtube",
"微信": "MessageSquareCode",
"预览": "Eye",
"iTerm2": "SquareTerminal",
"企业微信": "MessageSquareCode",
"IntelliJ IDEA": "Code",
"Microsoft Edge": "Globe",
"腾讯会议": "MessagesSquare",
"访达": "Folder",
"邮件": "Mail",
"备忘录": "NotebookTabs",
"日历": "CalendarFold",
"UserNotificationCenter": "Bell",
"Electron": "Atom",
"Firefox": "Globe",
"Safari浏览器": "Compass",
"熊掌记": "NotebookTabs",
"Alacritty": "SquareTerminal",
"系统设置": "Settings",
"股市": "CircleDollarSign",
"活动监视器": "Activity",
"Brave Browser": "Globe",
"Code": "Code",
};
export function translateAppName(appName: string): string | undefined {
// Remove the '.exe' suffix for Windows app names
const cleanedAppName = appName.replace(/\.exe$/, '');
const appIconMap: Record<string, string> = {
"chrome": "Chrome",
"firefox": "Globe",
"edge": "Globe",
"msedge": "Globe",
"code": "Code",
"cursor": "Code",
"windows app beta": "LayoutGrid",
"windows app preview": "LayoutGrid",
"google chrome": "Chrome",
"iina": "Youtube",
"微信": "MessageSquareCode",
"预览": "Eye",
"iterm2": "SquareTerminal",
"企业微信": "MessageSquareCode",
"intellij idea": "Code",
"microsoft edge": "Globe",
"腾讯会议": "Phone",
"访达": "Folder",
"邮件": "Mail",
"备忘录": "NotebookTabs",
"日历": "CalendarFold",
"usernotificationcenter": "Bell",
"electron": "Atom",
"safari浏览器": "Compass",
"熊掌记": "NotebookTabs",
"alacritty": "SquareTerminal",
"系统设置": "Settings",
"股市": "CircleDollarSign",
"活动监视器": "Activity",
"brave browser": "Globe",
"windowsterminal": "SquareTerminal",
"explorer": "Folder",
"clash for windows": "Globe",
"mpv": "Youtube",
"searchhost": "Search",
"lockapp": "Lock",
"thunder": "CloudDownload",
"xlliveud": "CloudDownload",
"ollama app": "Bot",
"githubdesktop": "Github",
};
// Try to match the cleaned app name (case-insensitive)
const iconName = appIconMap[cleanedAppName.toLowerCase()];
// If no match is found, return undefined
return iconName;
}

View File

@ -8,7 +8,7 @@
import { formatDistanceToNow } from 'date-fns';
import Logo from '$lib/components/Logo.svelte';
import { onMount } from 'svelte';
import { appIconMap } from '$lib/utils';
import { translateAppName } from '$lib/utils';
import LucideIcon from '$lib/components/LucideIcon.svelte';
let searchString = '';
@ -267,11 +267,11 @@
return filename(document.filepath);
}
function getAppName(document: any): string | null {
if (document.metadata_entries && document.metadata_entries.some((entry) => entry.key === 'active_app')) {
return document.metadata_entries.find((entry) => entry.key === 'active_app').value;
function getAppName(document: any): string {
if (document.metadata_entries && document.metadata_entries.some((entry: any) => entry.key === 'active_app')) {
return document.metadata_entries.find((entry: any) => entry.key === 'active_app').value;
} else {
return null;
return "unknown";
}
}
@ -368,7 +368,7 @@
<div
class="absolute bottom-2 left-6 bg-white bg-opacity-75 px-2 py-1 rounded-full text-xs font-semibold border border-gray-200 flex items-center space-x-2"
>
<LucideIcon name={appIconMap[getAppName(hit.document)] || 'Hexagon'} size={16} />
<LucideIcon name={translateAppName(getAppName(hit.document)) || "Hexagon"} size={16} />
<span>{getAppName(hit.document)}</span>
</div>
{/if}