@celljs/ta-web 4.18.0 → 4.20.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.
Files changed (135) hide show
  1. package/esm/browser/account/account-side.d.ts +13 -0
  2. package/esm/browser/account/account-side.js +74 -0
  3. package/esm/browser/account/device-account.d.ts +69 -0
  4. package/esm/browser/account/device-account.js +215 -0
  5. package/esm/browser/assistant/assistant-chat-list.js +2 -1
  6. package/esm/browser/components/account-menu.d.ts +1 -1
  7. package/esm/browser/components/account-menu.js +7 -2
  8. package/esm/browser/components/account-view.d.ts +17 -0
  9. package/esm/browser/components/account-view.js +216 -0
  10. package/esm/browser/components/app-view.js +4 -4
  11. package/esm/browser/components/cloud-sign-in-view.d.ts +5 -1
  12. package/esm/browser/components/cloud-sign-in-view.js +1 -1
  13. package/esm/browser/components/dino-look.d.ts +9 -1
  14. package/esm/browser/components/dino-look.js +46 -1
  15. package/esm/browser/components/environment-view.js +12 -1
  16. package/esm/browser/components/face-pictures.d.ts +10 -0
  17. package/esm/browser/components/face-pictures.js +24 -0
  18. package/esm/browser/components/face.d.ts +4 -1
  19. package/esm/browser/components/face.js +16 -1
  20. package/esm/browser/components/host-view.d.ts +3 -1
  21. package/esm/browser/components/host-view.js +7 -0
  22. package/esm/browser/components/picture-dialog.d.ts +18 -0
  23. package/esm/browser/components/picture-dialog.js +116 -0
  24. package/esm/browser/components/workbench-view.js +5 -1
  25. package/esm/browser/extension/icons.js +2 -1
  26. package/esm/browser/extension/web-api-home.d.ts +13 -0
  27. package/esm/browser/extension/web-api-home.js +2 -0
  28. package/esm/browser/extension/web-extension-api.d.ts +4 -4
  29. package/esm/browser/extension/web-extension-context.js +2 -1
  30. package/esm/browser/extension/web-home.d.ts +8 -0
  31. package/esm/browser/extension/web-home.js +20 -0
  32. package/esm/browser/gateway/console-limits.d.ts +15 -0
  33. package/esm/browser/gateway/console-limits.js +2 -2
  34. package/esm/browser/gateway/console-tenant.js +33 -2
  35. package/esm/browser/gateway/console-updates.d.ts +12 -0
  36. package/esm/browser/gateway/console-updates.js +76 -0
  37. package/esm/browser/gateway/console-util.d.ts +7 -1
  38. package/esm/browser/gateway/console-util.js +18 -0
  39. package/esm/browser/gateway/console-view.js +9 -2
  40. package/esm/browser/hosts.d.ts +5 -0
  41. package/esm/browser/hosts.js +11 -0
  42. package/esm/browser/i18n/locales.d.ts +69 -3
  43. package/esm/browser/i18n/locales.js +9 -3
  44. package/esm/browser/i18n/messages-all.d.ts +7 -0
  45. package/esm/browser/i18n/messages-all.js +14 -0
  46. package/esm/browser/i18n/messages-ja.js +64 -0
  47. package/esm/browser/i18n/messages-zh-tw.js +64 -0
  48. package/esm/browser/i18n/messages.d.ts +70 -8
  49. package/esm/browser/i18n/messages.js +161 -11
  50. package/esm/browser/i18n/use-t.js +4 -3
  51. package/esm/browser/settings/settings.js +3 -1
  52. package/esm/browser/style/dialogs.d.ts +1 -1
  53. package/esm/browser/style/dialogs.js +31 -0
  54. package/esm/browser/style/pages.d.ts +1 -1
  55. package/esm/browser/style/pages.js +5 -0
  56. package/esm/browser/style/phone.d.ts +1 -1
  57. package/esm/browser/style/phone.js +2 -1
  58. package/esm/browser/style/surfaces.d.ts +1 -1
  59. package/esm/browser/style/surfaces.js +1 -0
  60. package/esm/browser/util/picture.d.ts +5 -0
  61. package/esm/browser/util/picture.js +43 -0
  62. package/esm/browser/workbench-hosts.d.ts +7 -0
  63. package/esm/browser/workbench-hosts.js +20 -0
  64. package/esm/browser/workbench-protocol.d.ts +8 -1
  65. package/esm/browser/workbench-services.d.ts +2 -1
  66. package/esm/browser/workbench-services.js +3 -0
  67. package/esm/browser/workbench-util.d.ts +1 -1
  68. package/lib/browser/account/account-side.d.ts +14 -0
  69. package/lib/browser/account/account-side.js +111 -0
  70. package/lib/browser/account/device-account.d.ts +70 -0
  71. package/lib/browser/account/device-account.js +219 -0
  72. package/lib/browser/assistant/assistant-chat-list.js +2 -1
  73. package/lib/browser/components/account-menu.d.ts +1 -1
  74. package/lib/browser/components/account-menu.js +6 -1
  75. package/lib/browser/components/account-view.d.ts +18 -0
  76. package/lib/browser/components/account-view.js +255 -0
  77. package/lib/browser/components/app-view.js +2 -2
  78. package/lib/browser/components/cloud-sign-in-view.d.ts +5 -1
  79. package/lib/browser/components/cloud-sign-in-view.js +1 -0
  80. package/lib/browser/components/dino-look.d.ts +9 -1
  81. package/lib/browser/components/dino-look.js +48 -1
  82. package/lib/browser/components/environment-view.js +11 -0
  83. package/lib/browser/components/face-pictures.d.ts +11 -0
  84. package/lib/browser/components/face-pictures.js +60 -0
  85. package/lib/browser/components/face.d.ts +4 -1
  86. package/lib/browser/components/face.js +16 -1
  87. package/lib/browser/components/host-view.d.ts +3 -1
  88. package/lib/browser/components/host-view.js +8 -0
  89. package/lib/browser/components/picture-dialog.d.ts +19 -0
  90. package/lib/browser/components/picture-dialog.js +153 -0
  91. package/lib/browser/components/workbench-view.js +5 -1
  92. package/lib/browser/extension/icons.js +1 -0
  93. package/lib/browser/extension/web-api-home.d.ts +14 -0
  94. package/lib/browser/extension/web-api-home.js +3 -0
  95. package/lib/browser/extension/web-extension-api.d.ts +4 -4
  96. package/lib/browser/extension/web-extension-context.js +2 -1
  97. package/lib/browser/extension/web-home.d.ts +8 -0
  98. package/lib/browser/extension/web-home.js +54 -1
  99. package/lib/browser/gateway/console-limits.d.ts +15 -0
  100. package/lib/browser/gateway/console-limits.js +2 -0
  101. package/lib/browser/gateway/console-tenant.js +32 -1
  102. package/lib/browser/gateway/console-updates.d.ts +13 -0
  103. package/lib/browser/gateway/console-updates.js +113 -0
  104. package/lib/browser/gateway/console-util.d.ts +7 -1
  105. package/lib/browser/gateway/console-util.js +18 -0
  106. package/lib/browser/gateway/console-view.js +9 -2
  107. package/lib/browser/hosts.d.ts +5 -0
  108. package/lib/browser/hosts.js +11 -0
  109. package/lib/browser/i18n/locales.d.ts +69 -3
  110. package/lib/browser/i18n/locales.js +8 -2
  111. package/lib/browser/i18n/messages-all.d.ts +8 -0
  112. package/lib/browser/i18n/messages-all.js +17 -0
  113. package/lib/browser/i18n/messages-ja.js +64 -0
  114. package/lib/browser/i18n/messages-zh-tw.js +64 -0
  115. package/lib/browser/i18n/messages.d.ts +70 -8
  116. package/lib/browser/i18n/messages.js +163 -13
  117. package/lib/browser/i18n/use-t.js +4 -3
  118. package/lib/browser/settings/settings.js +3 -1
  119. package/lib/browser/style/dialogs.d.ts +1 -1
  120. package/lib/browser/style/dialogs.js +31 -0
  121. package/lib/browser/style/pages.d.ts +1 -1
  122. package/lib/browser/style/pages.js +5 -0
  123. package/lib/browser/style/phone.d.ts +1 -1
  124. package/lib/browser/style/phone.js +2 -1
  125. package/lib/browser/style/surfaces.d.ts +1 -1
  126. package/lib/browser/style/surfaces.js +1 -0
  127. package/lib/browser/util/picture.d.ts +6 -0
  128. package/lib/browser/util/picture.js +46 -0
  129. package/lib/browser/workbench-hosts.d.ts +7 -0
  130. package/lib/browser/workbench-hosts.js +20 -0
  131. package/lib/browser/workbench-protocol.d.ts +8 -1
  132. package/lib/browser/workbench-services.d.ts +2 -1
  133. package/lib/browser/workbench-services.js +3 -0
  134. package/lib/browser/workbench-util.d.ts +1 -1
  135. package/package.json +7 -7
