@domicile-desktop/manganese-page-requests 1.1.1 → 1.3.0

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 CHANGED
@@ -1,38 +1,52 @@
1
1
  {
2
2
  "dependencies": {
3
- "@domicile-desktop/component-library": "2.0.1",
4
- "@domicile-desktop/sdk": "2.1.0",
5
- "@pandacss/dev": "^1.12.1",
3
+ "@cprussin/option-result": "^2.0.1",
4
+ "@domicile-desktop/component-library": "2.2.0",
5
+ "@domicile-desktop/sdk": "3.0.0",
6
+ "@domicile-desktop/system-apps": "1.3.0",
7
+ "@pandacss/dev": "^1.12.2",
6
8
  "@phosphor-icons/react": "^2.1.10",
7
- "react": "^19.2.8",
8
- "zod": "^4.5.4"
9
+ "react": "^19.3.1",
10
+ "zod": "^4.6.7"
9
11
  },
10
12
  "description": "Manganese's prompts for a web page's permission, device and dialog requests.",
11
13
  "devDependencies": {
12
14
  "@cprussin/tsconfig": "^5.0.0",
13
15
  "@domicile-desktop/test-support": "0.0.2",
14
- "@pandacss/preset-panda": "^1.12.1",
16
+ "@pandacss/preset-panda": "^1.12.2",
15
17
  "@testing-library/react": "^16.3.3",
16
- "@testing-library/user-event": "^14.6.7",
17
- "@types/bun": "^1.4.2",
18
- "@types/react": "^19.2.18",
19
- "@types/react-dom": "^19.2.7",
20
- "postcss": "^8.5.28",
18
+ "@testing-library/user-event": "^14.6.10",
19
+ "@types/bun": "^1.4.4",
20
+ "@types/react": "^19.3.0",
21
+ "@types/react-dom": "^19.3.0",
22
+ "postcss": "^8.5.32",
21
23
  "typescript": "^7.0.2"
22
24
  },
23
25
  "engines": {
24
- "bun": ">=1.4.2",
25
- "node": ">=24"
26
+ "bun": ">=1.4.2"
26
27
  },
27
28
  "exports": {
29
+ "./AppMessageBox": "./src/AppMessageBox.tsx",
28
30
  "./DeviceAsk": "./src/DeviceAsk.tsx",
31
+ "./ExternalAppAsk": "./src/ExternalAppAsk.tsx",
32
+ "./IdentityAsk": "./src/IdentityAsk.tsx",
29
33
  "./PageDialog": "./src/PageDialog.tsx",
30
34
  "./PermissionAsk": "./src/PermissionAsk.tsx",
35
+ "./PickerAsk": "./src/PickerAsk.tsx",
36
+ "./PromptAsk": "./src/PromptAsk.tsx",
31
37
  "./permission-names": "./src/permission-names.tsx",
38
+ "./SignInAsk": "./src/SignInAsk.tsx",
39
+ "./shell-links": "./src/shell-links.ts",
32
40
  "./site-permissions": "./src/site-permissions.ts",
33
41
  "./useDeviceRequest": "./src/useDeviceRequest.ts",
34
42
  "./useDialogRequest": "./src/useDialogRequest.ts",
35
- "./usePermissionRequest": "./src/usePermissionRequest.ts"
43
+ "./useExternalAppRequest": "./src/useExternalAppRequest.ts",
44
+ "./useIdentityRequest": "./src/useIdentityRequest.ts",
45
+ "./useLinkOpener": "./src/useLinkOpener.ts",
46
+ "./usePermissionRequest": "./src/usePermissionRequest.ts",
47
+ "./usePickerRequest": "./src/usePickerRequest.ts",
48
+ "./usePromptRequest": "./src/usePromptRequest.ts",
49
+ "./useSignInRequest": "./src/useSignInRequest.ts"
36
50
  },
37
51
  "files": [
38
52
  "src/**",
@@ -57,5 +71,5 @@
57
71
  "test:unit": "bun test"
58
72
  },
59
73
  "type": "module",
60
- "version": "1.1.1"
74
+ "version": "1.3.0"
61
75
  }
