@domicile-desktop/system-apps 0.0.0-alpha-e455955b57c7 → 0.0.0-alpha-cd52ce30fbe6
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 +2 -2
- package/src/desktop-entry.ts +5 -3
- package/src/installed.ts +28 -3
- package/src/openers.ts +36 -10
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-cd52ce30fbe6",
|
|
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.",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"test:unit": "bun test"
|
|
55
55
|
},
|
|
56
56
|
"type": "module",
|
|
57
|
-
"version": "0.0.0-alpha-
|
|
57
|
+
"version": "0.0.0-alpha-cd52ce30fbe6"
|
|
58
58
|
}
|
package/src/desktop-entry.ts
CHANGED
|
@@ -37,12 +37,14 @@ export type DesktopEntry = {
|
|
|
37
37
|
* Entry `text` as `id`, or nothing if a launcher should not offer it.
|
|
38
38
|
*
|
|
39
39
|
* Reads only unlocalized keys in `[Desktop Entry]`. Rejects non-applications,
|
|
40
|
-
* `Hidden`
|
|
41
|
-
* `
|
|
40
|
+
* `Hidden` entries, entries without a `Name` or a readable `Exec`, and
|
|
41
|
+
* `Terminal` entries, since no terminal is configured. Rejects `NoDisplay`
|
|
42
|
+
* entries too, unless `shown` is false: such an entry still opens files.
|
|
42
43
|
*/
|
|
43
44
|
export const parseDesktopEntry = (
|
|
44
45
|
id: string,
|
|
45
46
|
text: string,
|
|
47
|
+
shown = true,
|
|
46
48
|
): Option<DesktopEntry> => {
|
|
47
49
|
const keys = keysOf(text);
|
|
48
50
|
const flag = (key: string) => keys.get(key) === "true";
|
|
@@ -50,7 +52,7 @@ export const parseDesktopEntry = (
|
|
|
50
52
|
const exec = keys.get("Exec");
|
|
51
53
|
return keys.get("Type") !== "Application" ||
|
|
52
54
|
flag("Hidden") ||
|
|
53
|
-
flag("NoDisplay") ||
|
|
55
|
+
(shown && flag("NoDisplay")) ||
|
|
54
56
|
flag("Terminal") ||
|
|
55
57
|
name === undefined ||
|
|
56
58
|
exec === undefined
|
package/src/installed.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Every application installed in the XDG data directories.
|
|
2
2
|
|
|
3
|
-
import type { Result } from "@cprussin/option-result";
|
|
3
|
+
import type { Option, Result } from "@cprussin/option-result";
|
|
4
4
|
import { None, Ok, Some } from "@cprussin/option-result";
|
|
5
5
|
import type { DirEntry, SystemError } from "@domicile-desktop/sdk/system";
|
|
6
6
|
import { FileType } from "@domicile-desktop/sdk/system";
|
|
@@ -45,6 +45,27 @@ export const installedApps = async (
|
|
|
45
45
|
);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The application whose ID is `id`, `NoDisplay` or not, or nothing if none
|
|
50
|
+
* is usable. As `installedApps`, an ID in an earlier directory hides later
|
|
51
|
+
* ones.
|
|
52
|
+
*/
|
|
53
|
+
export const installedApp = async (
|
|
54
|
+
domicile: AppsDesktop,
|
|
55
|
+
dataDirs: readonly string[],
|
|
56
|
+
id: string,
|
|
57
|
+
): Promise<Result<Option<DesktopEntry>, SystemError>> =>
|
|
58
|
+
await allOk(
|
|
59
|
+
await Promise.all(
|
|
60
|
+
dataDirs.map((dir) => entryFiles(domicile, `${dir}/applications`, "")),
|
|
61
|
+
),
|
|
62
|
+
).andThenAsync((dirs) => {
|
|
63
|
+
const file = firstOfEach(dirs.flat()).find((each) => each.id === id);
|
|
64
|
+
return file === undefined
|
|
65
|
+
? Promise.resolve(Ok(None<DesktopEntry>()))
|
|
66
|
+
: read(domicile, file, false);
|
|
67
|
+
});
|
|
68
|
+
|
|
48
69
|
/** Each ID's first file, in priority order. */
|
|
49
70
|
const firstOfEach = (files: readonly EntryFile[]): EntryFile[] => {
|
|
50
71
|
const seen = new Set<string>();
|
|
@@ -56,10 +77,14 @@ const firstOfEach = (files: readonly EntryFile[]): EntryFile[] => {
|
|
|
56
77
|
};
|
|
57
78
|
|
|
58
79
|
/** `file` parsed, or nothing for an unreadable file or one not to offer. */
|
|
59
|
-
const read = async (
|
|
80
|
+
const read = async (
|
|
81
|
+
domicile: AppsDesktop,
|
|
82
|
+
{ id, path }: EntryFile,
|
|
83
|
+
shown = true,
|
|
84
|
+
) =>
|
|
60
85
|
orAbsent(
|
|
61
86
|
(await domicile.files.readText(path)).map((text) =>
|
|
62
|
-
parseDesktopEntry(id, text),
|
|
87
|
+
parseDesktopEntry(id, text, shown),
|
|
63
88
|
),
|
|
64
89
|
None<DesktopEntry>(),
|
|
65
90
|
);
|
package/src/openers.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// opens it with.
|
|
3
3
|
|
|
4
4
|
import type { Option, Result } from "@cprussin/option-result";
|
|
5
|
-
import { Ok } from "@cprussin/option-result";
|
|
5
|
+
import { None, Ok } from "@cprussin/option-result";
|
|
6
6
|
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
7
7
|
import type { AppsDesktop } from "./apps-desktop";
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ import { dataDirs } from "./data-dirs";
|
|
|
11
11
|
import type { DesktopEntry } from "./desktop-entry";
|
|
12
12
|
import { desktopEnvironment, setVariable } from "./environment";
|
|
13
13
|
import { commandOf } from "./exec";
|
|
14
|
-
import { installedApps } from "./installed";
|
|
14
|
+
import { installedApp, installedApps } from "./installed";
|
|
15
15
|
import { defaultApps } from "./mime-apps";
|
|
16
16
|
import { allOk } from "./results";
|
|
17
17
|
import { supertypesOf } from "./supertypes";
|
|
@@ -36,9 +36,11 @@ export type Openers = {
|
|
|
36
36
|
* What can open `path`: relative to home, as every system call's path is, or
|
|
37
37
|
* absolute.
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
* `
|
|
41
|
-
*
|
|
39
|
+
* The application `domicile open` would run comes first, as
|
|
40
|
+
* `domicile open --which` says, so this agrees with what opening the file
|
|
41
|
+
* does. The rest come from `MimeType`, the defaults and subclasses only:
|
|
42
|
+
* aliases and `mimeapps.list`'s added and removed associations are not read.
|
|
43
|
+
* A launcher falls back to `xdg-open` when this offers nothing.
|
|
42
44
|
*/
|
|
43
45
|
export const openers = async (
|
|
44
46
|
domicile: AppsDesktop,
|
|
@@ -54,15 +56,39 @@ export const openers = async (
|
|
|
54
56
|
None: () => Promise.resolve(Ok<DesktopEntry[], SystemError>([])),
|
|
55
57
|
Some: (type) => appsFor(domicile, dirs, type),
|
|
56
58
|
})
|
|
57
|
-
).
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
).andThenAsync(async (apps) =>
|
|
60
|
+
(await openedWith(domicile, dirs, file)).map((first) => ({
|
|
61
|
+
apps: first.match({
|
|
62
|
+
None: () => apps,
|
|
63
|
+
Some: (app) => [app, ...apps.filter(({ id }) => id !== app.id)],
|
|
64
|
+
}),
|
|
65
|
+
command: (app: DesktopEntry) => commandFor(app, file),
|
|
66
|
+
contentType,
|
|
67
|
+
})),
|
|
68
|
+
),
|
|
62
69
|
),
|
|
63
70
|
);
|
|
64
71
|
});
|
|
65
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The application `domicile open` would run for `file`, or nothing when it
|
|
75
|
+
* would run none. The `domicile` is the running desktop's own, first on its
|
|
76
|
+
* `PATH`.
|
|
77
|
+
*/
|
|
78
|
+
const openedWith = async (
|
|
79
|
+
domicile: AppsDesktop,
|
|
80
|
+
dirs: readonly string[],
|
|
81
|
+
file: string,
|
|
82
|
+
): Promise<Result<Option<DesktopEntry>, SystemError>> =>
|
|
83
|
+
(
|
|
84
|
+
await domicile.processes.run(["domicile", "open", "--which", file])
|
|
85
|
+
).andThenAsync(({ code, stdout }) => {
|
|
86
|
+
const id = stdout.trim();
|
|
87
|
+
return code !== 0 || id === ""
|
|
88
|
+
? Promise.resolve(Ok(None<DesktopEntry>()))
|
|
89
|
+
: installedApp(domicile, dirs, id);
|
|
90
|
+
});
|
|
91
|
+
|
|
66
92
|
/** The installed applications for `contentType`, in `Openers.apps`'s order. */
|
|
67
93
|
const appsFor = async (
|
|
68
94
|
domicile: AppsDesktop,
|