@@ -0,0 +1,43 @@
1
+ import { TA_PICTURE } from '@celljs/ta-protocol';
2
+ /** Sides of the square tried, largest first, and qualities of each, till one fits a picture of Ta (TA_PICTURE.maxChars). */
3
+ const SIDES = [192, 160, 128, 96];
4
+ const QUALITIES = [0.86, 0.76, 0.66];
5
+ /** The picture the user gives themselves (TaRoomServer.setPicture), made of a photo. */
6
+ export var PictureUtil;
7
+ (function (PictureUtil) {
8
+ /** The middle square of a photo, as a JPEG small enough; undefined when none is. */
9
+ async function square(file) {
10
+ const bitmap = await createImageBitmap(file);
11
+ try {
12
+ const side = Math.min(bitmap.width, bitmap.height);
13
+ const left = (bitmap.width - side) / 2;
14
+ const top = (bitmap.height - side) / 2;
15
+ for (const size of SIDES) {
16
+ const canvas = document.createElement('canvas');
17
+ canvas.width = size;
18
+ canvas.height = size;
19
+ const context = canvas.getContext('2d');
20
+ if (!context) {
21
+ return undefined;
22
+ }
23
+ // What is clear in a PNG shows white, not black, in a JPEG.
24
+ context.fillStyle = '#fff';
25
+ context.fillRect(0, 0, size, size);
26
+ context.imageSmoothingQuality = 'high';
27
+ context.drawImage(bitmap, left, top, side, side, 0, 0, size, size);
28
+ for (const quality of QUALITIES) {
29
+ const url = canvas.toDataURL('image/jpeg', quality);
30
+ if (url.length <= TA_PICTURE.maxChars) {
31
+ return url;
32
+ }
33
+ }
34
+ }
35
+ return undefined;
36
+ }
37
+ finally {
38
+ bitmap.close();
39
+ }
40
+ }
41
+ PictureUtil.square = square;
42
+ })(PictureUtil || (PictureUtil = {}));
43
+ //# sourceMappingURL=picture.js.map
@@ -11,6 +11,13 @@ export declare abstract class WorkbenchHosts extends WorkbenchLists {
11
11
  /** What was kept of the computers dropped, being taken off the device. */
12
12
  protected forgetting: Promise<unknown>;
13
13
  signIn(given: string | Credential): Promise<void>;
14
+ /**
15
+ * A way into a computer of the user's account came (docs/design/ta-account.md): kept in the list of computers;
16
+ * used at once when none is.
17
+ */
18
+ addAccountHost(link: string, account: string): Promise<void>;
19
+ /** The computers the account brought: those of `account`, or all of them when the device left the account. */
20
+ forgetAccountHosts(account?: string): void;
14
21
  switchTo(hostId: string): void;
15
22
  forget(hostId: string): void;
16
23
  rename(hostId: string, name: string): void;
@@ -25,6 +25,26 @@ export class WorkbenchHosts extends WorkbenchLists {
25
25
  this.keepHosts(HostUtil.use(this.list, id, credential, Date.now(), { user: server.user, host: server.host }));
26
26
  this.load(id);
27
27
  }
28
+ /**
29
+ * A way into a computer of the user's account came (docs/design/ta-account.md): kept in the list of computers;
30
+ * used at once when none is.
31
+ */
32
+ async addAccountHost(link, account) {
33
+ const credential = WorkbenchUtil.credential(link);
34
+ const id = WorkbenchUtil.serverOf(credential, pageHost());
35
+ if (this.current.status === 'signed-out' && !this.list.current) {
36
+ this.keepHosts(HostUtil.keep(this.list, id, credential, account, Date.now()));
37
+ await this.signIn(credential);
38
+ return;
39
+ }
40
+ this.keepHosts(HostUtil.keep(this.list, id, credential, account, Date.now()));
41
+ }
42
+ /** The computers the account brought: those of `account`, or all of them when the device left the account. */
43
+ forgetAccountHosts(account) {
44
+ for (const host of this.list.hosts.filter(one => one.account && (account === undefined || one.account === account))) {
45
+ this.forget(host.id);
46
+ }
47
+ }
28
48
  switchTo(hostId) {
29
49
  const host = this.list.hosts.find(one => one.id === hostId);
30
50
  if (!host || (hostId === this.current.host && this.current.status !== 'signed-out')) {
@@ -1,5 +1,5 @@
1
1
  import type { SessionStore, SessionStoreOptions } from '@celljs/ta-client';
2
- import type { TaAccessServer, TaAuthEvent, TaAuthServer, TaDesktopEvent, TaGatewayServer, TaPackageServer, TaRelayServer, TaRemoteEvent, TaRemoteServer, TaRoomEvent, TaRoomServer, TaSavedSessionInfo, TaScreenShareServer, TaServer, TaServerInfo, TaSessionInfo, TaSettingsServer, TaTerminalServer, TaVoiceEvent, TaVoiceServer, TaWorkspaceServer } from '@celljs/ta-protocol';
2
+ import type { TaAccessServer, TaAccountServer, TaAuthEvent, TaAuthServer, TaDesktopEvent, TaGatewayServer, TaPackageServer, TaRelayServer, TaRemoteEvent, TaRemoteServer, TaRoomEvent, TaRoomServer, TaSavedSessionInfo, TaScreenShareServer, TaServer, TaServerInfo, TaSessionInfo, TaSettingsServer, TaTerminalServer, TaVoiceEvent, TaVoiceServer, TaWorkspaceServer } from '@celljs/ta-protocol';
3
3
  import type { RelayPairing } from '@celljs/ta-relay';
4
4
  export declare const TaWorkbench: unique symbol;
5
5
  /**
@@ -26,6 +26,8 @@ export interface SavedHost {
26
26
  name?: string;
27
27
  /** Who and which machine answered the last time. */
28
28
  server?: Pick<TaServerInfo, 'user' | 'host'>;
29
+ /** A computer of the user's account (docs/design/ta-account.md), by its id there: added and removed with it. */
30
+ account?: string;
29
31
  addedAt: number;
30
32
  usedAt: number;
31
33
  }
@@ -100,6 +102,7 @@ export interface TaWorkbench {
100
102
  /** Behind `ta gateway` only. */
101
103
  readonly gateway: TaGatewayServer;
102
104
  readonly relay: TaRelayServer;
105
+ readonly account: TaAccountServer;
103
106
  readonly remote: TaRemoteServer;
104
107
  /** Desktops of other computers (docs/design/ta-desktop-remote.md). */
105
108
  readonly screenShare: TaScreenShareServer;
@@ -127,6 +130,10 @@ export interface TaWorkbench {
127
130
  forget(hostId: string): void;
128
131
  /** Names a host on this device; an empty name gives it back its own. */
129
132
  rename(hostId: string, name: string): void;
133
+ /** A way into a computer of the user's account (docs/design/ta-account.md): kept, used at once when none is. */
134
+ addAccountHost(link: string, account: string): Promise<void>;
135
+ /** The computers the account brought: those of `account`, or all when the device left the account. */
136
+ forgetAccountHosts(account?: string): void;
130
137
  /** Forgets the computer in use and loads the page again, at the sign-in, with the other computers kept. */
131
138
  signOut(): void;
132
139
  /**
@@ -1,5 +1,5 @@
1
1
  import type { TaConnection } from '@celljs/ta-client';
2
- import { type TaAccessServer, type TaAuthEvent, type TaAuthServer, type TaDesktopEvent, type TaGatewayServer, type TaPackageServer, type TaRelayServer, type TaRemoteEvent, type TaRemoteServer, type TaRoomEvent, type TaRoomServer, type TaRoomWatch, type TaScreenShareServer, type TaServer, type TaSettingsServer, type TaTerminalServer, type TaVoiceEvent, type TaVoiceServer, type TaWorkspaceServer } from '@celljs/ta-protocol';
2
+ import { type TaAccessServer, type TaAccountServer, type TaAuthEvent, type TaAuthServer, type TaDesktopEvent, type TaGatewayServer, type TaPackageServer, type TaRelayServer, type TaRemoteEvent, type TaRemoteServer, type TaRoomEvent, type TaRoomServer, type TaRoomWatch, type TaScreenShareServer, type TaServer, type TaSettingsServer, type TaTerminalServer, type TaVoiceEvent, type TaVoiceServer, type TaWorkspaceServer } from '@celljs/ta-protocol';
3
3
  import type { WorkbenchCalls } from './workbench-calls.js';
4
4
  import type { ServiceName } from './workbench-util.js';
5
5
  /** The services of the workbench, and the listeners of what its connection tells. */
@@ -26,6 +26,7 @@ export declare abstract class WorkbenchServices {
26
26
  get auth(): TaAuthServer;
27
27
  get access(): TaAccessServer;
28
28
  get gateway(): TaGatewayServer;
29
+ get account(): TaAccountServer;
29
30
  get relay(): TaRelayServer;
30
31
  get remote(): TaRemoteServer;
31
32
  get screenShare(): TaScreenShareServer;
@@ -37,6 +37,9 @@ export class WorkbenchServices {
37
37
  get gateway() {
38
38
  return this.service('gateway');
39
39
  }
40
+ get account() {
41
+ return this.service('account');
42
+ }
40
43
  get relay() {
41
44
  return this.service('relay');
42
45
  }
@@ -26,7 +26,7 @@ export interface KeptLists {
26
26
  sessions: TaSessionInfo[];
27
27
  saved: TaSavedSessionInfo[];
28
28
  }
29
- export type ServiceName = 'server' | 'workspace' | 'terminals' | 'settings' | 'packages' | 'auth' | 'access' | 'gateway' | 'relay' | 'remote' | 'screenShare' | 'rooms' | 'voice';
29
+ export type ServiceName = 'server' | 'account' | 'workspace' | 'terminals' | 'settings' | 'packages' | 'auth' | 'access' | 'gateway' | 'relay' | 'remote' | 'screenShare' | 'rooms' | 'voice';
30
30
  /**
31
31
  * A conversation opens with about this much of its latest messages (a screen or two: the images of the user's
32
32
  * come apart, TaShownImage), its earlier ones loaded as much at a time when scrolled to.
@@ -0,0 +1,14 @@
1
+ import type { TaAccountInfo } from '@celljs/ta-protocol';
2
+ import { type AccountSide } from './device-account';
3
+ /**
4
+ * The account a page shows (docs/design/ta-account.md): in the app, the phone's own; elsewhere, that of the computer
5
+ * whose page it is, once connected to it.
6
+ */
7
+ export declare function useAccountSide(): AccountSide | undefined;
8
+ /** The account as it is now, read again every few seconds while shown; `act` runs a change and shows what it made. */
9
+ export declare function useAccountInfo(side: AccountSide | undefined, every?: number): {
10
+ info: TaAccountInfo | undefined;
11
+ failed: unknown;
12
+ act: (run: (side: AccountSide) => Promise<TaAccountInfo>) => Promise<void>;
13
+ };
14
+ //# sourceMappingURL=account-side.d.ts.map
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useAccountSide = useAccountSide;
37
+ exports.useAccountInfo = useAccountInfo;
38
+ const ta_relay_1 = require("@celljs/ta-relay");
39
+ const React = __importStar(require("react"));
40
+ const cloud_sign_in_1 = require("../cloud/cloud-sign-in");
41
+ const hooks_1 = require("../hooks");
42
+ const workbench_util_1 = require("../workbench-util");
43
+ const device_account_1 = require("./device-account");
44
+ /** The account of the computer of the page, through its ta serve (TaAccountServer). */
45
+ function serveSide(account) {
46
+ return {
47
+ read: () => account.getAccount(),
48
+ signIn: (provider, service) => account.signIn(provider, service),
49
+ cancelSignIn: () => account.cancelSignIn(),
50
+ approve: id => account.approve(id),
51
+ remove: id => account.remove(id),
52
+ signOut: () => account.signOut(),
53
+ };
54
+ }
55
+ /**
56
+ * The relay the app's account is on: that of the computers it is paired with, as theirs is; else the relay of the
57
+ * deployment this build is for, else the default one.
58
+ */
59
+ async function appService(hosts, current) {
60
+ var _a;
61
+ var _b, _c, _d;
62
+ const paired = (one) => (one && 'pairing' in one.credential ? one.credential.pairing.relay : undefined);
63
+ return ((_d = (_c = (_b = paired(hosts.find(one => one.id === current))) !== null && _b !== void 0 ? _b : hosts.map(paired).find(Boolean)) !== null && _c !== void 0 ? _c : (_a = (await cloud_sign_in_1.CloudSignInUtil.distribution())) === null || _a === void 0 ? void 0 : _a.relay) !== null && _d !== void 0 ? _d : (0, ta_relay_1.relayDefaultUrl)());
64
+ }
65
+ /**
66
+ * The account a page shows (docs/design/ta-account.md): in the app, the phone's own; elsewhere, that of the computer
67
+ * whose page it is, once connected to it.
68
+ */
69
+ function useAccountSide() {
70
+ const [{ status, hosts, host }, bench] = (0, hooks_1.useWorkbench)();
71
+ const app = workbench_util_1.WorkbenchUtil.isApp();
72
+ const where = React.useRef({ hosts, host });
73
+ where.current = { hosts, host };
74
+ const online = status === 'online';
75
+ return React.useMemo(() => {
76
+ if (app) {
77
+ return device_account_1.DeviceAccount.of(bench, () => appService(where.current.hosts, where.current.host), async () => {
78
+ var _a;
79
+ const chosen = cloud_sign_in_1.CloudSignInUtil.chosen();
80
+ const built = (_a = (await cloud_sign_in_1.CloudSignInUtil.distribution())) === null || _a === void 0 ? void 0 : _a.gateway;
81
+ return [chosen, built].filter((one) => !!one);
82
+ });
83
+ }
84
+ return online ? serveSide(bench.account) : undefined;
85
+ }, [app, online, bench]);
86
+ }
87
+ /** The account as it is now, read again every few seconds while shown; `act` runs a change and shows what it made. */
88
+ function useAccountInfo(side, every = 3000) {
89
+ const [info, setInfo] = React.useState();
90
+ const [failed, setFailed] = React.useState();
91
+ React.useEffect(() => {
92
+ if (!side) {
93
+ return;
94
+ }
95
+ let live = true;
96
+ const read = () => side.read().then(next => live && setInfo(next), (error) => live && setFailed(error));
97
+ void read();
98
+ const timer = setInterval(() => document.visibilityState !== 'hidden' && void read(), every);
99
+ return () => {
100
+ live = false;
101
+ clearInterval(timer);
102
+ };
103
+ }, [side, every]);
104
+ const act = React.useCallback(async (run) => {
105
+ if (side) {
106
+ setInfo(await run(side));
107
+ }
108
+ }, [side]);
109
+ return { info, failed, act };
110
+ }
111
+ //# sourceMappingURL=account-side.js.map
@@ -0,0 +1,70 @@
1
+ import type { TaAccountInfo } from '@celljs/ta-protocol';
2
+ import { AccountAgent, type AccountKept, type AccountView, type AccountWay } from '@celljs/ta-relay';
3
+ import type { SavedHost } from '../workbench-protocol';
4
+ /** What a page does about the account: of its ta serve (a computer), or of the device itself (the app). */
5
+ export interface AccountSide {
6
+ read(): Promise<TaAccountInfo>;
7
+ signIn(provider: string, service?: string): Promise<TaAccountInfo>;
8
+ cancelSignIn(): Promise<TaAccountInfo>;
9
+ approve(id: string): Promise<TaAccountInfo>;
10
+ remove(id: string): Promise<TaAccountInfo>;
11
+ signOut(): Promise<TaAccountInfo>;
12
+ }
13
+ /** The computers a device's account brings, kept with the device's computers (TaWorkbench). */
14
+ export interface AccountHosts {
15
+ readonly state: {
16
+ hosts: SavedHost[];
17
+ };
18
+ addAccountHost(link: string, account: string): Promise<void>;
19
+ forgetAccountHosts(account?: string): void;
20
+ }
21
+ /**
22
+ * The app as a device of the user's account (docs/design/ta-account.md): its own keys in localStorage; the computers
23
+ * of the account come into its list of computers as they let it in, and go as they are removed. The same agent as a
24
+ * computer's (AccountAgent), with the hooks of a device that pairs with computers rather than letting devices in.
25
+ */
26
+ export declare class DeviceAccount implements AccountSide {
27
+ protected readonly hosts: AccountHosts;
28
+ protected readonly service: () => Promise<string>;
29
+ protected readonly gateways: () => Promise<string[]>;
30
+ protected static instance?: DeviceAccount;
31
+ protected agent?: AccountAgent;
32
+ protected view?: AccountView;
33
+ protected signingIn?: {
34
+ way: AccountWay;
35
+ handle: string;
36
+ code: string;
37
+ url: string;
38
+ interval: number;
39
+ expiresAt: number;
40
+ };
41
+ protected error?: string;
42
+ protected timer?: ReturnType<typeof setTimeout>;
43
+ protected running?: Promise<void>;
44
+ protected constructor(hosts: AccountHosts, service: () => Promise<string>, gateways: () => Promise<string[]>);
45
+ /** The one of the page. */
46
+ static of(hosts: AccountHosts, service: () => Promise<string>, gateways: () => Promise<string[]>): DeviceAccount;
47
+ /** What the device calls itself in the account. */
48
+ static deviceName(agent?: string): string;
49
+ protected static read(): AccountKept | undefined;
50
+ protected agentOf(kept: AccountKept): AccountAgent;
51
+ /** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
52
+ protected cloudToken(): {
53
+ service: string;
54
+ token: string;
55
+ } | undefined;
56
+ /** Joins the account of the gateway of a Ta in the cloud of this device, unless the user left the account. */
57
+ protected adopt(): Promise<boolean>;
58
+ protected forget(): void;
59
+ protected schedule(after: number): void;
60
+ protected round(): Promise<void>;
61
+ protected pollSignIn(): Promise<number>;
62
+ read(): Promise<TaAccountInfo>;
63
+ signIn(provider: string, service?: string): Promise<TaAccountInfo>;
64
+ cancelSignIn(): Promise<TaAccountInfo>;
65
+ protected act(run: (agent: AccountAgent) => Promise<AccountView>): Promise<TaAccountInfo>;
66
+ approve(id: string): Promise<TaAccountInfo>;
67
+ remove(id: string): Promise<TaAccountInfo>;
68
+ signOut(): Promise<TaAccountInfo>;
69
+ }
70
+ //# sourceMappingURL=device-account.d.ts.map
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceAccount = void 0;
4
+ const ta_relay_1 = require("@celljs/ta-relay");
5
+ const workbench_util_1 = require("../workbench-util");
6
+ const KEY = 'ta.account';
7
+ /** Signed out of the account by the user: not signed in again by itself with the token of a Ta in the cloud. */
8
+ const OFF_KEY = 'ta.account.off';
9
+ const SYNC_MS = 15000;
10
+ const WAITING_SYNC_MS = 3000;
11
+ /**
12
+ * The app as a device of the user's account (docs/design/ta-account.md): its own keys in localStorage; the computers
13
+ * of the account come into its list of computers as they let it in, and go as they are removed. The same agent as a
14
+ * computer's (AccountAgent), with the hooks of a device that pairs with computers rather than letting devices in.
15
+ */
16
+ class DeviceAccount {
17
+ constructor(hosts, service, gateways) {
18
+ this.hosts = hosts;
19
+ this.service = service;
20
+ this.gateways = gateways;
21
+ const kept = DeviceAccount.read();
22
+ if (kept) {
23
+ this.agent = this.agentOf(kept);
24
+ }
25
+ this.schedule(0);
26
+ document.addEventListener('visibilitychange', () => document.visibilityState === 'visible' && this.schedule(0));
27
+ }
28
+ /** The one of the page. */
29
+ static of(hosts, service, gateways) {
30
+ var _a;
31
+ (_a = DeviceAccount.instance) !== null && _a !== void 0 ? _a : (DeviceAccount.instance = new DeviceAccount(hosts, service, gateways));
32
+ return DeviceAccount.instance;
33
+ }
34
+ /** What the device calls itself in the account. */
35
+ static deviceName(agent = navigator.userAgent) {
36
+ return /iPad/.test(agent) ? 'iPad' : /iPhone/.test(agent) ? 'iPhone' : /Android/.test(agent) ? 'Android' : 'Phone';
37
+ }
38
+ static read() {
39
+ var _a, _b;
40
+ var _c;
41
+ try {
42
+ const kept = JSON.parse((_c = (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.getItem(KEY)) !== null && _c !== void 0 ? _c : 'null');
43
+ return (kept === null || kept === void 0 ? void 0 : kept.token) && ((_b = kept.self) === null || _b === void 0 ? void 0 : _b.signKey) ? kept : undefined;
44
+ }
45
+ catch (_d) {
46
+ return undefined;
47
+ }
48
+ }
49
+ agentOf(kept) {
50
+ return new ta_relay_1.AccountAgent(kept, {
51
+ save: next => { var _a; return (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(next)); },
52
+ name: () => DeviceAccount.deviceName(),
53
+ pairing: (from, link) => this.hosts.addAccountHost(link, from.id),
54
+ unpaired: from => this.hosts.forgetAccountHosts(from),
55
+ signedOut: () => {
56
+ var _a;
57
+ this.forget();
58
+ // A token no longer good, or this device removed: not joined again by itself.
59
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(OFF_KEY, '1');
60
+ },
61
+ });
62
+ }
63
+ /** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
64
+ cloudToken() {
65
+ for (const host of this.hosts.state.hosts) {
66
+ if ('token' in host.credential && host.credential.url) {
67
+ return { service: host.credential.url.replace(/\/+$/, ''), token: host.credential.token };
68
+ }
69
+ }
70
+ return undefined;
71
+ }
72
+ /** Joins the account of the gateway of a Ta in the cloud of this device, unless the user left the account. */
73
+ async adopt() {
74
+ var _a, _b;
75
+ const cloud = ((_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.getItem(OFF_KEY)) ? undefined : this.cloudToken();
76
+ if (!cloud || !(await ta_relay_1.AccountService.ways(cloud.service, [cloud.service])).some(one => one.gateway)) {
77
+ return false;
78
+ }
79
+ const kept = await ta_relay_1.AccountAgent.create(cloud.service, cloud.token, { id: '', name: '' }, 'phone', DeviceAccount.deviceName());
80
+ (_b = (0, workbench_util_1.storage)()) === null || _b === void 0 ? void 0 : _b.setItem(KEY, JSON.stringify(kept));
81
+ this.agent = this.agentOf(kept);
82
+ return true;
83
+ }
84
+ forget() {
85
+ var _a;
86
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
87
+ this.agent = undefined;
88
+ this.view = undefined;
89
+ this.hosts.forgetAccountHosts();
90
+ }
91
+ schedule(after) {
92
+ clearTimeout(this.timer);
93
+ if (!this.agent && !this.signingIn && !this.cloudToken()) {
94
+ return;
95
+ }
96
+ this.timer = setTimeout(() => void this.round(), after);
97
+ }
98
+ round() {
99
+ var _a;
100
+ (_a = this.running) !== null && _a !== void 0 ? _a : (this.running = (async () => {
101
+ let next = SYNC_MS;
102
+ try {
103
+ if (this.signingIn) {
104
+ next = await this.pollSignIn();
105
+ }
106
+ else if (this.agent || (await this.adopt())) {
107
+ const agent = this.agent;
108
+ this.view = await agent.sync();
109
+ this.error = undefined;
110
+ if (this.view.waiting || this.view.devices.some(one => one.waiting)) {
111
+ next = WAITING_SYNC_MS;
112
+ }
113
+ }
114
+ }
115
+ catch (error) {
116
+ this.error = error instanceof Error ? error.message : String(error);
117
+ }
118
+ finally {
119
+ this.running = undefined;
120
+ }
121
+ if (document.visibilityState !== 'hidden') {
122
+ this.schedule(next);
123
+ }
124
+ })());
125
+ return this.running;
126
+ }
127
+ async pollSignIn() {
128
+ var _a, _b;
129
+ const signing = this.signingIn;
130
+ if (Date.now() > signing.expiresAt) {
131
+ this.signingIn = undefined;
132
+ return SYNC_MS;
133
+ }
134
+ const answer = await ta_relay_1.AccountService.check(signing.way, signing.handle);
135
+ if (answer.status === 'pending') {
136
+ return signing.interval * 1000;
137
+ }
138
+ this.signingIn = undefined;
139
+ if (answer.status === 'failed') {
140
+ this.error = answer.error;
141
+ return SYNC_MS;
142
+ }
143
+ const kept = await ta_relay_1.AccountAgent.create(signing.way.service, answer.token, answer.account, 'phone', DeviceAccount.deviceName());
144
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(kept));
145
+ (_b = (0, workbench_util_1.storage)()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
146
+ this.agent = this.agentOf(kept);
147
+ this.view = await this.agent.sync();
148
+ return WAITING_SYNC_MS;
149
+ }
150
+ async read() {
151
+ var _a, _b;
152
+ var _c, _d;
153
+ const service = (_d = (_c = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service) !== null && _c !== void 0 ? _c : (_b = this.signingIn) === null || _b === void 0 ? void 0 : _b.way.service) !== null && _d !== void 0 ? _d : (await this.service());
154
+ const error = this.error ? { error: this.error } : {};
155
+ if (!this.agent) {
156
+ const signing = this.signingIn;
157
+ return {
158
+ service,
159
+ providers: await ta_relay_1.AccountService.ways(service, await this.gateways().catch(() => [])).catch(() => []),
160
+ devices: [],
161
+ ...(signing ? { signingIn: { provider: signing.way.id, code: signing.code, url: signing.url, expiresAt: signing.expiresAt } } : {}),
162
+ ...error,
163
+ };
164
+ }
165
+ if (!this.view) {
166
+ await this.round();
167
+ }
168
+ const view = this.view;
169
+ if (!view) {
170
+ return { service, providers: [], account: this.agent.state.account, devices: [], ...error };
171
+ }
172
+ const devices = view.devices.map(({ trusted: _trusted, ...device }) => device);
173
+ return { service, providers: [], account: view.account, waiting: view.waiting, code: view.code, devices, ...error };
174
+ }
175
+ async signIn(provider, service) {
176
+ if (!this.agent) {
177
+ const ways = await ta_relay_1.AccountService.ways(await this.service(), await this.gateways().catch(() => []));
178
+ const way = ways.find(one => one.id === provider && (service === undefined || one.service === service));
179
+ if (!way) {
180
+ throw new ta_relay_1.AccountCallError(404, `No way to sign in with ${provider} here.`);
181
+ }
182
+ const start = await ta_relay_1.AccountService.begin(way, DeviceAccount.deviceName());
183
+ this.signingIn = { way, ...start, expiresAt: Date.now() + start.expiresIn * 1000 };
184
+ this.error = undefined;
185
+ this.schedule(start.interval * 1000);
186
+ }
187
+ return this.read();
188
+ }
189
+ async cancelSignIn() {
190
+ this.signingIn = undefined;
191
+ return this.read();
192
+ }
193
+ async act(run) {
194
+ if (!this.agent) {
195
+ throw new ta_relay_1.AccountCallError(401, 'Sign in to an account first.');
196
+ }
197
+ this.view = await run(this.agent);
198
+ this.schedule(WAITING_SYNC_MS);
199
+ return this.read();
200
+ }
201
+ approve(id) {
202
+ return this.act(agent => agent.approve(id));
203
+ }
204
+ remove(id) {
205
+ return this.act(agent => agent.remove(id));
206
+ }
207
+ async signOut() {
208
+ var _a;
209
+ if (this.agent) {
210
+ await this.agent.signOut();
211
+ this.forget();
212
+ (_a = (0, workbench_util_1.storage)()) === null || _a === void 0 ? void 0 : _a.setItem(OFF_KEY, '1');
213
+ }
214
+ this.error = undefined;
215
+ return this.read();
216
+ }
217
+ }
218
+ exports.DeviceAccount = DeviceAccount;
219
+ //# sourceMappingURL=device-account.js.map
@@ -43,6 +43,7 @@ const connection_bar_1 = require("../components/connection-bar");
43
43
  const side_lists_1 = require("../components/side-lists");
44
44
  const use_seen_chats_1 = require("../components/use-seen-chats");
45
45
  const web_extension_protocol_1 = require("../extension/web-extension-protocol");
46
+ const web_home_1 = require("../extension/web-home");
46
47
  const web_tasks_1 = require("../extension/web-tasks");
47
48
  const hooks_1 = require("../hooks");
48
49
  const use_t_1 = require("../i18n/use-t");
@@ -84,7 +85,7 @@ function useChatHome(onPicked) {
84
85
  latest.current = onPicked;
85
86
  const name = view ? web_extension_protocol_1.WebLabelUtil.text(view.title) : t('ta.builtin.assistant');
86
87
  const shown = extensions.page === side_lists_1.DOUBLE_PAGE;
87
- const shownItem = extensions.page && !extensions.pageHidden ? extensions.pageFrom : undefined;
88
+ const shownItem = web_home_1.WebHomeUtil.shown(extensions);
88
89
  return React.useMemo(() => {
89
90
  if (listed) {
90
91
  return undefined;
@@ -2,7 +2,7 @@ import { type LucideIcon } from 'lucide-react';
2
2
  import * as React from 'react';
3
3
  import type { SettingsSection } from './settings-view';
4
4
  /** What an entry of the account opens over the page. */
5
- export type AccountDialog = 'accounts' | 'directory' | 'relay' | 'hosts';
5
+ export type AccountDialog = 'accounts' | 'directory' | 'relay' | 'hosts' | 'devices';
6
6
  export interface AccountChoice {
7
7
  key: string;
8
8
  label: string;
@@ -46,11 +46,13 @@ const hooks_1 = require("../hooks");
46
46
  const hosts_1 = require("../hosts");
47
47
  const use_t_1 = require("../i18n/use-t");
48
48
  const workbench_util_1 = require("../workbench-util");
49
+ const account_view_1 = require("./account-view");
49
50
  const auth_view_1 = require("./auth-view");
50
51
  const dino_look_picker_1 = require("./dino-look-picker");
51
52
  const dismiss_1 = require("./dismiss");
52
53
  const host_view_1 = require("./host-view");
53
54
  const icon_1 = require("./icon");
55
+ const picture_dialog_1 = require("./picture-dialog");
54
56
  const relay_view_1 = require("./relay-view");
55
57
  const serve_restart_1 = require("./serve-restart");
56
58
  const settings_controls_1 = require("./settings-controls");
@@ -87,12 +89,14 @@ function useAccountEntries(onSettings, onDialog) {
87
89
  });
88
90
  return [
89
91
  [
92
+ entry('picture', t('ta.picture.title'), lucide_react_1.CircleUserRound, () => picture_dialog_1.PicturePicker.open()),
90
93
  entry('look', t('ta.look.title'), lucide_react_1.Sparkles, () => dino_look_picker_1.DinoLookPicker.open()),
91
94
  entry('settings', t('ta.settings'), lucide_react_1.Settings2, () => onSettings(), { keys: touch ? undefined : 'Mod+,' }),
92
95
  entry('packages', t('ta.manage.packages'), lucide_react_1.Puzzle, () => onSettings('packages')),
93
96
  ...(touch ? [] : [entry('shortcuts', t('ta.manage.shortcuts'), lucide_react_1.Keyboard, () => onSettings('shortcuts'))]),
94
97
  ],
95
98
  [
99
+ entry('devices', t('ta.myDevices.title'), lucide_react_1.MonitorSmartphone, () => onDialog('devices')),
96
100
  entry('hosts', t('ta.hosts.title'), lucide_react_1.Monitor, () => onDialog('hosts'), { detail: inUse && (hosts_1.HostUtil.label(inUse) || t('ta.hosts.thisServer')) }),
97
101
  entry('accounts', t('ta.manage.accounts'), lucide_react_1.KeyRound, () => onDialog('accounts')),
98
102
  entry('directory', t('ta.manage.workingDirectory'), lucide_react_1.FolderOpen, () => onDialog('directory')),
@@ -136,7 +140,8 @@ function AccountDialogs({ dialog, onClose }) {
136
140
  dialog === 'accounts' && React.createElement(auth_view_1.AuthDialog, { onClose: onClose }),
137
141
  dialog === 'directory' && React.createElement(working_directory_1.WorkingDirectoryPicker, { onClose: onClose }),
138
142
  dialog === 'relay' && React.createElement(relay_view_1.RelayDialog, { onClose: onClose }),
139
- dialog === 'hosts' && React.createElement(host_view_1.HostsDialog, { onClose: onClose })));
143
+ dialog === 'hosts' && React.createElement(host_view_1.HostsDialog, { onClose: onClose }),
144
+ dialog === 'devices' && React.createElement(account_view_1.DevicesDialog, { onClose: onClose })));
140
145
  }
141
146
  /** The round figure of the account: a close-up of the double, the dinosaur the user picked for it (a T. rex until then). */
142
147
  function AccountFigure({ size, className }) {