@@ -0,0 +1,72 @@
1
+ import { Button } from "@domicile-desktop/component-library/Button";
2
+ import { Switch } from "@domicile-desktop/component-library/Switch";
3
+ import type { MessageBox } from "@domicile-desktop/sdk/message-box";
4
+ import type { RefCallback } from "react";
5
+ import { useState } from "react";
6
+
7
+ import { PageModal } from "./PageModal";
8
+
9
+ type Props = {
10
+ box: MessageBox;
11
+ /** The user pressed button `button`, leaving the checkbox `checked`. */
12
+ onAnswer: (button: number, checked: boolean) => void;
13
+ /** Gets the element to focus: the default button, or else Cancel. */
14
+ ref?: RefCallback<HTMLElement> | undefined;
15
+ };
16
+
17
+ /**
18
+ * An Electron app's message box (`dialog.showMessageBox`), over the window
19
+ * that asked, as a page's `confirm()` is.
20
+ *
21
+ * The app's buttons, in the app's order, with its default one in the accent
22
+ * color. A `PageModal`: Enter presses the default button, if the app named
23
+ * one, and Escape presses its cancel button. The app's checkbox, such as
24
+ * "Don't ask again", is a switch, as other asks' are. Takes no focus itself:
25
+ * the caller focuses `ref`'s element as its own focus rules allow. Key it by
26
+ * the box, so each starts with the app's checkbox.
27
+ */
28
+ export const AppMessageBox = ({ box, onAnswer, ref }: Props) => {
29
+ const [checked, setChecked] = useState(box.checkboxChecked);
30
+ const focused = box.defaultButton ?? box.cancelButton;
31
+ return (
32
+ <PageModal
33
+ footer={box.buttons.map((label, button) => (
34
+ <Button
35
+ // The app's buttons have no ids but their places, which a box never
36
+ // changes.
37
+ key={button}
38
+ onClick={
39
+ button === box.defaultButton
40
+ ? undefined
41
+ : () => {
42
+ onAnswer(button, checked);
43
+ }
44
+ }
45
+ ref={button === focused ? ref : undefined}
46
+ type={button === box.defaultButton ? "submit" : "button"}
47
+ variant={button === box.defaultButton ? "accent" : "outline"}
48
+ >
49
+ {label}
50
+ </Button>
51
+ ))}
52
+ message={box.detail === "" ? undefined : box.detail}
53
+ onDismiss={() => {
54
+ onAnswer(box.cancelButton, checked);
55
+ }}
56
+ onSubmit={() => {
57
+ if (box.defaultButton !== undefined) {
58
+ onAnswer(box.defaultButton, checked);
59
+ }
60
+ }}
61
+ title={box.message}
62
+ >
63
+ {box.checkbox !== undefined && (
64
+ <Switch
65
+ checked={checked}
66
+ label={box.checkbox}
67
+ onCheckedChange={setChecked}
68
+ />
69
+ )}
70
+ </PageModal>
71
+ );
72
+ };
package/src/DeviceAsk.tsx CHANGED
@@ -1,4 +1,7 @@
1
1
  import { Button } from "@domicile-desktop/component-library/Button";
2
+ import { EmptyState } from "@domicile-desktop/component-library/EmptyState";
3
+ import { Loading } from "@domicile-desktop/component-library/Loading";
4
+ import { DevicesIcon } from "@phosphor-icons/react/dist/ssr/Devices";
2
5
  import { useId, useState } from "react";
3
6
 
4
7
  import { css } from "../styled-system/css";
