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 OCRTable from './OCRTable.svelte';
import { marked } from 'marked'; import { marked } from 'marked';
import { ChevronLeft, ChevronRight, X, Hash, Library, Folder, FileClock } from 'lucide-svelte'; 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'; 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="flex-none w-full md:w-1/2 flex flex-col">
<div class="mb-4"> <div class="mb-4">
<div class="flex items-center space-x-2 text-lg leading-tight font-medium text-black hover:underline"> <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> <p>{title}</p>
</div> </div>
</div> </div>

View File

@ -61,30 +61,59 @@ export const flyAndScale = (
}; };
}; };
export const appIconMap: Record<string, string> = { export function translateAppName(appName: string): string | undefined {
"Cursor": "Code", // Remove the '.exe' suffix for Windows app names
"Google Chrome": "Chrome", const cleanedAppName = appName.replace(/\.exe$/, '');
"IINA": "Youtube",
"微信": "MessageSquareCode", const appIconMap: Record<string, string> = {
"预览": "Eye", "chrome": "Chrome",
"iTerm2": "SquareTerminal", "firefox": "Globe",
"企业微信": "MessageSquareCode", "edge": "Globe",
"IntelliJ IDEA": "Code", "msedge": "Globe",
"Microsoft Edge": "Globe", "code": "Code",
"腾讯会议": "MessagesSquare", "cursor": "Code",
"访达": "Folder",
"邮件": "Mail", "windows app beta": "LayoutGrid",
"备忘录": "NotebookTabs", "windows app preview": "LayoutGrid",
"日历": "CalendarFold",
"UserNotificationCenter": "Bell", "google chrome": "Chrome",
"Electron": "Atom", "iina": "Youtube",
"Firefox": "Globe", "微信": "MessageSquareCode",
"Safari浏览器": "Compass", "预览": "Eye",
"熊掌记": "NotebookTabs", "iterm2": "SquareTerminal",
"Alacritty": "SquareTerminal", "企业微信": "MessageSquareCode",
"系统设置": "Settings", "intellij idea": "Code",
"股市": "CircleDollarSign", "microsoft edge": "Globe",
"活动监视器": "Activity", "腾讯会议": "Phone",
"Brave Browser": "Globe", "访达": "Folder",
"Code": "Code", "邮件": "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 { formatDistanceToNow } from 'date-fns';
import Logo from '$lib/components/Logo.svelte'; import Logo from '$lib/components/Logo.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { appIconMap } from '$lib/utils'; import { translateAppName } from '$lib/utils';
import LucideIcon from '$lib/components/LucideIcon.svelte'; import LucideIcon from '$lib/components/LucideIcon.svelte';
let searchString = ''; let searchString = '';
@ -267,11 +267,11 @@
return filename(document.filepath); return filename(document.filepath);
} }
function getAppName(document: any): string | null { function getAppName(document: any): string {
if (document.metadata_entries && document.metadata_entries.some((entry) => entry.key === 'active_app')) { if (document.metadata_entries && document.metadata_entries.some((entry: any) => entry.key === 'active_app')) {
return document.metadata_entries.find((entry) => entry.key === 'active_app').value; return document.metadata_entries.find((entry: any) => entry.key === 'active_app').value;
} else { } else {
return null; return "unknown";
} }
} }
@ -368,7 +368,7 @@
<div <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" 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> <span>{getAppName(hit.document)}</span>
</div> </div>
{/if} {/if}