Skip to content

Commit 92aba94

Browse files
colinmcneildgageot
authored andcommitted
Add build step to pull all catalog images and cache them as static assets
1 parent 7ac82c1 commit 92aba94

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

src/extension/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ COPY host-binary/dist/windows-${TARGETARCH}/host-binary.exe /windows/host-binary
4242
COPY host-binary/dist/darwin-${TARGETARCH}/host-binary /darwin/host-binary
4343
COPY host-binary/dist/linux-${TARGETARCH}/host-binary /linux/host-binary
4444
COPY --from=client-builder /ui/build ui
45+
COPY ui/static-assets ui/static-assets
4546
#COPY data /data
4647

4748
#CMD ["/service", "-socket", "/run/guest-services/backend.sock"]

src/extension/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ bin:
1414
cross:
1515
cd host-binary && $(MAKE) cross
1616

17-
build-extension: cross ## Build service image to be deployed as a desktop extension
17+
pull-catalog-images: ## Pull all icons from the catalog into static-assets with base64 filenames
18+
cat ../../prompts/catalog.yaml | yq -r '.registry[].icon' | while read -r iconUrl; do \
19+
iconName=$$( echo "$$iconUrl" | xxd -p -u | tr -d '\n' ); \
20+
iconPath="ui/static-assets/$$iconName.png"; \
21+
[ -f "$$iconPath" ] || curl -o "$$iconPath" "$$iconUrl"; \
22+
done
23+
24+
build-extension: cross pull-catalog-images ## Build service image to be deployed as a desktop extension
1825
docker buildx build --load --tag=$(IMAGE):$(TAG) .
1926

2027
install-extension: build-extension ## Install the extension

src/extension/ui/src/components/tile/Modal.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import { useSecrets } from '../../queries/useSecrets';
4545
import { CatalogItemRichened } from '../../types/catalog';
4646
import ConfigEditor from './ConfigEditor';
4747
import { isEmpty } from 'lodash-es';
48+
import { encode } from 'js-base64';
49+
import CatalogIconPath from '../../utils/CatalogIconPath';
4850

4951
interface TabPanelProps {
5052
children?: React.ReactNode;
@@ -172,16 +174,19 @@ const ConfigurationModal = ({
172174
alignItems: 'center',
173175
}}
174176
>
175-
<Avatar
176-
variant="square"
177-
src={catalogItem.icon}
178-
alt={catalogItem.name}
179-
sx={{
180-
width: 40,
181-
height: 40,
182-
borderRadius: 1,
183-
}}
184-
/>
177+
{
178+
// TODO: Figure out if catalog icon is actually optional, and if so, find a good fallback.
179+
catalogItem.icon && <Avatar
180+
variant="square"
181+
src={CatalogIconPath(catalogItem.icon)}
182+
alt={catalogItem.name}
183+
sx={{
184+
width: 40,
185+
height: 40,
186+
borderRadius: 1,
187+
}}
188+
/>
189+
}
185190
{catalogItem.title ?? catalogItem.name}
186191
<Tooltip
187192
placement="right"
@@ -386,7 +391,7 @@ const ConfigurationModal = ({
386391
const secretEdited =
387392
(secret.assigned &&
388393
localSecrets[secret.name] !==
389-
ASSIGNED_SECRET_PLACEHOLDER) ||
394+
ASSIGNED_SECRET_PLACEHOLDER) ||
390395
(!secret.assigned &&
391396
localSecrets[secret.name] !== '');
392397
return (

src/extension/ui/src/components/tile/Top.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Avatar, CardHeader, Switch, Tooltip, Typography } from '@mui/material';
22

33
import { CatalogItemRichened } from '../../types/catalog';
44
import { useEffect, useState } from 'react';
5+
import CatalogIconPath from '../../utils/CatalogIconPath';
56

67
type TopProps = {
78
onToggleRegister: (checked: boolean) => void;
@@ -20,13 +21,15 @@ export default function Top({ item, onToggleRegister }: TopProps) {
2021
setToggled(item.registered);
2122
}, [item.registered]);
2223

24+
const url = CatalogIconPath(item.icon || '');
25+
2326
return (
2427
<CardHeader
2528
sx={{ padding: 0 }}
2629
avatar={
2730
<Avatar
2831
variant="square"
29-
src={item.icon}
32+
src={url}
3033
alt={item.name}
3134
sx={{
3235
width: 24,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const CatalogIconPath = (iconUrl: string) => {
2+
const iconFilename = [...iconUrl].map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('').toUpperCase() + '0A.png';
3+
return new URL(`/static-assets/${iconFilename}`, import.meta.url).href;
4+
}
5+
6+
export default CatalogIconPath;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.png
2+
*.svg

src/extension/ui/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineConfig({
2323
},
2424
},
2525
},
26+
assetsInclude: ['./static-assets/**/*'],
2627
server: {
2728
port: 3000,
2829
strictPort: true,

0 commit comments

Comments
 (0)