@@ -25,10 +28,14 @@ export const DeviceAsk = ({ request }: Props) => {
25
28
  {request.title}
26
29
  </span>
27
30
  {request.devices === undefined && (
28
- <span className={noteStyles}>Looking for devices…</span>
31
+ <Loading icon={DevicesIcon}>Looking for devices…</Loading>
29
32
  )}
30
33
  {request.devices?.length === 0 && (
31
- <span className={noteStyles}>No compatible devices found</span>
34
+ <EmptyState
35
+ hint="Plug in or turn on the device, and it shows up here."
36
+ icon={DevicesIcon}
37
+ title="No devices found"
38
+ />
32
39
  )}
33
40
  {request.devices !== undefined && request.devices.length > 0 && (
34
41
  <ul aria-label="Devices" className={devicesStyles}>
@@ -87,8 +94,6 @@ const askingTextStyles = css({
87
94
  overflowWrap: "anywhere",
88
95
  });
89
96
 
90
- const noteStyles = css({ color: "muted", fontSize: "sm" });
91
-
92
97
  const devicesStyles = vstack({
93
98
  alignItems: "stretch",
94
99
  gap: 1,
@@ -0,0 +1,112 @@
1
+ import type { Option } from "@cprussin/option-result";
2
+ import { Button } from "@domicile-desktop/component-library/Button";
3
+ import { Switch } from "@domicile-desktop/component-library/Switch";
4
+ import type { DescribedApp } from "@domicile-desktop/system-apps/describe-apps";
5
+ import { AppWindowIcon } from "@phosphor-icons/react/dist/ssr/AppWindow";
6
+ import type { RefCallback } from "react";
7
+ import { useState } from "react";
8
+
9
+ import { css } from "../styled-system/css";
10
+ import { PageModal } from "./PageModal";
11
+ import { hostOf } from "./site-host";
12
+ import type { ExternalAppRequest } from "./useExternalAppRequest";
13
+
14
+ /** The application's icon beside the title, as the app chooser draws it. */
15
+ const TITLE_ICON_SIZE = 32;
16
+
17
+ type Props = {
18
+ /** The application that opens the link; nothing when none does. */
19
+ app: Option<DescribedApp>;
20
+ /** Gets the element to focus: the answer button. */
21
+ ref?: RefCallback<HTMLElement> | undefined;
22
+ request: ExternalAppRequest;
23
+ };
24
+
25
+ /**
26
+ * Asks whether to open a link for an application, such as `zoommtg:`, over
27
+ * the page that opened it, as Chrome's "Open Zoom?" does, naming the
28
+ * application from its desktop entry. A site that may be remembered gets a
29
+ * switch to stop asking.
30
+ *
31
+ * A `PageModal`: Enter opens and Escape cancels. Takes no focus itself: the
32
+ * caller focuses `ref`'s element as its own focus rules allow.
33
+ */
34
+ export const ExternalAppAsk = ({ app, ref, request }: Props) => {
35
+ const [remember, setRemember] = useState(false);
36
+ const host = hostOf(request.origin);
37
+ return app.match({
38
+ None: () => (
39
+ <PageModal
40
+ footer={
41
+ <Button ref={ref} type="submit">
42
+ Close
43
+ </Button>
44
+ }
45
+ message={`Nothing on this computer opens ${schemeOf(request.url)} links.`}
46
+ onDismiss={request.dismiss}
47
+ onSubmit={request.dismiss}
48
+ title="No app opens this link"
49
+ />
50
+ ),
51
+ Some: ({ icon, name }) => (
52
+ <PageModal
53
+ footer={
54
+ <>
55
+ <Button onClick={request.dismiss} variant="outline">
56
+ Cancel
57
+ </Button>
58
+ <Button ref={ref} type="submit" variant="accent">
59
+ {`Open ${name}`}
60
+ </Button>
61
+ </>
62
+ }
63
+ message={`${host ?? "This page"} wants to open this link in ${name}.`}
64
+ onDismiss={request.dismiss}
65
+ onSubmit={() => {
66
+ request.open(remember);
67
+ }}
68
+ title={
69
+ <>
70
+ {icon === undefined ? (
71
+ <AppWindowIcon size={TITLE_ICON_SIZE} />
72
+ ) : (
73
+ <img
74
+ alt=""
75
+ className={iconStyles}
76
+ height={TITLE_ICON_SIZE}
77
+ src={icon}
78
+ width={TITLE_ICON_SIZE}
79
+ />
80
+ )}
81
+ {`Open ${name}?`}
82
+ </>
83
+ }
84
+ >
85
+ <p className={addressStyles}>{request.url}</p>
86
+ {request.mayRemember && host !== undefined && (
87
+ <Switch
88
+ checked={remember}
89
+ label={`Always let ${host} open these links in ${name}`}
90
+ onCheckedChange={setRemember}
91
+ />
92
+ )}
93
+ </PageModal>
94
+ ),
95
+ });
96
+ };
97
+
98
+ /** The link's scheme, as people name its links: `zoommtg`. */
99
+ const schemeOf = (url: string): string => url.slice(0, url.indexOf(":"));
100
+
101
+ const iconStyles = css({ flexShrink: 0, objectFit: "contain" });
102
+
103
+ // The link on one line, as the app chooser shows the address it opens.
104
+ const addressStyles = css({
105
+ color: "muted",
106
+ fontFamily: "mono",
107
+ fontSize: "xs",
108
+ margin: 0,
109
+ overflow: "hidden",
110
+ textOverflow: "ellipsis",
111
+ whiteSpace: "nowrap",
112
+ });