@domicile-desktop/manganese-inbox-gmail 0.0.0-stage → 0.0.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/README.md +43 -2
- package/package.json +44 -4
- package/src/as-reading.ts +23 -0
- package/src/gmail-inbox.ts +75 -0
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @domicile-desktop/manganese-inbox-gmail
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Manganese's Gmail inbox: one account's conversation count in the notification
|
|
4
|
+
drawer and the launcher, read with the Gmail API. Its unread conversations
|
|
5
|
+
count toward the bell.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
Put `gmailInbox(…)` in [`runManganese`](../shell-manganese/README.md)'s
|
|
10
|
+
`inboxes`.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { runManganese } from "@domicile-desktop/manganese";
|
|
14
|
+
import { gmailInbox } from "@domicile-desktop/manganese-inbox-gmail";
|
|
15
|
+
|
|
16
|
+
export const Shell = runManganese({
|
|
17
|
+
inboxes: [
|
|
18
|
+
gmailInbox({
|
|
19
|
+
client: { id: "….apps.googleusercontent.com", secret: "…" },
|
|
20
|
+
email: "me@gmail.com",
|
|
21
|
+
launcherName: "Email - Work",
|
|
22
|
+
nickname: "Work",
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `client`: a Google Cloud OAuth client, Desktop app type. How to make one:
|
|
29
|
+
[manganese-bar-module-gmail](../manganese-bar-module-gmail/README.md#use).
|
|
30
|
+
- `email`: the Google account.
|
|
31
|
+
- `nickname`: its name in the drawer.
|
|
32
|
+
- `launcherName`: its name in the launcher. `nickname` if not given.
|
|
33
|
+
|
|
34
|
+
A press opens the account's own Gmail window, or brings it up, or signs the
|
|
35
|
+
account in. New mail is notified under the nickname, and a press of one opens
|
|
36
|
+
the message in that window. What it
|
|
37
|
+
shows: [TOP-BAR.md](../shell-manganese/docs/TOP-BAR.md#inboxes). It reads the
|
|
38
|
+
inbox as the `Gmail` bar item does.
|
|
39
|
+
|
|
40
|
+
## Test
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
bun run turbo test --filter @domicile-desktop/manganese-inbox-gmail
|
|
44
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@domicile-desktop/manganese-bar-module-gmail": "1.0.0",
|
|
4
|
+
"@domicile-desktop/manganese-notifications": "1.0.0",
|
|
5
|
+
"@domicile-desktop/react": "0.0.0",
|
|
6
|
+
"@domicile-desktop/sdk": "1.0.0",
|
|
7
|
+
"@phosphor-icons/react": "^2.1.10"
|
|
8
|
+
},
|
|
9
|
+
"description": "Manganese's Gmail inbox: one account's conversation count in the notification drawer, read with the Gmail API.",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@cprussin/tsconfig": "^5.0.0",
|
|
12
|
+
"@domicile-desktop/test-support": "0.0.1",
|
|
13
|
+
"@types/bun": "^1.4.2",
|
|
14
|
+
"@types/react": "^19.2.18",
|
|
15
|
+
"react": "^19.2.8",
|
|
16
|
+
"typescript": "^7.0.2"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"bun": ">=1.4.2",
|
|
20
|
+
"node": ">=24"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./src/gmail-inbox.ts"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"src/**",
|
|
27
|
+
"!src/**/*.test.ts"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
2
30
|
"name": "@domicile-desktop/manganese-inbox-gmail",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
}
|
|
31
|
+
"private": false,
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"directory": "packages/manganese-inbox-gmail",
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/cprussin/domicile.git"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test:types": "tsc --noEmit",
|
|
42
|
+
"test:unit": "bun test"
|
|
43
|
+
},
|
|
44
|
+
"type": "module",
|
|
45
|
+
"version": "0.0.0"
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Inbox as GmailReading } from "@domicile-desktop/manganese-bar-module-gmail/inbox";
|
|
2
|
+
import { InboxKind as GmailKind } from "@domicile-desktop/manganese-bar-module-gmail/inbox";
|
|
3
|
+
import { InboxReading } from "@domicile-desktop/manganese-notifications/inbox";
|
|
4
|
+
|
|
5
|
+
/** A Gmail account's reading, as the drawer and the launcher read it. */
|
|
6
|
+
export const asReading = (reading: GmailReading): InboxReading => {
|
|
7
|
+
switch (reading.kind) {
|
|
8
|
+
case GmailKind.SignedOut:
|
|
9
|
+
return InboxReading.SignedOut();
|
|
10
|
+
case GmailKind.Counted:
|
|
11
|
+
return InboxReading.Counted(
|
|
12
|
+
reading.total,
|
|
13
|
+
reading.unread,
|
|
14
|
+
reading.latest.map(({ from, receivedAt, subject }) => ({
|
|
15
|
+
from,
|
|
16
|
+
receivedAt,
|
|
17
|
+
subject,
|
|
18
|
+
})),
|
|
19
|
+
);
|
|
20
|
+
case GmailKind.Failed:
|
|
21
|
+
return InboxReading.Failed(reading.reason);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
gmailAppId,
|
|
3
|
+
inboxAddress,
|
|
4
|
+
} from "@domicile-desktop/manganese-bar-module-gmail/addresses";
|
|
5
|
+
import type { GoogleClient } from "@domicile-desktop/manganese-bar-module-gmail/consent";
|
|
6
|
+
import { deskInbox } from "@domicile-desktop/manganese-bar-module-gmail/desk-inbox";
|
|
7
|
+
import type { Inbox as GmailReading } from "@domicile-desktop/manganese-bar-module-gmail/inbox";
|
|
8
|
+
import type { InboxReading } from "@domicile-desktop/manganese-notifications/inbox";
|
|
9
|
+
import {
|
|
10
|
+
Inbox,
|
|
11
|
+
InboxReadingKind,
|
|
12
|
+
} from "@domicile-desktop/manganese-notifications/inbox";
|
|
13
|
+
import { perDesktop } from "@domicile-desktop/react/per-desktop";
|
|
14
|
+
import type { SharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
15
|
+
import { sharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
16
|
+
import { AppReuse } from "@domicile-desktop/sdk/desktop/browser";
|
|
17
|
+
import { EnvelopeSimpleIcon } from "@phosphor-icons/react/dist/ssr/EnvelopeSimple";
|
|
18
|
+
|
|
19
|
+
import { asReading } from "./as-reading";
|
|
20
|
+
|
|
21
|
+
type Options = {
|
|
22
|
+
/** The Google Cloud OAuth client (Desktop app) it signs in with. */
|
|
23
|
+
client: GoogleClient;
|
|
24
|
+
/** The Google account, such as `me@gmail.com`. */
|
|
25
|
+
email: string;
|
|
26
|
+
/** The account's name in the drawer, such as `Work`. */
|
|
27
|
+
nickname: string;
|
|
28
|
+
/** Its name in the launcher, such as `Email - Work`. `nickname` if not given. */
|
|
29
|
+
launcherName?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One Gmail account's inbox in the notification drawer and the launcher,
|
|
34
|
+
* read with the Gmail API: its conversations, with the unread ones counted
|
|
35
|
+
* toward the bell. A press opens it in the account's own Gmail window, or
|
|
36
|
+
* brings that window up, or signs it in. Goes in `runManganese`'s `inboxes`.
|
|
37
|
+
*/
|
|
38
|
+
export const gmailInbox = ({
|
|
39
|
+
client,
|
|
40
|
+
email,
|
|
41
|
+
launcherName,
|
|
42
|
+
nickname,
|
|
43
|
+
}: Options): Inbox =>
|
|
44
|
+
Inbox.Watched({
|
|
45
|
+
account: email,
|
|
46
|
+
app: { appId: gmailAppId(email), url: inboxAddress(email) },
|
|
47
|
+
icon: EnvelopeSimpleIcon,
|
|
48
|
+
...(launcherName === undefined ? {} : { launcherName }),
|
|
49
|
+
name: nickname,
|
|
50
|
+
notifiesAs: nickname,
|
|
51
|
+
open: (domicile, reading) => {
|
|
52
|
+
if (reading?.kind === InboxReadingKind.SignedOut) {
|
|
53
|
+
deskInbox(domicile)(email, client, nickname).signIn();
|
|
54
|
+
} else {
|
|
55
|
+
domicile.browser.openApp(inboxAddress(email), {
|
|
56
|
+
id: gmailAppId(email),
|
|
57
|
+
reuse: AppReuse.Focus,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
read: perDesktop((domicile) =>
|
|
62
|
+
asReadings(deskInbox(domicile)(email, client, nickname).inbox),
|
|
63
|
+
),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** `watch`'s readings, as the drawer reads them. */
|
|
67
|
+
const asReadings = (watch: SharedWatch<GmailReading>) =>
|
|
68
|
+
sharedWatch<InboxReading>((onReading) =>
|
|
69
|
+
watch.subscribe(() => {
|
|
70
|
+
const reading = watch.current();
|
|
71
|
+
if (reading !== undefined) {
|
|
72
|
+
onReading(asReading(reading));
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
);
|