Skip to content

Build your personal knowledge base with Trilium Notes

feat(resources): list only the resources on this device

Elian Doran3c1fdac064c9
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 697bc8a79d..00f5523a11 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4641,9 +4641,8 @@
"list_title": "Resources",
"list_description": "Large files that features download when they are first needed, such as the speech recognition models. They are stored on this device and are not synced, so each device downloads its own copy.",
"installed": "Installed",
- "not_downloaded": "Not downloaded",
"partially_downloaded": "{{downloaded}} of {{size}} downloaded",
"space_used": "Space used",
- "no_resources": "No feature on this device uses downloadable resources."
+ "no_resources": "Nothing has been downloaded yet."
}
}
diff --git a/apps/client/src/widgets/type_widgets/options/resources.spec.tsx b/apps/client/src/widgets/type_widgets/options/resources.spec.tsx
index 852b0f76c7..3478933d31 100644
--- a/apps/client/src/widgets/type_widgets/options/resources.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/resources.spec.tsx
@@ -52,7 +52,8 @@ beforeEach(() => {
mocks.resources = [
resource({ id: "test.installed", installed: true, downloadedSize: 10 * MIB, directory: "/data/resources/test.installed-abc" }),
resource({ id: "test.partial", downloadedSize: 4 * MIB }),
- resource({ id: "test.missing" })
+ resource({ id: "test.missing" }),
+ resource({ id: "test.by-hand", installed: true, directory: "/data/transcription-model" })
];
mocks.requests = 0;
mocks.handlers = [];
@@ -71,24 +72,24 @@ async function open() {
}
describe("ResourcesSettings", () => {
- it("lists each resource with its status, the folder of an installed one, and the space used", async () => {
+ it("lists the resources installed or partly downloaded, with their status and folder", async () => {
await open();
const rows = [ ...host.querySelectorAll(".resources-item") ];
expect(rows.map((row) => row.querySelector(".tn-card-option-title")?.textContent))
- .toEqual([ "test.installed", "test.partial", "test.missing" ]);
+ .toEqual([ "test.installed", "test.partial", "test.by-hand" ]);
expect(rows.map((row) => row.querySelector(".resources-status small")?.textContent)).toEqual([
"resources_options.installed",
`resources_options.partially_downloaded {"downloaded":"4.00 MiB","size":"10 MiB"}`,
- "resources_options.not_downloaded"
+ "resources_options.installed"
]);
expect(rows.map((row) => row.querySelector(".directory-stub")?.textContent ?? null))
- .toEqual([ "/data/resources/test.installed-abc", null, null ]);
+ .toEqual([ "/data/resources/test.installed-abc", null, "/data/transcription-model" ]);
expect(host.querySelector(".resources-total .resources-size")?.textContent).toBe("14 MiB");
});
- it("shows an empty state when no feature registers a resource", async () => {
- mocks.resources = [];
+ it("shows an empty state when nothing is downloaded", async () => {
+ mocks.resources = [ resource({ id: "test.missing" }) ];
await open();
expect(host.querySelector(".resources-item")).toBeNull();
diff --git a/apps/client/src/widgets/type_widgets/options/resources.tsx b/apps/client/src/widgets/type_widgets/options/resources.tsx
index af10dc9de5..cc45536eb1 100644
--- a/apps/client/src/widgets/type_widgets/options/resources.tsx
+++ b/apps/client/src/widgets/type_widgets/options/resources.tsx
@@ -13,7 +13,7 @@ import Icon from "../../react/Icon";
import NoItems from "../../react/NoItems";
import OptionsPageHeader from "./components/OptionsPageHeader";
-/** Lists the resources the features of this device can download, and which of them are installed. */
+/** Lists the resources installed on this device, and the ones an interrupted download left partly fetched. */
export default function ResourcesSettings() {
const resources = useResources();
@@ -39,14 +39,18 @@ export default function ResourcesSettings() {
);
}
-/** The registered resources, fetched again whenever a download of any of them ends. */
+/**
+ * The resources installed or partly downloaded, including copies installed by hand, which have no
+ * downloaded bytes. Fetched again whenever a download ends.
+ */
function useResources() {
const [ resources, setResources ] = useState<ResourceInfo[]>();
useEffect(() => {
const refresh = () => {
void server.get<ResourcesStatusResponse>("resources")
- .then((status) => setResources(status.resources));
+ .then((status) => setResources(status.resources.filter(
+ ({ installed, downloadedSize }) => installed || downloadedSize > 0)));
};
const handler = (message: WebSocketMessage) => {
if (message.type === "resource-download" && message.download.status !== "downloading") {
@@ -108,11 +112,8 @@ function getStatusText({ installed, size, downloadedSize }: ResourceInfo) {
if (installed) {
return t("resources_options.installed");
}
- if (downloadedSize > 0) {
- return t("resources_options.partially_downloaded", {
- downloaded: formatSize(downloadedSize, 2, size),
- size: formatSize(size)
- });
- }
- return t("resources_options.not_downloaded");
+ return t("resources_options.partially_downloaded", {
+ downloaded: formatSize(downloadedSize, 2, size),
+ size: formatSize(size)
+ });
}