@domicile-desktop/system-apps 0.0.0-alpha-59d60d9540df → 0.0.0-alpha-75f1c331c3ad

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Installed applications and bookmarks for a shell's launcher, read through
4
4
  [`@domicile-desktop/sdk/system`](../chrome-sdk/README.md). Manganese's launcher
5
- uses it (`src/launcher/app-search.ts`).
5
+ uses it (`src/launcher/app-search.ts`), and the component library's portal
6
+ dialogs name applications with it.
6
7
 
7
8
  ## Usage
8
9
 
@@ -28,6 +29,7 @@ const editors = findApps(apps, "edit", 50);
28
29
  | `./installed` | Every desktop entry under them; an earlier directory hides a later one's ID. |
29
30
  | `./desktop-entry` | One entry parsed: name, comment, argv, icon and `X-Domicile-Preview`. |
30
31
  | `./find-apps`, `./bookmark` | The launcher's matching and ranking; bookmarks and their Zod schema. |
32
+ | `./describe-apps` | Application IDs named and drawn by their entries, for a shell to say who asks. |
31
33
  | `./mime-apps` | A content type's default applications from every `mimeapps.list`, the desktop's own (`domicile-mimeapps.list`) first. |
32
34
  | `./omit` | Desktop file IDs left out, as globs. |
33
35
  | `./app-icons` | Icon names resolved in `hicolor` and `pixmaps` to `data:` URLs (PNG, SVG, 128 KiB at most). |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dependencies": {
3
3
  "@cprussin/option-result": "^2.0.1",
4
- "@domicile-desktop/sdk": "0.0.0-alpha-59d60d9540df",
4
+ "@domicile-desktop/sdk": "0.0.0-alpha-75f1c331c3ad",
5
5
  "zod": "^4.5.4"
6
6
  },
7
7
  "description": "Installed applications and bookmarks for a Domicile shell's launcher, read through @domicile-desktop/sdk/system.",
@@ -16,6 +16,7 @@
16
16
  "./bookmark": "./src/bookmark.ts",
17
17
  "./curl": "./src/curl.ts",
18
18
  "./data-dirs": "./src/data-dirs.ts",
19
+ "./describe-apps": "./src/describe-apps.ts",
19
20
  "./desktop-entry": "./src/desktop-entry.ts",
20
21
  "./fake-system": "./src/fake-system.ts",
21
22
  "./favicon": "./src/favicon.ts",
@@ -46,5 +47,5 @@
46
47
  "test:unit": "bun test"
47
48
  },
48
49
  "type": "module",
49
- "version": "0.0.0-alpha-59d60d9540df"
50
+ "version": "0.0.0-alpha-75f1c331c3ad"
50
51
  }
@@ -0,0 +1,60 @@
1
+ // Applications named and drawn by their desktop entries, for a shell to show
2
+ // who asks for something.
3
+
4
+ import type { Option } from "@cprussin/option-result";
5
+ import { None, Ok, Result } from "@cprussin/option-result";
6
+ import type { System, SystemError } from "@domicile-desktop/sdk/system";
7
+
8
+ import type { IconLookup } from "./app-icons";
9
+ import { appIcons } from "./app-icons";
10
+ import { dataDirs } from "./data-dirs";
11
+ import type { DesktopEntry } from "./desktop-entry";
12
+ import { installedApps } from "./installed";
13
+
14
+ /** An application, as its desktop entry describes it. */
15
+ export type DescribedApp = {
16
+ /** Its desktop file ID without `.desktop`, as portals and windows name it. */
17
+ id: string;
18
+ /** Its entry's `Name`, or `id` when it has no entry. */
19
+ name: string;
20
+ /** A `data:` URL, or `undefined` for none. */
21
+ icon: string | undefined;
22
+ };
23
+
24
+ /** Each of `ids`, in order, described by its installed desktop entry. */
25
+ export const describeApps = async (
26
+ system: System,
27
+ ids: readonly string[],
28
+ ): Promise<Result<DescribedApp[], SystemError>> =>
29
+ (await dataDirs(system)).andThenAsync(async (dirs) => {
30
+ const icons = appIcons(system, dirs);
31
+ return (await installedApps(system, dirs)).andThenAsync(
32
+ async (installed) => {
33
+ const entries = new Map(
34
+ installed.map((entry) => [entry.id.replace(/\.desktop$/, ""), entry]),
35
+ );
36
+ return Result.collect(
37
+ await Promise.all(
38
+ ids.map((id) => described(icons, id, entries.get(id))),
39
+ ),
40
+ );
41
+ },
42
+ );
43
+ });
44
+
45
+ /** App `id`, named and drawn by its `entry` when it has one. */
46
+ const described = async (
47
+ icons: IconLookup,
48
+ id: string,
49
+ entry: DesktopEntry | undefined,
50
+ ): Promise<Result<DescribedApp, SystemError>> =>
51
+ entry === undefined
52
+ ? Ok({ icon: undefined, id, name: id })
53
+ : (entry.icon === undefined
54
+ ? Ok<Option<string>, SystemError>(None())
55
+ : await icons(entry.icon)
56
+ ).map((icon) => ({
57
+ icon: icon.match({ None: () => undefined, Some: (url) => url }),
58
+ id,
59
+ name: entry.name,
60
+ }));