Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(resources): show the download dialog's resources as a card, with icons
Elian Doran3db8e1b355f1
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 9659766b3d..d971bac26a 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4609,10 +4609,10 @@},"resource_download": {"title": "Download required",- "intro": "This needs the files below, which do not come with Trilium. They are downloaded once and kept on this device.",- "partially_downloaded": "{{size}}, of which {{downloaded}} is already downloaded",+ "intro": "Trilium needs to download the following files before it can continue. They are saved on this device and are not synced, so each of your devices downloads them separately.",+ "partially_downloaded": "{{size}} already downloaded","sources": "From {{sources}}",- "total": "Download size: {{size}}",+ "total": "Download size","free_space": "Free space: {{size}}","not_enough_space": "There is not enough free space for this download.","progress": "{{received}} of {{total}}",diff --git a/apps/client/src/widgets/dialogs/resource_download.css b/apps/client/src/widgets/dialogs/resource_download.cssindex 0de5657505..4f83a23e80 100644--- a/apps/client/src/widgets/dialogs/resource_download.css+++ b/apps/client/src/widgets/dialogs/resource_download.css@@ -1,27 +1,29 @@.modal.resource-download-dialog {.resource-download-list {- padding-inline-start: 1.25em;-- li + li {- margin-top: 0.75em;- }+ margin-bottom: 1em;+ }- p {- margin-bottom: 0.25em;- }+ .resource-download-item {+ gap: 12px;}- .resource-download-meta {+ .resource-download-icon {+ align-self: flex-start;+ font-size: 1.6em;color: var(--muted-text-color);- font-size: 0.9em;}- .resource-download-totals {- display: flex;- flex-wrap: wrap;- justify-content: space-between;- gap: 0.5em;- font-weight: 600;+ .resource-download-size {+ flex-shrink: 0;+ font-variant-numeric: tabular-nums;+ white-space: nowrap;+ }++ .resource-download-total {+ .tn-card-option-title,+ .resource-download-size {+ font-weight: 600;+ }}.resource-download-progress {diff --git a/apps/client/src/widgets/dialogs/resource_download.spec.tsx b/apps/client/src/widgets/dialogs/resource_download.spec.tsxindex e72da98566..d52395753c 100644--- a/apps/client/src/widgets/dialogs/resource_download.spec.tsx+++ b/apps/client/src/widgets/dialogs/resource_download.spec.tsx@@ -31,6 +31,7 @@ const STATUS: ResourcesStatusResponse = {id: "transcription.model",title: "Speech recognition model",description: "Transcribes meetings",+ icon: "bx bx-captions",size: 700,downloadedSize: 200,sources: [ "huggingface.co", "github.com" ],@@ -61,9 +62,14 @@ describe("ResourceDownloadDialog", () => {mocks.post.mockResolvedValue(progress({ receivedBytes: 200 }));await open();- expect(text(".resource-download-list")).toContain("Speech recognition model");+ const row = container.querySelector(".resource-download-item");+ expect(row?.querySelector(".resource-download-icon")?.classList).toContain("bx-captions");+ expect(row?.textContent).toContain("Speech recognition model");expect(text(".resource-download-meta")).toContain("huggingface.co, github.com");- expect(text(".resource-download-totals")).toContain(`"size":"500 B"`);+ expect(text(".resource-download-meta")).toContain(`"size":"200 B"`);+ expect(text(".resource-download-item .resource-download-size")).toBe("700 B");+ expect(text(".resource-download-total .resource-download-size")).toBe("500 B");+ expect(text(".resource-download-total")).toContain(`free_space:{"size":"100 B"}`);expect(container.querySelector(".alert-warning")).not.toBeNull();await click("resource_download.download");diff --git a/apps/client/src/widgets/dialogs/resource_download.tsx b/apps/client/src/widgets/dialogs/resource_download.tsxindex 2a041b9d94..f74498f023 100644--- a/apps/client/src/widgets/dialogs/resource_download.tsx+++ b/apps/client/src/widgets/dialogs/resource_download.tsx@@ -11,7 +11,9 @@ import { formatSize } from "../../services/utils";import { subscribeToMessages, unsubscribeToMessage } from "../../services/ws";import Alert from "../react/Alert";import Button from "../react/Button";+import { Card, CardSection } from "../react/Card";import { useTriliumEvent } from "../react/hooks";+import Icon from "../react/Icon";import Modal from "../react/Modal";export interface ResourceDownloadDialogOptions {@@ -82,7 +84,7 @@ export default function ResourceDownloadDialog() {return (<ModalclassName="resource-download-dialog"- size="md"+ size="lg"title={t("resource_download.title")}show={shown}onHidden={() => {@@ -118,15 +120,24 @@ function ResourceList({ status }: { status: ResourcesStatusResponse }) {return (<><p>{t("resource_download.intro")}</p>- <ul className="resource-download-list">+ <Card className="resource-download-list">{missing.map((resource) => <ResourceItem key={resource.id} resource={resource} />)}- </ul>- <p className="resource-download-totals">- <span>{t("resource_download.total", { size: formatSize(remaining) })}</span>- {status.freeBytes !== null && (- <span>{t("resource_download.free_space", { size: formatSize(status.freeBytes) })}</span>- )}- </p>+ <CardSection className="tn-card-option resource-download-total">+ <div className="tn-card-option-label">+ <span className="tn-card-option-title">{t("resource_download.total")}</span>+ {status.freeBytes !== null && (+ <small className="tn-card-option-description">+ {t("resource_download.free_space", {+ size: formatSize(status.freeBytes)+ })}+ </small>+ )}+ </div>+ <span className="tn-card-option-value resource-download-size">+ {formatSize(remaining)}+ </span>+ </CardSection>+ </Card>{status.freeBytes !== null && status.freeBytes < remaining && (<Alert type="warning">{t("resource_download.not_enough_space")}</Alert>)}@@ -134,22 +145,28 @@ function ResourceList({ status }: { status: ResourcesStatusResponse }) {);}+/** One resource as a settings row: its icon, what it is and where it comes from, and its size. */function ResourceItem({ resource }: { resource: ResourceInfo }) {- const size = formatSize(resource.size);return (- <li>- <strong>{resource.title}</strong>- <p>{resource.description}</p>- <p className="resource-download-meta">- {resource.downloadedSize- ? t("resource_download.partially_downloaded", {- size, downloaded: formatSize(resource.downloadedSize)- })- : size}- {" · "}- {t("resource_download.sources", { sources: resource.sources.join(", ") })}- </p>- </li>+ <CardSection className="tn-card-option resource-download-item">+ <Icon icon={resource.icon} className="resource-download-icon" />+ <div className="tn-card-option-label">+ <span className="tn-card-option-title">{resource.title}</span>+ <small className="tn-card-option-description">{resource.description}</small>+ <small className="tn-card-option-description resource-download-meta">+ {t("resource_download.sources", { sources: resource.sources.join(", ") })}+ {resource.downloadedSize > 0 && <>+ {" · "}+ {t("resource_download.partially_downloaded", {+ size: formatSize(resource.downloadedSize)+ })}+ </>}+ </small>+ </div>+ <span className="tn-card-option-value resource-download-size">+ {formatSize(resource.size)}+ </span>+ </CardSection>);}diff --git a/apps/desktop/src/services/transcription/model.ts b/apps/desktop/src/services/transcription/model.tsindex b03767b6b3..7833e1378b 100644--- a/apps/desktop/src/services/transcription/model.ts+++ b/apps/desktop/src/services/transcription/model.ts@@ -25,6 +25,7 @@ export const RECOGNIZER_MODEL: ResourceDefinition = {version: "v3-int8-2bda32ec",title: () => t("transcription.recognizer-title"),description: () => t("transcription.recognizer-description"),+ icon: "bx bx-captions",findLocalCopy: () => fs.existsSync(LOCAL_MODEL_DIR) ? LOCAL_MODEL_DIR : null,files: [{@@ -59,6 +60,7 @@ export const VAD_MODEL: ResourceDefinition = {version: "1",title: () => t("transcription.vad-title"),description: () => t("transcription.vad-description"),+ icon: "bx bx-pulse",findLocalCopy: () => fs.existsSync(path.join(LOCAL_MODEL_DIR, VAD_FILE)) ? LOCAL_MODEL_DIR : null,files: [ {path: VAD_FILE,@@ -73,6 +75,7 @@ export const SPEAKER_MODEL: ResourceDefinition = {version: "1",title: () => t("transcription.speaker-title"),description: () => t("transcription.speaker-description"),+ icon: "bx bx-user-voice",findLocalCopy: () => {const directory = path.join(LOCAL_MODEL_DIR, "speaker");return fs.existsSync(path.join(directory, SPEAKER_FILE)) ? directory : null;diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex 68bcf778b2..df4e8ee7e5 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -573,11 +573,11 @@"attachment-title": "Transcript","model-not-downloaded": "The speech recognition model is not downloaded yet. Start a recording from the launcher to download it.","recognizer-title": "Parakeet TDT 0.6B v3",- "recognizer-description": "NVIDIA's speech recognition model, which turns what is said into text in 25 European languages. It runs on this device: nothing you record leaves your computer.",+ "recognizer-description": "A speech recognition model by NVIDIA that supports 25 European languages. Recognition runs entirely on this device, so your recordings never leave it.","vad-title": "Silero VAD",- "vad-description": "Finds the stretches of speech in the audio, so that only those are transcribed.",+ "vad-description": "Used to detect speech in the audio, so that only the parts with speech are transcribed.","speaker-title": "TitaNet small",- "speaker-description": "Tells apart the other people in the meeting, so that the transcript shows who said what."+ "speaker-description": "Used to distinguish speakers, so that you can see who said what in the transcript."},"resources": {"unknown": "There is no resource named {{id}}.",diff --git a/apps/server/src/services/resources.spec.ts b/apps/server/src/services/resources.spec.tsindex 0cd1573a1b..05cdd701cd 100644--- a/apps/server/src/services/resources.spec.ts+++ b/apps/server/src/services/resources.spec.ts@@ -88,6 +88,7 @@ describe("ResourceManager", () => {id: "test.model",title: "Test model",description: "For tests",+ icon: "bx bx-test-tube",size: MODEL.length + TOKENS.length,downloadedSize: MODEL.length + TOKENS.length,sources: [ "127.0.0.1" ],@@ -166,6 +167,7 @@ function defineModel({ id = "test.model", tokensUrl = "/tokens.txt", tokensHashversion: "1",title: () => "Test model",description: () => "For tests",+ icon: "bx bx-test-tube",files: [file("nested/model.bin", MODEL),{ path: "tokens.txt", url: `${baseUrl}${tokensUrl}`, size: tokensSize, sha256: tokensHash }diff --git a/apps/server/src/services/resources.ts b/apps/server/src/services/resources.tsindex a51c4f1a62..e1c1c2c4bf 100644--- a/apps/server/src/services/resources.ts+++ b/apps/server/src/services/resources.ts@@ -27,6 +27,8 @@ export interface ResourceDefinition {version: string;title(): string;description(): string;+ /** Boxicons classes, `bx bx-…`, for the download dialog. */+ icon: string;files: ResourceFile[];/*** Returns a directory that holds the files outside the manager, such as a model installed by@@ -192,6 +194,7 @@ export class ResourceManager {id: definition.id,title: definition.title(),description: definition.description(),+ icon: definition.icon,size: sumSizes(definition.files),downloadedSize: sumSizes(downloaded),sources: [ ...new Set(definition.files.map(({ url }) => new URL(url).hostname)) ],diff --git a/packages/commons/src/lib/resources.ts b/packages/commons/src/lib/resources.tsindex 65876ce195..87e1c37807 100644--- a/packages/commons/src/lib/resources.ts+++ b/packages/commons/src/lib/resources.ts@@ -9,6 +9,8 @@ export interface ResourceInfo {id: string;title: string;description: string;+ /** Boxicons classes, `bx bx-…`. */+ icon: string;/** The size of all its files, in bytes. */size: number;/** The bytes of its files already downloaded and verified, kept from an interrupted download. */