mirror of
https://github.com/kunkunsh/kunkun-ext-neohtop.git
synced 2025-04-11 17:29:45 +00:00
adds processes icons
This commit is contained in:
parent
be55e49c54
commit
d7008f754d
14
package-lock.json
generated
14
package-lock.json
generated
@ -13,6 +13,7 @@
|
|||||||
"@fortawesome/free-solid-svg-icons": "^6.6.0",
|
"@fortawesome/free-solid-svg-icons": "^6.6.0",
|
||||||
"@tauri-apps/api": "^1.5.3",
|
"@tauri-apps/api": "^1.5.3",
|
||||||
"@tauri-apps/plugin-shell": "^2",
|
"@tauri-apps/plugin-shell": "^2",
|
||||||
|
"simple-icons": "^13.15.0",
|
||||||
"svelte-fa": "^4.0.3"
|
"svelte-fa": "^4.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -1513,6 +1514,19 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/simple-icons": {
|
||||||
|
"version": "13.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/simple-icons/-/simple-icons-13.15.0.tgz",
|
||||||
|
"integrity": "sha512-8SzFj9CvPlDnjDLISsAWTvpCs7om2zbSJZ1hNLRo6quWKLqFwjCD9opS24Q/yD0bdsnVHPpF0N3hitpHrY5u9w==",
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12.18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/simple-icons"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/sirv": {
|
"node_modules/sirv": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.0.tgz",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"@fortawesome/free-solid-svg-icons": "^6.6.0",
|
"@fortawesome/free-solid-svg-icons": "^6.6.0",
|
||||||
"@tauri-apps/api": "^1.5.3",
|
"@tauri-apps/api": "^1.5.3",
|
||||||
"@tauri-apps/plugin-shell": "^2",
|
"@tauri-apps/plugin-shell": "^2",
|
||||||
|
"simple-icons": "^13.15.0",
|
||||||
"svelte-fa": "^4.0.3"
|
"svelte-fa": "^4.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import Fa from "svelte-fa";
|
import Fa from "svelte-fa";
|
||||||
import type { Process, Column } from "$lib/types";
|
import type { Process, Column } from "$lib/types";
|
||||||
|
import * as SimpleIcons from "simple-icons";
|
||||||
|
|
||||||
export let processes: Process[];
|
export let processes: Process[];
|
||||||
export let columns: Column[];
|
export let columns: Column[];
|
||||||
@ -22,6 +23,47 @@
|
|||||||
if (sortConfig.field !== field) return "↕";
|
if (sortConfig.field !== field) return "↕";
|
||||||
return sortConfig.direction === "asc" ? "↑" : "↓";
|
return sortConfig.direction === "asc" ? "↑" : "↓";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleImageError(event: Event) {
|
||||||
|
const img = event.target as HTMLImageElement;
|
||||||
|
img.src = getIconForProcess("default"); // Fallback to default icon
|
||||||
|
img.onerror = null; // Prevent infinite loop if default icon also fails
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIconForProcess(name: string): string {
|
||||||
|
const cleanName = name
|
||||||
|
// Remove common app suffixes
|
||||||
|
.replace(/\.(app|exe)$/i, "")
|
||||||
|
// Replace separators with spaces
|
||||||
|
.replace(/[-_./\\]/g, " ")
|
||||||
|
// Get first word, trim, and lowercase
|
||||||
|
.split(" ")[0]
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
// Convert to SimpleIcons format (capitalize first word)
|
||||||
|
const formattedName =
|
||||||
|
cleanName.charAt(0).toUpperCase() + cleanName.slice(1);
|
||||||
|
const iconKey = `si${formattedName}`;
|
||||||
|
let simpleIcon = SimpleIcons[iconKey as keyof typeof SimpleIcons];
|
||||||
|
|
||||||
|
// Default icon if no match found
|
||||||
|
if (!simpleIcon) {
|
||||||
|
simpleIcon = SimpleIcons.siGhostery;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use theme color instead of brand color
|
||||||
|
const color = getComputedStyle(document.documentElement)
|
||||||
|
.getPropertyValue("--text")
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
const svg =
|
||||||
|
typeof simpleIcon === "object" && "svg" in simpleIcon
|
||||||
|
? simpleIcon.svg
|
||||||
|
: "";
|
||||||
|
const svgWithColor = svg.replace("<svg", `<svg fill="${color}"`);
|
||||||
|
return `data:image/svg+xml;base64,${btoa(svgWithColor)}`;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
@ -53,7 +95,19 @@
|
|||||||
>
|
>
|
||||||
{#each columns.filter((col) => col.visible) as column}
|
{#each columns.filter((col) => col.visible) as column}
|
||||||
<td class="truncate">
|
<td class="truncate">
|
||||||
{#if column.format}
|
{#if column.id === "name"}
|
||||||
|
<div class="name-cell">
|
||||||
|
<img
|
||||||
|
class="process-icon"
|
||||||
|
src={getIconForProcess(process.name)}
|
||||||
|
alt=""
|
||||||
|
height="16"
|
||||||
|
width="16"
|
||||||
|
on:error={handleImageError}
|
||||||
|
/>
|
||||||
|
<span class="process-name">{process.name}</span>
|
||||||
|
</div>
|
||||||
|
{:else if column.format}
|
||||||
{@html column.format(process[column.id])}
|
{@html column.format(process[column.id])}
|
||||||
{:else}
|
{:else}
|
||||||
{process[column.id]}
|
{process[column.id]}
|
||||||
@ -345,4 +399,16 @@
|
|||||||
.btn-action:disabled::before {
|
.btn-action:disabled::before {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.process-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name-cell {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -117,7 +117,7 @@ export const themes: Record<string, Theme> = {
|
|||||||
crust: '#13131a',
|
crust: '#13131a',
|
||||||
text: '#a9b1d6',
|
text: '#a9b1d6',
|
||||||
subtext0: '#9aa5ce',
|
subtext0: '#9aa5ce',
|
||||||
subtext1: '#b4f9f8',
|
subtext1: '#9aa5ce',
|
||||||
surface0: '#232433',
|
surface0: '#232433',
|
||||||
surface1: '#2a2b3d',
|
surface1: '#2a2b3d',
|
||||||
surface2: '#32344a',
|
surface2: '#32344a',
|
||||||
|
@ -73,12 +73,8 @@ export const statusMap: Record<string, ProcessStatus> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function formatStatus(status: string): string {
|
export function formatStatus(status: string): string {
|
||||||
// Log the incoming status for debugging
|
|
||||||
console.log('Process status:', status);
|
|
||||||
|
|
||||||
const processStatus = statusMap[status] || statusMap.Unknown;
|
const processStatus = statusMap[status] || statusMap.Unknown;
|
||||||
return `<span class="status-badge" style="--status-color: ${processStatus.color}">
|
return `<span class="status-badge" style="--status-color: ${processStatus.color}">
|
||||||
<span class="status-emoji">${processStatus.emoji}</span>
|
|
||||||
${processStatus.label}
|
${processStatus.label}
|
||||||
</span>`;
|
</span>`;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user