@domicile-desktop/sdk 0.0.0-alpha-bf4214ef2f5b → 0.0.0-alpha-eac3f852668d

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/dist/portal.d.ts CHANGED
@@ -2,8 +2,10 @@ import type { DomicileHost } from "./domicile-host";
2
2
  export declare enum PortalKind {
3
3
  /** A yes/no question, such as whether an application may use the camera. */
4
4
  Access = 0,
5
+ /** Pick an application to open a file or URI with. */
6
+ AppChooser = 1,
5
7
  /** A kind this SDK cannot parse. Answer it with {@link PortalAnswer.Refused}. */
6
- Unknown = 1
8
+ Unknown = 2
7
9
  }
8
10
  /** What every request carries. */
9
11
  export type PortalRequestBase = {
@@ -22,6 +24,18 @@ export type AccessBody = {
22
24
  grantLabel: string | undefined;
23
25
  denyLabel: string | undefined;
24
26
  };
27
+ /** What an app chooser opens, and the applications it offers. */
28
+ export type AppChooserBody = {
29
+ /** Desktop file IDs without `.desktop`. May change while the dialog is up. */
30
+ choices: readonly string[];
31
+ /** The application chosen last time for this content type. */
32
+ lastChoice: string | undefined;
33
+ /** The MIME type being opened. */
34
+ contentType: string | undefined;
35
+ uri: string | undefined;
36
+ /** The file's name, without its directory. */
37
+ filename: string | undefined;
38
+ };
25
39
  export declare const PortalRequest: {
26
40
  Access: (base: PortalRequestBase, body: AccessBody) => {
27
41
  /** The id {@link answerPortalRequest} takes. */
@@ -33,6 +47,16 @@ export declare const PortalRequest: {
33
47
  body: AccessBody;
34
48
  kind: PortalKind.Access;
35
49
  };
50
+ AppChooser: (base: PortalRequestBase, body: AppChooserBody) => {
51
+ /** The id {@link answerPortalRequest} takes. */
52
+ id: number;
53
+ /** The asking application's desktop file id. Empty when unknown. */
54
+ appId: string;
55
+ /** The `<app>` to show the dialog over, or the focused screen when absent. */
56
+ parentAppId: string | undefined;
57
+ body: AppChooserBody;
58
+ kind: PortalKind.AppChooser;
59
+ };
36
60
  Unknown: (base: PortalRequestBase, wireKind: string) => {
37
61
  /** The id {@link answerPortalRequest} takes. */
38
62
  id: number;
@@ -48,15 +72,22 @@ export type PortalRequest = ReturnType<(typeof PortalRequest)[keyof typeof Porta
48
72
  export declare enum PortalAnswerKind {
49
73
  /** The user allowed an {@link PortalKind.Access} request. */
50
74
  Access = 0,
75
+ /** The application the user picked in an {@link PortalKind.AppChooser}. */
76
+ AppChooser = 1,
51
77
  /** The user dismissed or denied the dialog. */
52
- Canceled = 1,
78
+ Canceled = 2,
53
79
  /** The shell has no dialog for this kind. */
54
- Refused = 2
80
+ Refused = 3
55
81
  }
56
82
  export declare const PortalAnswer: {
57
83
  Access: () => {
58
84
  kind: PortalAnswerKind.Access;
59
85
  };
86
+ /** `choice` must be one of the request's `choices`. */
87
+ AppChooser: (choice: string) => {
88
+ choice: string;
89
+ kind: PortalAnswerKind.AppChooser;
90
+ };
60
91
  Canceled: () => {
61
92
  kind: PortalAnswerKind.Canceled;
62
93
  };
package/dist/portal.js CHANGED
@@ -9,8 +9,10 @@ export var PortalKind;
9
9
  (function (PortalKind) {
10
10
  /** A yes/no question, such as whether an application may use the camera. */
11
11
  PortalKind[PortalKind["Access"] = 0] = "Access";
12
+ /** Pick an application to open a file or URI with. */
13
+ PortalKind[PortalKind["AppChooser"] = 1] = "AppChooser";
12
14
  /** A kind this SDK cannot parse. Answer it with {@link PortalAnswer.Refused}. */
13
- PortalKind[PortalKind["Unknown"] = 1] = "Unknown";
15
+ PortalKind[PortalKind["Unknown"] = 2] = "Unknown";
14
16
  })(PortalKind || (PortalKind = {}));
15
17
  export const PortalRequest = {
16
18
  Access: (base, body) => ({
@@ -18,6 +20,11 @@ export const PortalRequest = {
18
20
  body,
19
21
  kind: PortalKind.Access,
20
22
  }),
23
+ AppChooser: (base, body) => ({
24
+ ...base,
25
+ body,
26
+ kind: PortalKind.AppChooser,
27
+ }),
21
28
  Unknown: (base, wireKind) => ({
22
29
  ...base,
23
30
  kind: PortalKind.Unknown,
@@ -28,13 +35,20 @@ export var PortalAnswerKind;
28
35
  (function (PortalAnswerKind) {
29
36
  /** The user allowed an {@link PortalKind.Access} request. */
30
37
  PortalAnswerKind[PortalAnswerKind["Access"] = 0] = "Access";
38
+ /** The application the user picked in an {@link PortalKind.AppChooser}. */
39
+ PortalAnswerKind[PortalAnswerKind["AppChooser"] = 1] = "AppChooser";
31
40
  /** The user dismissed or denied the dialog. */
32
- PortalAnswerKind[PortalAnswerKind["Canceled"] = 1] = "Canceled";
41
+ PortalAnswerKind[PortalAnswerKind["Canceled"] = 2] = "Canceled";
33
42
  /** The shell has no dialog for this kind. */
34
- PortalAnswerKind[PortalAnswerKind["Refused"] = 2] = "Refused";
43
+ PortalAnswerKind[PortalAnswerKind["Refused"] = 3] = "Refused";
35
44
  })(PortalAnswerKind || (PortalAnswerKind = {}));
36
45
  export const PortalAnswer = {
37
46
  Access: () => ({ kind: PortalAnswerKind.Access }),
47
+ /** `choice` must be one of the request's `choices`. */
48
+ AppChooser: (choice) => ({
49
+ choice,
50
+ kind: PortalAnswerKind.AppChooser,
51
+ }),
38
52
  Canceled: () => ({ kind: PortalAnswerKind.Canceled }),
39
53
  Refused: () => ({ kind: PortalAnswerKind.Refused }),
40
54
  };
@@ -56,7 +70,7 @@ export const watchPortalRequests = (host, listener) => {
56
70
  };
57
71
  /** Answer request `id`. The first answer to reach the compositor wins. */
58
72
  export const answerPortalRequest = (host, id, answer) => {
59
- host.answerPortalRequest(id, JSON.stringify({ kind: wireAnswer(answer) }));
73
+ host.answerPortalRequest(id, JSON.stringify(wireAnswer(answer)));
60
74
  };
61
75
  const accessSchema = z
62
76
  .object({
@@ -73,12 +87,31 @@ const accessSchema = z
73
87
  subtitle: body.subtitle,
74
88
  title: body.title,
75
89
  }));
90
+ const appChooserSchema = z
91
+ .object({
92
+ choices: z.array(z.string()),
93
+ content_type: z.string().optional(),
94
+ filename: z.string().optional(),
95
+ last_choice: z.string().optional(),
96
+ uri: z.string().optional(),
97
+ })
98
+ .transform((body) => ({
99
+ choices: body.choices,
100
+ contentType: body.content_type,
101
+ filename: body.filename,
102
+ lastChoice: body.last_choice,
103
+ uri: body.uri,
104
+ }));
76
105
  /** Each kind's wire name, and how to read its body into a request. */
77
106
  const KINDS = new Map([
78
107
  [
79
108
  "access",
80
109
  (base, body) => PortalRequest.Access(base, accessSchema.parse(body)),
81
110
  ],
111
+ [
112
+ "app_chooser",
113
+ (base, body) => PortalRequest.AppChooser(base, appChooserSchema.parse(body)),
114
+ ],
82
115
  ]);
83
116
  const itemSchema = z.object({
84
117
  app_id: z.string(),
@@ -102,13 +135,16 @@ const parseRequest = (item) => {
102
135
  ? PortalRequest.Unknown(base, item.kind)
103
136
  : parse(base, item.body);
104
137
  };
138
+ /** `answer` as the compositor reads it. */
105
139
  const wireAnswer = (answer) => {
106
140
  switch (answer.kind) {
107
141
  case PortalAnswerKind.Access:
108
- return "access";
142
+ return { kind: "access" };
143
+ case PortalAnswerKind.AppChooser:
144
+ return { choice: answer.choice, kind: "app_chooser" };
109
145
  case PortalAnswerKind.Canceled:
110
- return "canceled";
146
+ return { kind: "canceled" };
111
147
  case PortalAnswerKind.Refused:
112
- return "refused";
148
+ return { kind: "refused" };
113
149
  }
114
150
  };
package/package.json CHANGED
@@ -95,7 +95,7 @@
95
95
  "test:unit": "bun test"
96
96
  },
97
97
  "type": "module",
98
- "version": "0.0.0-alpha-bf4214ef2f5b",
98
+ "version": "0.0.0-alpha-eac3f852668d",
99
99
  "repository": {
100
100
  "type": "git",
101
101
  "url": "git+https://github.com/cprussin/domicile.git",