@domicile-desktop/system-apps 0.0.0-alpha-56dd6c187f4e → 0.0.0-alpha-c15ba93d1d2b

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
@@ -1,20 +1,21 @@
1
1
  # @domicile-desktop/system-apps
2
2
 
3
- Installed applications and bookmarks for a shell's launcher, read through
4
- [`@domicile-desktop/sdk/system`](../chrome-sdk/README.md). Manganese's launcher
3
+ Installed applications and bookmarks for a shell's launcher, read through the
4
+ `files`, `processes` and `dbus` namespaces of
5
+ [`desktop(domicile)`](../chrome-sdk/README.md). Manganese's launcher
5
6
  uses it (`src/launcher/app-search.ts`), and the component library's portal
6
7
  dialogs name applications with it.
7
8
 
8
9
  ## Usage
9
10
 
10
11
  ```ts
11
- import { system } from "@domicile-desktop/sdk/system";
12
+ import { desktop } from "@domicile-desktop/sdk/desktop/desktop";
12
13
  import { appIcons } from "@domicile-desktop/system-apps/app-icons";
13
14
  import { dataDirs } from "@domicile-desktop/system-apps/data-dirs";
14
15
  import { findApps } from "@domicile-desktop/system-apps/find-apps";
15
16
  import { installedApps } from "@domicile-desktop/system-apps/installed";
16
17
 
17
- const host = system(domicile);
18
+ const host = desktop(domicile);
18
19
  const dirs = (await dataDirs(host)).unwrapOr([]);
19
20
  const apps = (await installedApps(host, dirs)).unwrapOr([]);
20
21
  const icon = appIcons(host, dirs);
@@ -25,6 +26,7 @@ const editors = findApps(apps, "edit", 50);
25
26
 
26
27
  | Module | What it is |
27
28
  | --- | --- |
29
+ | `./apps-desktop` | `AppsDesktop`: the slice of `desktop(domicile)` the library calls. |
28
30
  | `./data-dirs` | The XDG data directories, from the desktop's environment (`env -0`). |
29
31
  | `./installed` | Every desktop entry under them; an earlier directory hides a later one's ID. |
30
32
  | `./desktop-entry` | One entry parsed: name, comment, argv, icon and `X-Domicile-Preview`. |
@@ -35,7 +37,7 @@ const editors = findApps(apps, "edit", 50);
35
37
  | `./omit` | Desktop file IDs left out, as globs. |
36
38
  | `./app-icons` | Icon names resolved to `data:` URLs (PNG, SVG, 128 KiB at most) by the icon theme spec: a theme, its `Inherits`, `hicolor`, then `pixmaps`, at the size asked for, in `apps` or the contexts given. `themedIcons` falls back to `<name>-symbolic` and says which icons are symbolic. Pass the theme `readIconTheme` reads. |
37
39
  | `./favicon`, `./curl`, `./favicons` | A bookmark's icon: picked from the page, fetched with `curl`, kept and retried. |
38
- | `./fake-system` | A `System` over an in-memory tree, for tests. Its Settings portal serves the icon theme it is given. |
40
+ | `./fake-desktop` | A desktop's `files`, `processes` and `dbus` over an in-memory tree, for tests. Its Settings portal serves the icon theme it is given. |
39
41
 
40
42
  - Calls resolve `Result`s with the SDK's `SystemError`; a missing or
41
43
  unreadable file or directory is skipped, as the specs say.
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-56dd6c187f4e",
4
+ "@domicile-desktop/sdk": "0.0.0-alpha-c15ba93d1d2b",
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.",
@@ -18,12 +18,13 @@
18
18
  "exports": {
19
19
  "./app-icons": "./src/app-icons.ts",
20
20
  "./app-id-name": "./src/app-id-name.ts",
21
+ "./apps-desktop": "./src/apps-desktop.ts",
21
22
  "./bookmark": "./src/bookmark.ts",
22
23
  "./curl": "./src/curl.ts",
23
24
  "./data-dirs": "./src/data-dirs.ts",
24
25
  "./describe-apps": "./src/describe-apps.ts",
25
26
  "./desktop-entry": "./src/desktop-entry.ts",
26
- "./fake-system": "./src/fake-system.ts",
27
+ "./fake-desktop": "./src/fake-desktop.ts",
27
28
  "./favicon": "./src/favicon.ts",
28
29
  "./favicons": "./src/favicons.ts",
29
30
  "./find-apps": "./src/find-apps.ts",
@@ -53,5 +54,5 @@
53
54
  "test:unit": "bun test"
54
55
  },
55
56
  "type": "module",
56
- "version": "0.0.0-alpha-56dd6c187f4e"
57
+ "version": "0.0.0-alpha-c15ba93d1d2b"
57
58
  }
package/src/app-icons.ts CHANGED
@@ -8,7 +8,8 @@
8
8
 
9
9
  import type { Option, Result } from "@cprussin/option-result";
10
10
  import { None, Ok, Some } from "@cprussin/option-result";
11
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
11
+ import type { SystemError } from "@domicile-desktop/sdk/system";
12
+ import type { AppsDesktop } from "./apps-desktop";
12
13
 
13
14
  import { dataUrl } from "./data-url";
14
15
  import type { ThemeDirectory } from "./icon-theme-index";
@@ -62,12 +63,12 @@ export type IconOptions = {
62
63
 
63
64
  /** {@link themedIcons}' URLs alone, for pictures that keep their own colors. */
64
65
  export const appIcons = (
65
- system: System,
66
+ domicile: AppsDesktop,
66
67
  dataDirs: readonly string[],
67
68
  contexts: readonly string[] = ["apps"],
68
69
  options: IconOptions = {},
69
70
  ): IconLookup => {
70
- const lookup = themedIcons(system, dataDirs, contexts, options);
71
+ const lookup = themedIcons(domicile, dataDirs, contexts, options);
71
72
  return async (name) =>
72
73
  (await lookup(name)).map((icon) => icon.map(({ url }) => url));
73
74
  };
@@ -81,7 +82,7 @@ export const appIcons = (
81
82
  * lookup to see newly installed icons.
82
83
  */
83
84
  export const themedIcons = (
84
- system: System,
85
+ domicile: AppsDesktop,
85
86
  dataDirs: readonly string[],
86
87
  contexts: readonly string[] = ["apps"],
87
88
  { size = 48, theme }: IconOptions = {},
@@ -94,11 +95,13 @@ export const themedIcons = (
94
95
  return (name) => {
95
96
  const known = looked.get(name);
96
97
  if (known === undefined) {
97
- listed ??= listings(system, dataDirs, contexts, theme);
98
+ listed ??= listings(domicile, dataDirs, contexts, theme);
98
99
  const lookup = name.startsWith("/")
99
- ? read(system, name)
100
+ ? read(domicile, name)
100
101
  : listed.then((themes) =>
101
- themes.andThenAsync((each) => orSymbolic(system, each, size, name)),
102
+ themes.andThenAsync((each) =>
103
+ orSymbolic(domicile, each, size, name),
104
+ ),
102
105
  );
103
106
  looked.set(name, lookup);
104
107
  return lookup;
@@ -124,17 +127,17 @@ type Theme = { name: string; directories: readonly ThemeDirectory[] };
124
127
  * search them, then `pixmaps`.
125
128
  */
126
129
  const listings = async (
127
- system: System,
130
+ domicile: AppsDesktop,
128
131
  dataDirs: readonly string[],
129
132
  contexts: readonly string[],
130
133
  theme: string | undefined,
131
134
  ): Promise<Result<Listed[][], SystemError>> => {
132
- const themes = await chain(system, dataDirs, contexts, theme);
135
+ const themes = await chain(domicile, dataDirs, contexts, theme);
133
136
  return themes.andThenAsync(async (each) =>
134
137
  allOk(
135
138
  await Promise.all([
136
- ...each.map((one) => themeListing(system, dataDirs, one)),
137
- pixmaps(system, dataDirs),
139
+ ...each.map((one) => themeListing(domicile, dataDirs, one)),
140
+ pixmaps(domicile, dataDirs),
138
141
  ]),
139
142
  ),
140
143
  );
@@ -145,7 +148,7 @@ const listings = async (
145
148
  * `hicolor`. A theme installed nowhere is skipped.
146
149
  */
147
150
  const chain = async (
148
- system: System,
151
+ domicile: AppsDesktop,
149
152
  dataDirs: readonly string[],
150
153
  contexts: readonly string[],
151
154
  theme: string | undefined,
@@ -156,7 +159,7 @@ const chain = async (
156
159
  return Ok([]);
157
160
  } else {
158
161
  seen.add(name);
159
- const loaded = await loadTheme(system, dataDirs, contexts, name);
162
+ const loaded = await loadTheme(domicile, dataDirs, contexts, name);
160
163
  return loaded.andThenAsync((found) =>
161
164
  found.match({
162
165
  None: () => Promise.resolve(Ok<Theme[], SystemError>([])),
@@ -188,7 +191,7 @@ const chain = async (
188
191
  * `index.theme` found, or nothing if it is not installed.
189
192
  */
190
193
  const loadTheme = async (
191
- system: System,
194
+ domicile: AppsDesktop,
192
195
  dataDirs: readonly string[],
193
196
  contexts: readonly string[],
194
197
  name: string,
@@ -200,7 +203,7 @@ const loadTheme = async (
200
203
  > => {
201
204
  for (const dir of dataDirs) {
202
205
  const text = orAbsent(
203
- (await system.readTextFile(`${dir}/icons/${name}/index.theme`)).map(
206
+ (await domicile.files.readText(`${dir}/icons/${name}/index.theme`)).map(
204
207
  (read): Option<string> => Some(read),
205
208
  ),
206
209
  None(),
@@ -221,7 +224,7 @@ const loadTheme = async (
221
224
  }
222
225
  }
223
226
  return name === HICOLOR
224
- ? (await laidOut(system, dataDirs, contexts)).map((directories) =>
227
+ ? (await laidOut(domicile, dataDirs, contexts)).map((directories) =>
225
228
  Some({ directories, inherits: [] }),
226
229
  )
227
230
  : Ok(None());
@@ -229,16 +232,17 @@ const loadTheme = async (
229
232
 
230
233
  /** `hicolor`'s `<size>/<context>` directories, read from its layout. */
231
234
  const laidOut = async (
232
- system: System,
235
+ domicile: AppsDesktop,
233
236
  dataDirs: readonly string[],
234
237
  contexts: readonly string[],
235
238
  ): Promise<Result<ThemeDirectory[], SystemError>> =>
236
239
  allOk(
237
240
  await Promise.all(
238
241
  dataDirs.map(async (dir) =>
239
- orAbsent(await system.readDir(`${dir}/icons/${HICOLOR}`), []).map(
240
- (entries) => entries.map((entry) => entry.name),
241
- ),
242
+ orAbsent(
243
+ await domicile.files.readDir(`${dir}/icons/${HICOLOR}`),
244
+ [],
245
+ ).map((entries) => entries.map((entry) => entry.name)),
242
246
  ),
243
247
  ),
244
248
  ).map((listed) => {
@@ -284,7 +288,7 @@ const sized = (name: string): Omit<ThemeDirectory, "context">[] => {
284
288
 
285
289
  /** `theme`'s directories that exist, each directory under every data directory. */
286
290
  const themeListing = async (
287
- system: System,
291
+ domicile: AppsDesktop,
288
292
  dataDirs: readonly string[],
289
293
  { directories, name }: Theme,
290
294
  ): Promise<Result<Listed[], SystemError>> => {
@@ -292,10 +296,12 @@ const themeListing = async (
292
296
  await Promise.all(
293
297
  dataDirs.map(async (dir) => {
294
298
  const root = `${dir}/icons/${name}`;
295
- return orAbsent(await system.readDir(root), []).map((entries) => ({
296
- root,
297
- tops: new Set(entries.map((entry) => entry.name)),
298
- }));
299
+ return orAbsent(await domicile.files.readDir(root), []).map(
300
+ (entries) => ({
301
+ root,
302
+ tops: new Set(entries.map((entry) => entry.name)),
303
+ }),
304
+ );
299
305
  }),
300
306
  ),
301
307
  );
@@ -306,7 +312,7 @@ const themeListing = async (
306
312
  present
307
313
  .filter(({ tops }) => tops.has(directory.path.split("/")[0] ?? ""))
308
314
  .map(({ root }) =>
309
- listing(system, `${root}/${directory.path}`, directory),
315
+ listing(domicile, `${root}/${directory.path}`, directory),
310
316
  ),
311
317
  ),
312
318
  ),
@@ -315,21 +321,21 @@ const themeListing = async (
315
321
  };
316
322
 
317
323
  const pixmaps = async (
318
- system: System,
324
+ domicile: AppsDesktop,
319
325
  dataDirs: readonly string[],
320
326
  ): Promise<Result<Listed[], SystemError>> =>
321
327
  allOk(
322
328
  await Promise.all(
323
- dataDirs.map((dir) => listing(system, `${dir}/pixmaps`, undefined)),
329
+ dataDirs.map((dir) => listing(domicile, `${dir}/pixmaps`, undefined)),
324
330
  ),
325
331
  );
326
332
 
327
333
  const listing = async (
328
- system: System,
334
+ domicile: AppsDesktop,
329
335
  dir: string,
330
336
  directory: ThemeDirectory | undefined,
331
337
  ): Promise<Result<Listed, SystemError>> =>
332
- orAbsent(await system.readDir(dir), []).map((entries) => ({
338
+ orAbsent(await domicile.files.readDir(dir), []).map((entries) => ({
333
339
  dir,
334
340
  directory,
335
341
  names: new Set(entries.map((entry) => entry.name)),
@@ -337,15 +343,15 @@ const listing = async (
337
343
 
338
344
  /** `name`'s icon, else its `-symbolic` one's. */
339
345
  const orSymbolic = async (
340
- system: System,
346
+ domicile: AppsDesktop,
341
347
  themes: readonly Listed[][],
342
348
  size: number,
343
349
  name: string,
344
350
  ): Promise<Result<Option<ThemedIcon>, SystemError>> => {
345
- const plain = await named(system, themes, size, name);
351
+ const plain = await named(domicile, themes, size, name);
346
352
  return plain.mapOr(true, (found) => found.isSome()) || name.endsWith(SYMBOLIC)
347
353
  ? plain
348
- : named(system, themes, size, `${name}${SYMBOLIC}`);
354
+ : named(domicile, themes, size, `${name}${SYMBOLIC}`);
349
355
  };
350
356
 
351
357
  /**
@@ -353,7 +359,7 @@ const orSymbolic = async (
353
359
  * directory suits `size` best, earliest listed among equals.
354
360
  */
355
361
  const named = async (
356
- system: System,
362
+ domicile: AppsDesktop,
357
363
  themes: readonly Listed[][],
358
364
  size: number,
359
365
  name: string,
@@ -372,7 +378,7 @@ const named = async (
372
378
  )
373
379
  .toSorted((a, b) => a.distance - b.distance);
374
380
  for (const { path } of candidates) {
375
- const icon = await read(system, path);
381
+ const icon = await read(domicile, path);
376
382
  if (icon.mapOr(true, (found) => found.isSome())) {
377
383
  return icon;
378
384
  }
@@ -383,7 +389,7 @@ const named = async (
383
389
 
384
390
  /** The file at `path` as an icon, or nothing if it cannot be drawn. */
385
391
  const read = async (
386
- system: System,
392
+ domicile: AppsDesktop,
387
393
  path: string,
388
394
  ): Promise<Result<Option<ThemedIcon>, SystemError>> => {
389
395
  const dot = path.lastIndexOf(".");
@@ -391,15 +397,16 @@ const read = async (
391
397
  return mime === undefined
392
398
  ? Ok(None())
393
399
  : orAbsent(
394
- await (await system.stat(path)).andThenAsync(async ({ size }) =>
395
- size > LARGEST
396
- ? Ok(None<ThemedIcon>())
397
- : (await system.readFile(path)).map((bytes) =>
398
- Some({
399
- symbolic: path.slice(0, dot).endsWith(SYMBOLIC),
400
- url: dataUrl(mime, bytes),
401
- }),
402
- ),
400
+ await (await domicile.files.stat(path)).andThenAsync(
401
+ async ({ size }) =>
402
+ size > LARGEST
403
+ ? Ok(None<ThemedIcon>())
404
+ : (await domicile.files.read(path)).map((bytes) =>
405
+ Some({
406
+ symbolic: path.slice(0, dot).endsWith(SYMBOLIC),
407
+ url: dataUrl(mime, bytes),
408
+ }),
409
+ ),
403
410
  ),
404
411
  None(),
405
412
  );
@@ -0,0 +1,12 @@
1
+ // The parts of the desktop the apps library reads through.
2
+
3
+ import type { Dbus } from "@domicile-desktop/sdk/desktop/dbus";
4
+ import type { Files } from "@domicile-desktop/sdk/desktop/files";
5
+ import type { Processes } from "@domicile-desktop/sdk/desktop/processes";
6
+
7
+ /** What the library calls: files and processes, and D-Bus for the icon theme. */
8
+ export type AppsDesktop = {
9
+ readonly dbus: Pick<Dbus, "call">;
10
+ readonly files: Pick<Files, "read" | "readDir" | "readText" | "stat">;
11
+ readonly processes: Pick<Processes, "run" | "spawn">;
12
+ };
@@ -3,8 +3,9 @@
3
3
 
4
4
  import type { Option, Result } from "@cprussin/option-result";
5
5
  import { None, Ok, Some } from "@cprussin/option-result";
6
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
6
+ import type { SystemError } from "@domicile-desktop/sdk/system";
7
7
  import { FileType } from "@domicile-desktop/sdk/system";
8
+ import type { AppsDesktop } from "./apps-desktop";
8
9
 
9
10
  import { globOf } from "./glob";
10
11
  import { allOk, orAbsent } from "./results";
@@ -23,19 +24,20 @@ type Glob = { weight: number; type: string; pattern: string; glob: RegExp };
23
24
  * longest pattern, then the earliest directory.
24
25
  */
25
26
  export const contentTypeOf = async (
26
- system: System,
27
+ domicile: AppsDesktop,
27
28
  dataDirs: readonly string[],
28
29
  path: string,
29
30
  ): Promise<Result<Option<string>, SystemError>> =>
30
- (await system.stat(path)).andThenAsync(async ({ fileType }) =>
31
+ (await domicile.files.stat(path)).andThenAsync(async ({ fileType }) =>
31
32
  fileType === FileType.Directory
32
33
  ? Ok<Option<string>, SystemError>(Some(DIRECTORY))
33
34
  : allOk(
34
35
  await Promise.all(
35
36
  dataDirs.map(async (dir) =>
36
- orAbsent(await system.readTextFile(`${dir}/mime/globs2`), "").map(
37
- globsIn,
38
- ),
37
+ orAbsent(
38
+ await domicile.files.readText(`${dir}/mime/globs2`),
39
+ "",
40
+ ).map(globsIn),
39
41
  ),
40
42
  ),
41
43
  ).map((globs) => matching(globs.flat(), nameOf(path))),
package/src/curl.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // allow its origin to read their answers.
3
3
 
4
4
  import { None, Some } from "@cprussin/option-result";
5
- import type { System } from "@domicile-desktop/sdk/system";
5
+ import type { AppsDesktop } from "./apps-desktop";
6
6
 
7
7
  import type { Fetch, Page } from "./favicon";
8
8
 
@@ -19,10 +19,10 @@ const USER_AGENT =
19
19
  * nothing.
20
20
  */
21
21
  export const curlFetch =
22
- (system: System): Fetch =>
22
+ (domicile: AppsDesktop): Fetch =>
23
23
  async (url) =>
24
24
  (
25
- await system.spawn([
25
+ await domicile.processes.spawn([
26
26
  "curl",
27
27
  "--silent",
28
28
  "--fail",
package/src/data-dirs.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  // https://specifications.freedesktop.org/basedir-spec/latest/.
3
3
 
4
4
  import type { Result } from "@cprussin/option-result";
5
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
5
+ import type { SystemError } from "@domicile-desktop/sdk/system";
6
+ import type { AppsDesktop } from "./apps-desktop";
6
7
 
7
8
  import { desktopEnvironment, setVariable } from "./environment";
8
9
 
@@ -18,9 +19,9 @@ const DEFAULT_DATA_DIRS = "/usr/local/share:/usr/share";
18
19
  * call's path is.
19
20
  */
20
21
  export const dataDirs = async (
21
- system: System,
22
+ domicile: AppsDesktop,
22
23
  ): Promise<Result<string[], SystemError>> =>
23
- (await desktopEnvironment(system)).map((variables) => [
24
+ (await desktopEnvironment(domicile)).map((variables) => [
24
25
  setVariable(variables, "XDG_DATA_HOME") ?? ".local/share",
25
26
  ...(setVariable(variables, "XDG_DATA_DIRS") ?? DEFAULT_DATA_DIRS).split(
26
27
  ":",
@@ -4,11 +4,11 @@
4
4
  import type { Option } from "@cprussin/option-result";
5
5
  import { None, Ok, Result } from "@cprussin/option-result";
6
6
  import { readIconTheme } from "@domicile-desktop/sdk/icon-theme";
7
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
8
-
7
+ import type { SystemError } from "@domicile-desktop/sdk/system";
9
8
  import type { IconLookup } from "./app-icons";
10
9
  import { appIcons } from "./app-icons";
11
10
  import { appIdName } from "./app-id-name";
11
+ import type { AppsDesktop } from "./apps-desktop";
12
12
  import { dataDirs } from "./data-dirs";
13
13
  import type { DesktopEntry } from "./desktop-entry";
14
14
  import { installedApps } from "./installed";
@@ -29,19 +29,19 @@ export type DescribedApp = {
29
29
  * its entry.
30
30
  */
31
31
  export const describeApps = async (
32
- system: System,
32
+ domicile: AppsDesktop,
33
33
  ids: readonly string[],
34
34
  ): Promise<Result<DescribedApp[], SystemError>> => {
35
35
  const [dirs, theme] = await Promise.all([
36
- dataDirs(system),
37
- readIconTheme(system),
36
+ dataDirs(domicile),
37
+ readIconTheme(domicile),
38
38
  ]);
39
39
  return dirs.andThenAsync((found) =>
40
40
  theme.andThenAsync((named) =>
41
41
  describedIn(
42
- system,
42
+ domicile,
43
43
  found,
44
- appIcons(system, found, ["apps"], {
44
+ appIcons(domicile, found, ["apps"], {
45
45
  theme: named.match({ None: () => undefined, Some: (name) => name }),
46
46
  }),
47
47
  ids,
@@ -52,12 +52,12 @@ export const describeApps = async (
52
52
 
53
53
  /** Each of `ids` described by its entry under `dirs`, drawn by `icons`. */
54
54
  const describedIn = async (
55
- system: System,
55
+ domicile: AppsDesktop,
56
56
  dirs: readonly string[],
57
57
  icons: IconLookup,
58
58
  ids: readonly string[],
59
59
  ): Promise<Result<DescribedApp[], SystemError>> =>
60
- (await installedApps(system, dirs)).andThenAsync(async (installed) => {
60
+ (await installedApps(domicile, dirs)).andThenAsync(async (installed) => {
61
61
  return Result.collect(
62
62
  await Promise.all(
63
63
  ids.map((id) => described(icons, id, entryFor(installed, id))),
@@ -1,13 +1,14 @@
1
1
  // The desktop's environment, which a page cannot see.
2
2
 
3
3
  import type { Result } from "@cprussin/option-result";
4
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
4
+ import type { SystemError } from "@domicile-desktop/sdk/system";
5
+ import type { AppsDesktop } from "./apps-desktop";
5
6
 
6
7
  /** The variables the shell's processes start with, read with `env -0`. */
7
8
  export const desktopEnvironment = async (
8
- system: System,
9
+ domicile: AppsDesktop,
9
10
  ): Promise<Result<ReadonlyMap<string, string>, SystemError>> =>
10
- (await system.run(["env", "-0"])).map((ran) => {
11
+ (await domicile.processes.run(["env", "-0"])).map((ran) => {
11
12
  if (ran.code === 0) {
12
13
  return environmentOf(ran.stdout);
13
14
  } else {
@@ -1,14 +1,15 @@
1
- // A `System` over an in-memory tree, for a shell's tests.
1
+ // A desktop's files, processes and D-Bus over an in-memory tree, for a
2
+ // shell's tests.
2
3
 
3
4
  import type { Result } from "@cprussin/option-result";
4
5
  import { Err, Ok } from "@cprussin/option-result";
6
+ import type { AppDomicile } from "@domicile-desktop/sdk/desktop/app-desktop";
5
7
  import type {
6
8
  DbusBody,
7
9
  DirEntry,
8
10
  Ran,
9
11
  Stat,
10
12
  Subprocess,
11
- System,
12
13
  SystemError,
13
14
  } from "@domicile-desktop/sdk/system";
14
15
  import { FileType, SystemErrorKind } from "@domicile-desktop/sdk/system";
@@ -30,7 +31,7 @@ export type Spawned = {
30
31
  code: number;
31
32
  };
32
33
 
33
- export type FakeSystem = System & {
34
+ export type FakeDesktop = AppDomicile & {
34
35
  /** Every path read, listed or statted, in order. */
35
36
  touched: string[];
36
37
  };
@@ -41,15 +42,15 @@ type Tree = Readonly<Record<string, Node>>;
41
42
  const SETTINGS = "org.freedesktop.impl.portal.Settings";
42
43
 
43
44
  /**
44
- * A system whose files are `tree`, keyed by path, with the directories
45
+ * A desktop whose files are `tree`, keyed by path, with the directories
45
46
  * between them implied. `spawned` answers `spawn` and `run`. Its Settings
46
47
  * portal serves `iconTheme`, or no icon theme when `undefined`.
47
48
  */
48
- export const fakeSystem = (
49
+ export const fakeDesktop = (
49
50
  tree: Tree,
50
51
  spawned: (argv: readonly string[]) => Spawned = unexpected,
51
52
  iconTheme: string | undefined = undefined,
52
- ): FakeSystem => {
53
+ ): FakeDesktop => {
53
54
  const touched: string[] = [];
54
55
  const at = (path: string): Result<Found, SystemError> => {
55
56
  touched.push(path);
@@ -62,66 +63,62 @@ export const fakeSystem = (
62
63
  : Err({ kind: SystemErrorKind.IsADirectory, message: path }),
63
64
  );
64
65
  return {
65
- addVirtualMonitor: unexpected,
66
- createDir: unexpected,
67
- dbusCall: (call) =>
68
- call.interface === SETTINGS && call.member === "ReadAll"
69
- ? Promise.resolve(Ok(settings(iconTheme)))
70
- : unexpected(),
71
- dbusMatch: unexpected,
72
- idleWarnings: unexpected,
73
- keymaps: unexpected,
74
- previewWindow: unexpected,
75
- readDir: (path) =>
76
- Promise.resolve(
77
- at(path).andThen((node) =>
78
- typeof node === "string" || node instanceof Uint8Array
79
- ? Err({ kind: SystemErrorKind.NotADirectory, message: path })
80
- : Ok(listing(tree, node.directory)),
81
- ),
82
- ),
83
- readFile: (path) => Promise.resolve(readFile(path)),
84
- readTextFile: (path) =>
85
- Promise.resolve(
86
- readFile(path).map((bytes) => new TextDecoder().decode(bytes)),
87
- ),
88
- run: (argv) => {
89
- const { code, stderr, stdout } = spawned(argv);
90
- const ran: Ran = {
91
- code,
92
- signal: undefined,
93
- stderr,
94
- stdout: new TextDecoder().decode(bytesOf(stdout)),
95
- };
96
- return Promise.resolve(Ok(ran));
66
+ dbus: {
67
+ call: (call) =>
68
+ call.interface === SETTINGS && call.member === "ReadAll"
69
+ ? Promise.resolve(Ok(settings(iconTheme)))
70
+ : unexpected(),
71
+ match: unexpected,
97
72
  },
98
- screenshot: unexpected,
99
- selectKeymap: unexpected,
100
- setWindowStates: unexpected,
101
- shellCommands: unexpected,
102
- spawn: (argv) => Promise.resolve(Ok(subprocess(spawned(argv)))),
103
- stat: (path) =>
104
- Promise.resolve(
105
- at(path).map(
106
- (node): Stat =>
73
+ files: {
74
+ createDir: unexpected,
75
+ read: (path) => Promise.resolve(readFile(path)),
76
+ readDir: (path) =>
77
+ Promise.resolve(
78
+ at(path).andThen((node) =>
107
79
  typeof node === "string" || node instanceof Uint8Array
108
- ? {
109
- fileType: FileType.File,
110
- modifiedMs: undefined,
111
- size: bytesOf(node).byteLength,
112
- }
113
- : {
114
- fileType: FileType.Directory,
115
- modifiedMs: undefined,
116
- size: 0,
117
- },
80
+ ? Err({ kind: SystemErrorKind.NotADirectory, message: path })
81
+ : Ok(listing(tree, node.directory)),
82
+ ),
83
+ ),
84
+ readText: (path) =>
85
+ Promise.resolve(
86
+ readFile(path).map((bytes) => new TextDecoder().decode(bytes)),
87
+ ),
88
+ stat: (path) =>
89
+ Promise.resolve(
90
+ at(path).map(
91
+ (node): Stat =>
92
+ typeof node === "string" || node instanceof Uint8Array
93
+ ? {
94
+ fileType: FileType.File,
95
+ modifiedMs: undefined,
96
+ size: bytesOf(node).byteLength,
97
+ }
98
+ : {
99
+ fileType: FileType.Directory,
100
+ modifiedMs: undefined,
101
+ size: 0,
102
+ },
103
+ ),
118
104
  ),
119
- ),
105
+ watch: unexpected,
106
+ write: unexpected,
107
+ },
108
+ processes: {
109
+ run: (argv) => {
110
+ const { code, stderr, stdout } = spawned(argv);
111
+ const ran: Ran = {
112
+ code,
113
+ signal: undefined,
114
+ stderr,
115
+ stdout: new TextDecoder().decode(bytesOf(stdout)),
116
+ };
117
+ return Promise.resolve(Ok(ran));
118
+ },
119
+ spawn: (argv) => Promise.resolve(Ok(subprocess(spawned(argv)))),
120
+ },
120
121
  touched,
121
- unlockRefusals: unexpected,
122
- watch: unexpected,
123
- windowRequests: unexpected,
124
- writeFile: unexpected,
125
122
  };
126
123
  };
127
124
 
package/src/installed.ts CHANGED
@@ -2,12 +2,9 @@
2
2
 
3
3
  import type { Result } from "@cprussin/option-result";
4
4
  import { None, Ok, Some } from "@cprussin/option-result";
5
- import type {
6
- DirEntry,
7
- System,
8
- SystemError,
9
- } from "@domicile-desktop/sdk/system";
5
+ import type { DirEntry, SystemError } from "@domicile-desktop/sdk/system";
10
6
  import { FileType } from "@domicile-desktop/sdk/system";
7
+ import type { AppsDesktop } from "./apps-desktop";
11
8
 
12
9
  import type { DesktopEntry } from "./desktop-entry";
13
10
  import { parseDesktopEntry } from "./desktop-entry";
@@ -25,19 +22,19 @@ type EntryFile = { id: string; path: string };
25
22
  * directories and unreadable files are skipped.
26
23
  */
27
24
  export const installedApps = async (
28
- system: System,
25
+ domicile: AppsDesktop,
29
26
  dataDirs: readonly string[],
30
27
  ): Promise<Result<DesktopEntry[], SystemError>> => {
31
28
  const listed = allOk(
32
29
  await Promise.all(
33
- dataDirs.map((dir) => entryFiles(system, `${dir}/applications`, "")),
30
+ dataDirs.map((dir) => entryFiles(domicile, `${dir}/applications`, "")),
34
31
  ),
35
32
  );
36
33
  return (
37
34
  await listed.andThenAsync(async (dirs) =>
38
35
  allOk(
39
36
  await Promise.all(
40
- firstOfEach(dirs.flat()).map((file) => read(system, file)),
37
+ firstOfEach(dirs.flat()).map((file) => read(domicile, file)),
41
38
  ),
42
39
  ),
43
40
  )
@@ -59,9 +56,9 @@ const firstOfEach = (files: readonly EntryFile[]): EntryFile[] => {
59
56
  };
60
57
 
61
58
  /** `file` parsed, or nothing for an unreadable file or one not to offer. */
62
- const read = async (system: System, { id, path }: EntryFile) =>
59
+ const read = async (domicile: AppsDesktop, { id, path }: EntryFile) =>
63
60
  orAbsent(
64
- (await system.readTextFile(path)).map((text) =>
61
+ (await domicile.files.readText(path)).map((text) =>
65
62
  parseDesktopEntry(id, text),
66
63
  ),
67
64
  None<DesktopEntry>(),
@@ -72,34 +69,35 @@ const read = async (system: System, { id, path }: EntryFile) =>
72
69
  * its path under `dir`, `/` read as `-`.
73
70
  */
74
71
  const entryFiles = async (
75
- system: System,
72
+ domicile: AppsDesktop,
76
73
  dir: string,
77
74
  prefix: string,
78
75
  ): Promise<Result<EntryFile[], SystemError>> =>
79
- orAbsent(await system.readDir(dir), []).andThenAsync(async (entries) =>
80
- allOk(
81
- await Promise.all(
82
- entries.map((entry) => filesAt(system, dir, prefix, entry)),
83
- ),
84
- ).map((found) => found.flat()),
76
+ orAbsent(await domicile.files.readDir(dir), []).andThenAsync(
77
+ async (entries) =>
78
+ allOk(
79
+ await Promise.all(
80
+ entries.map((entry) => filesAt(domicile, dir, prefix, entry)),
81
+ ),
82
+ ).map((found) => found.flat()),
85
83
  );
86
84
 
87
85
  /** The entry files `entry` in `dir` holds: itself, or those under it. */
88
86
  const filesAt = async (
89
- system: System,
87
+ domicile: AppsDesktop,
90
88
  dir: string,
91
89
  prefix: string,
92
90
  { fileType, name }: DirEntry,
93
91
  ): Promise<Result<EntryFile[], SystemError>> => {
94
92
  const path = `${dir}/${name}`;
95
- const below = () => entryFiles(system, path, `${prefix}${name}-`);
93
+ const below = () => entryFiles(domicile, path, `${prefix}${name}-`);
96
94
  if (fileType === FileType.Directory) {
97
95
  return below();
98
96
  } else if (name.endsWith(".desktop")) {
99
97
  return Ok([{ id: `${prefix}${name}`, path }]);
100
98
  } else if (fileType === FileType.Symlink) {
101
99
  return orAbsent(
102
- (await system.stat(path)).map(({ fileType: target }) =>
100
+ (await domicile.files.stat(path)).map(({ fileType: target }) =>
103
101
  target === FileType.Directory ? Some(target) : None<FileType>(),
104
102
  ),
105
103
  None<FileType>(),
package/src/mime-apps.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  // https://specifications.freedesktop.org/mime-apps-spec/latest/.
3
3
 
4
4
  import type { Result } from "@cprussin/option-result";
5
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
5
+ import type { SystemError } from "@domicile-desktop/sdk/system";
6
+ import type { AppsDesktop } from "./apps-desktop";
6
7
 
7
8
  import { desktopEnvironment, setVariable } from "./environment";
8
9
  import { allOk, orAbsent } from "./results";
@@ -19,14 +20,14 @@ const GROUP = "[Default Applications]";
19
20
  * skipped.
20
21
  */
21
22
  export const defaultApps = async (
22
- system: System,
23
+ domicile: AppsDesktop,
23
24
  contentType: string,
24
25
  ): Promise<Result<string[], SystemError>> =>
25
- (await desktopEnvironment(system)).andThenAsync(async (variables) =>
26
+ (await desktopEnvironment(domicile)).andThenAsync(async (variables) =>
26
27
  allOk(
27
28
  await Promise.all(
28
29
  listPaths(variables).map(async (path) =>
29
- orAbsent(await system.readTextFile(path), "").map((text) =>
30
+ orAbsent(await domicile.files.readText(path), "").map((text) =>
30
31
  defaultsIn(text, contentType),
31
32
  ),
32
33
  ),
package/src/openers.ts CHANGED
@@ -3,7 +3,8 @@
3
3
 
4
4
  import type { Option, Result } from "@cprussin/option-result";
5
5
  import { Ok } from "@cprussin/option-result";
6
- import type { System, SystemError } from "@domicile-desktop/sdk/system";
6
+ import type { SystemError } from "@domicile-desktop/sdk/system";
7
+ import type { AppsDesktop } from "./apps-desktop";
7
8
 
8
9
  import { contentTypeOf } from "./content-type";
9
10
  import { dataDirs } from "./data-dirs";
@@ -36,18 +37,18 @@ export type Openers = {
36
37
  * back to `xdg-open` when this offers nothing.
37
38
  */
38
39
  export const openers = async (
39
- system: System,
40
+ domicile: AppsDesktop,
40
41
  path: string,
41
42
  ): Promise<Result<Openers, SystemError>> =>
42
- (await desktopEnvironment(system)).andThenAsync(async (variables) => {
43
+ (await desktopEnvironment(domicile)).andThenAsync(async (variables) => {
43
44
  const file = path.startsWith("/") ? path : `${homeOf(variables)}/${path}`;
44
- return (await dataDirs(system)).andThenAsync(async (dirs) =>
45
- (await contentTypeOf(system, dirs, path)).andThenAsync(
45
+ return (await dataDirs(domicile)).andThenAsync(async (dirs) =>
46
+ (await contentTypeOf(domicile, dirs, path)).andThenAsync(
46
47
  async (contentType) =>
47
48
  (
48
49
  await contentType.match({
49
50
  None: () => Promise.resolve(Ok<DesktopEntry[], SystemError>([])),
50
- Some: (type) => appsFor(system, dirs, type),
51
+ Some: (type) => appsFor(domicile, dirs, type),
51
52
  })
52
53
  ).map((apps) => ({
53
54
  apps,
@@ -60,12 +61,12 @@ export const openers = async (
60
61
 
61
62
  /** The installed applications for `contentType`, in `Openers.apps`'s order. */
62
63
  const appsFor = async (
63
- system: System,
64
+ domicile: AppsDesktop,
64
65
  dirs: readonly string[],
65
66
  contentType: string,
66
67
  ): Promise<Result<DesktopEntry[], SystemError>> =>
67
- (await installedApps(system, dirs)).andThenAsync(async (installed) =>
68
- (await defaultApps(system, contentType)).map((defaults) => {
68
+ (await installedApps(domicile, dirs)).andThenAsync(async (installed) =>
69
+ (await defaultApps(domicile, contentType)).map((defaults) => {
69
70
  const byId = new Map(installed.map((app) => [app.id, app]));
70
71
  const first = [...new Set(defaults)].flatMap((id) => {
71
72
  const app = byId.get(id);
package/src/results.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Combining the `Result`s of system calls made side by side.
1
+ // Combining the `Result`s of desktop calls made side by side.
2
2
 
3
3
  import type { Result } from "@cprussin/option-result";
4
4
  import { Ok } from "@cprussin/option-result";