@domicile-desktop/system-apps 0.0.0-alpha-eaa92c7f029b → 0.0.0-alpha-53d80caa357f
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/package.json +4 -3
- package/src/data-dirs.ts +25 -6
- package/src/desktop-entry.ts +21 -6
- package/src/installed.ts +13 -6
- package/src/openers.ts +30 -24
- package/src/terminal.ts +45 -0
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-
|
|
4
|
+
"@domicile-desktop/sdk": "0.0.0-alpha-53d80caa357f",
|
|
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.",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"./omit": "./src/omit.ts",
|
|
33
33
|
"./opener": "./src/opener.ts",
|
|
34
34
|
"./openers": "./src/openers.ts",
|
|
35
|
-
"./opens": "./src/opens.ts"
|
|
35
|
+
"./opens": "./src/opens.ts",
|
|
36
|
+
"./terminal": "./src/terminal.ts"
|
|
36
37
|
},
|
|
37
38
|
"files": [
|
|
38
39
|
"src/**",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"test:unit": "bun test"
|
|
56
57
|
},
|
|
57
58
|
"type": "module",
|
|
58
|
-
"version": "0.0.0-alpha-
|
|
59
|
+
"version": "0.0.0-alpha-53d80caa357f"
|
|
59
60
|
}
|
package/src/data-dirs.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
|
6
6
|
import type { AppsDesktop } from "./apps-desktop";
|
|
7
7
|
|
|
8
8
|
import { desktopEnvironment, setVariable } from "./environment";
|
|
9
|
+
import { terminalOf } from "./terminal";
|
|
9
10
|
|
|
10
11
|
/** The spec's default for an unset or empty `XDG_DATA_DIRS`. */
|
|
11
12
|
const DEFAULT_DATA_DIRS = "/usr/local/share:/usr/share";
|
|
@@ -21,9 +22,27 @@ const DEFAULT_DATA_DIRS = "/usr/local/share:/usr/share";
|
|
|
21
22
|
export const dataDirs = async (
|
|
22
23
|
domicile: AppsDesktop,
|
|
23
24
|
): Promise<Result<string[], SystemError>> =>
|
|
24
|
-
(await desktopEnvironment(domicile)).map(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
(await desktopEnvironment(domicile)).map(dataDirsOf);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* {@link dataDirs} and the desk's terminal (see `./terminal`), from one read
|
|
29
|
+
* of the environment: what listing the applications takes.
|
|
30
|
+
*/
|
|
31
|
+
export const appPlaces = async (
|
|
32
|
+
domicile: AppsDesktop,
|
|
33
|
+
): Promise<
|
|
34
|
+
Result<
|
|
35
|
+
{ dirs: string[]; terminal: readonly string[] | undefined },
|
|
36
|
+
SystemError
|
|
37
|
+
>
|
|
38
|
+
> =>
|
|
39
|
+
(await desktopEnvironment(domicile)).map((variables) => ({
|
|
40
|
+
dirs: dataDirsOf(variables),
|
|
41
|
+
terminal: terminalOf(variables),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
/** The data directories `variables` name. */
|
|
45
|
+
const dataDirsOf = (variables: ReadonlyMap<string, string>): string[] => [
|
|
46
|
+
setVariable(variables, "XDG_DATA_HOME") ?? ".local/share",
|
|
47
|
+
...(setVariable(variables, "XDG_DATA_DIRS") ?? DEFAULT_DATA_DIRS).split(":"),
|
|
48
|
+
];
|
package/src/desktop-entry.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type DesktopEntry = {
|
|
|
17
17
|
name: string;
|
|
18
18
|
/** Empty for an entry with no `Comment`. */
|
|
19
19
|
comment: string;
|
|
20
|
-
/** The argv it runs. */
|
|
20
|
+
/** The argv it runs: in the desk's terminal, for a `Terminal` entry. */
|
|
21
21
|
command: readonly string[];
|
|
22
22
|
/** `Exec` as written, for `commandOf` to open a file with. */
|
|
23
23
|
exec: string;
|
|
@@ -31,34 +31,42 @@ export type DesktopEntry = {
|
|
|
31
31
|
preview: string | undefined;
|
|
32
32
|
/** `StartupWMClass`: the app id of the window it opens, if not its own id. */
|
|
33
33
|
windowClass: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The desk's terminal, which this `Terminal=true` entry runs in, as htop
|
|
36
|
+
* and vim do; `undefined` for an application with windows of its own.
|
|
37
|
+
*/
|
|
38
|
+
terminal: readonly string[] | undefined;
|
|
34
39
|
};
|
|
35
40
|
|
|
36
41
|
/**
|
|
37
42
|
* Entry `text` as `id`, or nothing if a launcher should not offer it.
|
|
38
43
|
*
|
|
39
44
|
* Reads only unlocalized keys in `[Desktop Entry]`. Rejects non-applications,
|
|
40
|
-
* `Hidden` entries
|
|
41
|
-
* `Terminal`
|
|
42
|
-
*
|
|
45
|
+
* `Hidden` entries and entries without a `Name` or a readable `Exec`. A
|
|
46
|
+
* `Terminal` entry runs in `terminal`, the desk's (see `./terminal`), and is
|
|
47
|
+
* rejected when there is none. Rejects `NoDisplay` entries too, unless
|
|
48
|
+
* `shown` is false: such an entry still opens files.
|
|
43
49
|
*/
|
|
44
50
|
export const parseDesktopEntry = (
|
|
45
51
|
id: string,
|
|
46
52
|
text: string,
|
|
47
53
|
shown = true,
|
|
54
|
+
terminal?: readonly string[],
|
|
48
55
|
): Option<DesktopEntry> => {
|
|
49
56
|
const keys = keysOf(text);
|
|
50
57
|
const flag = (key: string) => keys.get(key) === "true";
|
|
51
58
|
const name = keys.get("Name");
|
|
52
59
|
const exec = keys.get("Exec");
|
|
60
|
+
const runsIn = flag("Terminal") ? terminal : undefined;
|
|
53
61
|
return keys.get("Type") !== "Application" ||
|
|
54
62
|
flag("Hidden") ||
|
|
55
63
|
(shown && flag("NoDisplay")) ||
|
|
56
|
-
flag("Terminal") ||
|
|
64
|
+
(flag("Terminal") && terminal === undefined) ||
|
|
57
65
|
name === undefined ||
|
|
58
66
|
exec === undefined
|
|
59
67
|
? None()
|
|
60
68
|
: commandOf(exec).map((command) => ({
|
|
61
|
-
command,
|
|
69
|
+
command: inTerminal(runsIn, command),
|
|
62
70
|
comment: unescaped(keys.get("Comment") ?? ""),
|
|
63
71
|
exec,
|
|
64
72
|
icon: optional(keys.get("Icon")),
|
|
@@ -68,6 +76,7 @@ export const parseDesktopEntry = (
|
|
|
68
76
|
.filter((type) => type !== ""),
|
|
69
77
|
name: unescaped(name),
|
|
70
78
|
preview: optional(keys.get("X-Domicile-Preview")),
|
|
79
|
+
terminal: runsIn,
|
|
71
80
|
windowClass: optional(keys.get("StartupWMClass")),
|
|
72
81
|
words: [name, keys.get("GenericName") ?? "", keys.get("Keywords") ?? ""]
|
|
73
82
|
.map(unescaped)
|
|
@@ -76,6 +85,12 @@ export const parseDesktopEntry = (
|
|
|
76
85
|
}));
|
|
77
86
|
};
|
|
78
87
|
|
|
88
|
+
/** `command`, run in `terminal` if there is one. */
|
|
89
|
+
export const inTerminal = (
|
|
90
|
+
terminal: readonly string[] | undefined,
|
|
91
|
+
command: readonly string[],
|
|
92
|
+
): string[] => [...(terminal ?? []), ...command];
|
|
93
|
+
|
|
79
94
|
/** The `[Desktop Entry]` group's keys; the first of a repeated key wins. */
|
|
80
95
|
const keysOf = (text: string): ReadonlyMap<string, string> => {
|
|
81
96
|
const keys = new Map<string, string>();
|
package/src/installed.ts
CHANGED
|
@@ -14,7 +14,9 @@ import { allOk, orAbsent } from "./results";
|
|
|
14
14
|
type EntryFile = { id: string; path: string };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Every application in `applications/` under `dataDirs`, unordered.
|
|
17
|
+
* Every application in `applications/` under `dataDirs`, unordered. A
|
|
18
|
+
* `Terminal` entry runs in `terminal`, the desk's (see `./terminal`), and is
|
|
19
|
+
* left out without one.
|
|
18
20
|
*
|
|
19
21
|
* `dataDirs` is highest priority first (see `./data-dirs`). An ID in an
|
|
20
22
|
* earlier directory hides the same ID in later ones, even when the earlier
|
|
@@ -24,6 +26,7 @@ type EntryFile = { id: string; path: string };
|
|
|
24
26
|
export const installedApps = async (
|
|
25
27
|
domicile: AppsDesktop,
|
|
26
28
|
dataDirs: readonly string[],
|
|
29
|
+
terminal?: readonly string[],
|
|
27
30
|
): Promise<Result<DesktopEntry[], SystemError>> => {
|
|
28
31
|
const listed = allOk(
|
|
29
32
|
await Promise.all(
|
|
@@ -34,7 +37,9 @@ export const installedApps = async (
|
|
|
34
37
|
await listed.andThenAsync(async (dirs) =>
|
|
35
38
|
allOk(
|
|
36
39
|
await Promise.all(
|
|
37
|
-
firstOfEach(dirs.flat()).map((file) =>
|
|
40
|
+
firstOfEach(dirs.flat()).map((file) =>
|
|
41
|
+
read(domicile, file, true, terminal),
|
|
42
|
+
),
|
|
38
43
|
),
|
|
39
44
|
),
|
|
40
45
|
)
|
|
@@ -48,12 +53,13 @@ export const installedApps = async (
|
|
|
48
53
|
/**
|
|
49
54
|
* The application whose ID is `id`, `NoDisplay` or not, or nothing if none
|
|
50
55
|
* is usable. As `installedApps`, an ID in an earlier directory hides later
|
|
51
|
-
* ones
|
|
56
|
+
* ones, and a `Terminal` entry needs `terminal`.
|
|
52
57
|
*/
|
|
53
58
|
export const installedApp = async (
|
|
54
59
|
domicile: AppsDesktop,
|
|
55
60
|
dataDirs: readonly string[],
|
|
56
61
|
id: string,
|
|
62
|
+
terminal?: readonly string[],
|
|
57
63
|
): Promise<Result<Option<DesktopEntry>, SystemError>> =>
|
|
58
64
|
await allOk(
|
|
59
65
|
await Promise.all(
|
|
@@ -63,7 +69,7 @@ export const installedApp = async (
|
|
|
63
69
|
const file = firstOfEach(dirs.flat()).find((each) => each.id === id);
|
|
64
70
|
return file === undefined
|
|
65
71
|
? Promise.resolve(Ok(None<DesktopEntry>()))
|
|
66
|
-
: read(domicile, file, false);
|
|
72
|
+
: read(domicile, file, false, terminal);
|
|
67
73
|
});
|
|
68
74
|
|
|
69
75
|
/** Each ID's first file, in priority order. */
|
|
@@ -80,11 +86,12 @@ const firstOfEach = (files: readonly EntryFile[]): EntryFile[] => {
|
|
|
80
86
|
const read = async (
|
|
81
87
|
domicile: AppsDesktop,
|
|
82
88
|
{ id, path }: EntryFile,
|
|
83
|
-
shown
|
|
89
|
+
shown: boolean,
|
|
90
|
+
terminal: readonly string[] | undefined,
|
|
84
91
|
) =>
|
|
85
92
|
orAbsent(
|
|
86
93
|
(await domicile.files.readText(path)).map((text) =>
|
|
87
|
-
parseDesktopEntry(id, text, shown),
|
|
94
|
+
parseDesktopEntry(id, text, shown, terminal),
|
|
88
95
|
),
|
|
89
96
|
None<DesktopEntry>(),
|
|
90
97
|
);
|
package/src/openers.ts
CHANGED
|
@@ -9,12 +9,14 @@ import type { AppsDesktop } from "./apps-desktop";
|
|
|
9
9
|
import { contentTypeOf } from "./content-type";
|
|
10
10
|
import { dataDirs } from "./data-dirs";
|
|
11
11
|
import type { DesktopEntry } from "./desktop-entry";
|
|
12
|
+
import { inTerminal } from "./desktop-entry";
|
|
12
13
|
import { desktopEnvironment, setVariable } from "./environment";
|
|
13
14
|
import { commandOf } from "./exec";
|
|
14
15
|
import { installedApp, installedApps } from "./installed";
|
|
15
16
|
import { defaultApps } from "./mime-apps";
|
|
16
17
|
import { allOk } from "./results";
|
|
17
18
|
import { supertypesOf } from "./supertypes";
|
|
19
|
+
import { terminalOf } from "./terminal";
|
|
18
20
|
|
|
19
21
|
/** What can open a file. */
|
|
20
22
|
export type Openers = {
|
|
@@ -48,16 +50,17 @@ export const openers = async (
|
|
|
48
50
|
): Promise<Result<Openers, SystemError>> =>
|
|
49
51
|
(await desktopEnvironment(domicile)).andThenAsync(async (variables) => {
|
|
50
52
|
const file = path.startsWith("/") ? path : `${homeOf(variables)}/${path}`;
|
|
53
|
+
const terminal = terminalOf(variables);
|
|
51
54
|
return (await dataDirs(domicile)).andThenAsync(async (dirs) =>
|
|
52
55
|
(await contentTypeOf(domicile, dirs, path)).andThenAsync(
|
|
53
56
|
async (contentType) =>
|
|
54
57
|
(
|
|
55
58
|
await contentType.match({
|
|
56
59
|
None: () => Promise.resolve(Ok<DesktopEntry[], SystemError>([])),
|
|
57
|
-
Some: (type) => appsFor(domicile, dirs, type),
|
|
60
|
+
Some: (type) => appsFor(domicile, dirs, type, terminal),
|
|
58
61
|
})
|
|
59
62
|
).andThenAsync(async (apps) =>
|
|
60
|
-
(await openedWith(domicile, dirs, file)).map((first) => ({
|
|
63
|
+
(await openedWith(domicile, dirs, file, terminal)).map((first) => ({
|
|
61
64
|
apps: first.match({
|
|
62
65
|
None: () => apps,
|
|
63
66
|
Some: (app) => [app, ...apps.filter(({ id }) => id !== app.id)],
|
|
@@ -79,6 +82,7 @@ const openedWith = async (
|
|
|
79
82
|
domicile: AppsDesktop,
|
|
80
83
|
dirs: readonly string[],
|
|
81
84
|
file: string,
|
|
85
|
+
terminal: readonly string[] | undefined,
|
|
82
86
|
): Promise<Result<Option<DesktopEntry>, SystemError>> =>
|
|
83
87
|
(
|
|
84
88
|
await domicile.processes.run(["domicile", "open", "--which", file])
|
|
@@ -86,7 +90,7 @@ const openedWith = async (
|
|
|
86
90
|
const id = stdout.trim();
|
|
87
91
|
return code !== 0 || id === ""
|
|
88
92
|
? Promise.resolve(Ok(None<DesktopEntry>()))
|
|
89
|
-
: installedApp(domicile, dirs, id);
|
|
93
|
+
: installedApp(domicile, dirs, id, terminal);
|
|
90
94
|
});
|
|
91
95
|
|
|
92
96
|
/** The installed applications for `contentType`, in `Openers.apps`'s order. */
|
|
@@ -94,28 +98,30 @@ const appsFor = async (
|
|
|
94
98
|
domicile: AppsDesktop,
|
|
95
99
|
dirs: readonly string[],
|
|
96
100
|
contentType: string,
|
|
101
|
+
terminal: readonly string[] | undefined,
|
|
97
102
|
): Promise<Result<DesktopEntry[], SystemError>> =>
|
|
98
|
-
(await installedApps(domicile, dirs)).andThenAsync(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
103
|
+
(await installedApps(domicile, dirs, terminal)).andThenAsync(
|
|
104
|
+
async (installed) =>
|
|
105
|
+
(await supertypesOf(domicile, dirs, contentType)).andThenAsync(
|
|
106
|
+
async (supertypes) => {
|
|
107
|
+
const types = [contentType, ...supertypes];
|
|
108
|
+
return allOk(
|
|
109
|
+
await Promise.all(types.map((type) => defaultApps(domicile, type))),
|
|
110
|
+
).map((defaults) => {
|
|
111
|
+
const byId = new Map(installed.map((app) => [app.id, app]));
|
|
112
|
+
const first = defaults.flat().flatMap((id) => {
|
|
113
|
+
const app = byId.get(id);
|
|
114
|
+
return app === undefined ? [] : [app];
|
|
115
|
+
});
|
|
116
|
+
const rest = types.flatMap((type) =>
|
|
117
|
+
installed
|
|
118
|
+
.filter((app) => app.mimeTypes.includes(type))
|
|
119
|
+
.toSorted((a, b) => a.name.localeCompare(b.name)),
|
|
120
|
+
);
|
|
121
|
+
return [...new Set([...first, ...rest])];
|
|
109
122
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.filter((app) => app.mimeTypes.includes(type))
|
|
113
|
-
.toSorted((a, b) => a.name.localeCompare(b.name)),
|
|
114
|
-
);
|
|
115
|
-
return [...new Set([...first, ...rest])];
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
),
|
|
123
|
+
},
|
|
124
|
+
),
|
|
119
125
|
);
|
|
120
126
|
|
|
121
127
|
const homeOf = (variables: ReadonlyMap<string, string>): string => {
|
|
@@ -133,5 +139,5 @@ const commandFor = (app: DesktopEntry, file: string): string[] =>
|
|
|
133
139
|
None: () => {
|
|
134
140
|
throw new Error(`${app.id}'s Exec could not be read again`);
|
|
135
141
|
},
|
|
136
|
-
Some: (command) => command,
|
|
142
|
+
Some: (command) => inTerminal(app.terminal, command),
|
|
137
143
|
});
|
package/src/terminal.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The terminal the desk's config names, which `Terminal=true` applications
|
|
2
|
+
// such as htop and vim run in. See `domicile_host::desk_terminal`.
|
|
3
|
+
|
|
4
|
+
import type { Option, Result } from "@cprussin/option-result";
|
|
5
|
+
import { None, Some } from "@cprussin/option-result";
|
|
6
|
+
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
7
|
+
import type { AppsDesktop } from "./apps-desktop";
|
|
8
|
+
|
|
9
|
+
import { desktopEnvironment, setVariable } from "./environment";
|
|
10
|
+
|
|
11
|
+
/** The variable the compositor puts the config's `terminal` in, as JSON. */
|
|
12
|
+
export const TERMINAL_VARIABLE = "DOMICILE_TERMINAL";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The desk's terminal: an argv that opens one on its own, and runs an
|
|
16
|
+
* application's argv put after it. Nothing when the config names none, since
|
|
17
|
+
* Domicile has no default terminal.
|
|
18
|
+
*/
|
|
19
|
+
export const deskTerminal = async (
|
|
20
|
+
domicile: AppsDesktop,
|
|
21
|
+
): Promise<Result<Option<readonly string[]>, SystemError>> =>
|
|
22
|
+
(await desktopEnvironment(domicile)).map((variables) => {
|
|
23
|
+
const terminal = terminalOf(variables);
|
|
24
|
+
return terminal === undefined ? None() : Some(terminal);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** The terminal `variables` name, or `undefined` for none or a bad value. */
|
|
28
|
+
export const terminalOf = (
|
|
29
|
+
variables: ReadonlyMap<string, string>,
|
|
30
|
+
): readonly string[] | undefined => {
|
|
31
|
+
const value = setVariable(variables, TERMINAL_VARIABLE);
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const argv: unknown = JSON.parse(value);
|
|
37
|
+
return Array.isArray(argv) &&
|
|
38
|
+
argv.length > 0 &&
|
|
39
|
+
argv.every((word) => typeof word === "string")
|
|
40
|
+
? (argv as string[])
|
|
41
|
+
: undefined;
|
|
42
|
+
} catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|