@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.
- package/esm/browser/account/account-side.d.ts +13 -0
- package/esm/browser/account/account-side.js +74 -0
- package/esm/browser/account/device-account.d.ts +69 -0
- package/esm/browser/account/device-account.js +215 -0
- package/esm/browser/assistant/assistant-chat-list.js +2 -1
- package/esm/browser/components/account-menu.d.ts +1 -1
- package/esm/browser/components/account-menu.js +7 -2
- package/esm/browser/components/account-view.d.ts +17 -0
- package/esm/browser/components/account-view.js +216 -0
- package/esm/browser/components/app-view.js +4 -4
- package/esm/browser/components/cloud-sign-in-view.d.ts +5 -1
- package/esm/browser/components/cloud-sign-in-view.js +1 -1
- package/esm/browser/components/dino-look.d.ts +9 -1
- package/esm/browser/components/dino-look.js +46 -1
- package/esm/browser/components/environment-view.js +12 -1
- package/esm/browser/components/face-pictures.d.ts +10 -0
- package/esm/browser/components/face-pictures.js +24 -0
- package/esm/browser/components/face.d.ts +4 -1
- package/esm/browser/components/face.js +16 -1
- package/esm/browser/components/host-view.d.ts +3 -1
- package/esm/browser/components/host-view.js +7 -0
- package/esm/browser/components/picture-dialog.d.ts +18 -0
- package/esm/browser/components/picture-dialog.js +116 -0
- package/esm/browser/components/workbench-view.js +5 -1
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-api-home.d.ts +13 -0
- package/esm/browser/extension/web-api-home.js +2 -0
- package/esm/browser/extension/web-extension-api.d.ts +4 -4
- package/esm/browser/extension/web-extension-context.js +2 -1
- package/esm/browser/extension/web-home.d.ts +8 -0
- package/esm/browser/extension/web-home.js +20 -0
- package/esm/browser/gateway/console-limits.d.ts +15 -0
- package/esm/browser/gateway/console-limits.js +2 -2
- package/esm/browser/gateway/console-tenant.js +33 -2
- package/esm/browser/gateway/console-updates.d.ts +12 -0
- package/esm/browser/gateway/console-updates.js +76 -0
- package/esm/browser/gateway/console-util.d.ts +7 -1
- package/esm/browser/gateway/console-util.js +18 -0
- package/esm/browser/gateway/console-view.js +9 -2
- package/esm/browser/hosts.d.ts +5 -0
- package/esm/browser/hosts.js +11 -0
- package/esm/browser/i18n/locales.d.ts +69 -3
- package/esm/browser/i18n/locales.js +9 -3
- package/esm/browser/i18n/messages-all.d.ts +7 -0
- package/esm/browser/i18n/messages-all.js +14 -0
- package/esm/browser/i18n/messages-ja.js +64 -0
- package/esm/browser/i18n/messages-zh-tw.js +64 -0
- package/esm/browser/i18n/messages.d.ts +70 -8
- package/esm/browser/i18n/messages.js +161 -11
- package/esm/browser/i18n/use-t.js +4 -3
- package/esm/browser/settings/settings.js +3 -1
- package/esm/browser/style/dialogs.d.ts +1 -1
- package/esm/browser/style/dialogs.js +31 -0
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +5 -0
- package/esm/browser/style/phone.d.ts +1 -1
- package/esm/browser/style/phone.js +2 -1
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +1 -0
- package/esm/browser/util/picture.d.ts +5 -0
- package/esm/browser/util/picture.js +43 -0
- package/esm/browser/workbench-hosts.d.ts +7 -0
- package/esm/browser/workbench-hosts.js +20 -0
- package/esm/browser/workbench-protocol.d.ts +8 -1
- package/esm/browser/workbench-services.d.ts +2 -1
- package/esm/browser/workbench-services.js +3 -0
- package/esm/browser/workbench-util.d.ts +1 -1
- package/lib/browser/account/account-side.d.ts +14 -0
- package/lib/browser/account/account-side.js +111 -0
- package/lib/browser/account/device-account.d.ts +70 -0
- package/lib/browser/account/device-account.js +219 -0
- package/lib/browser/assistant/assistant-chat-list.js +2 -1
- package/lib/browser/components/account-menu.d.ts +1 -1
- package/lib/browser/components/account-menu.js +6 -1
- package/lib/browser/components/account-view.d.ts +18 -0
- package/lib/browser/components/account-view.js +255 -0
- package/lib/browser/components/app-view.js +2 -2
- package/lib/browser/components/cloud-sign-in-view.d.ts +5 -1
- package/lib/browser/components/cloud-sign-in-view.js +1 -0
- package/lib/browser/components/dino-look.d.ts +9 -1
- package/lib/browser/components/dino-look.js +48 -1
- package/lib/browser/components/environment-view.js +11 -0
- package/lib/browser/components/face-pictures.d.ts +11 -0
- package/lib/browser/components/face-pictures.js +60 -0
- package/lib/browser/components/face.d.ts +4 -1
- package/lib/browser/components/face.js +16 -1
- package/lib/browser/components/host-view.d.ts +3 -1
- package/lib/browser/components/host-view.js +8 -0
- package/lib/browser/components/picture-dialog.d.ts +19 -0
- package/lib/browser/components/picture-dialog.js +153 -0
- package/lib/browser/components/workbench-view.js +5 -1
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-api-home.d.ts +14 -0
- package/lib/browser/extension/web-api-home.js +3 -0
- package/lib/browser/extension/web-extension-api.d.ts +4 -4
- package/lib/browser/extension/web-extension-context.js +2 -1
- package/lib/browser/extension/web-home.d.ts +8 -0
- package/lib/browser/extension/web-home.js +54 -1
- package/lib/browser/gateway/console-limits.d.ts +15 -0
- package/lib/browser/gateway/console-limits.js +2 -0
- package/lib/browser/gateway/console-tenant.js +32 -1
- package/lib/browser/gateway/console-updates.d.ts +13 -0
- package/lib/browser/gateway/console-updates.js +113 -0
- package/lib/browser/gateway/console-util.d.ts +7 -1
- package/lib/browser/gateway/console-util.js +18 -0
- package/lib/browser/gateway/console-view.js +9 -2
- package/lib/browser/hosts.d.ts +5 -0
- package/lib/browser/hosts.js +11 -0
- package/lib/browser/i18n/locales.d.ts +69 -3
- package/lib/browser/i18n/locales.js +8 -2
- package/lib/browser/i18n/messages-all.d.ts +8 -0
- package/lib/browser/i18n/messages-all.js +17 -0
- package/lib/browser/i18n/messages-ja.js +64 -0
- package/lib/browser/i18n/messages-zh-tw.js +64 -0
- package/lib/browser/i18n/messages.d.ts +70 -8
- package/lib/browser/i18n/messages.js +163 -13
- package/lib/browser/i18n/use-t.js +4 -3
- package/lib/browser/settings/settings.js +3 -1
- package/lib/browser/style/dialogs.d.ts +1 -1
- package/lib/browser/style/dialogs.js +31 -0
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +5 -0
- package/lib/browser/style/phone.d.ts +1 -1
- package/lib/browser/style/phone.js +2 -1
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +1 -0
- package/lib/browser/util/picture.d.ts +6 -0
- package/lib/browser/util/picture.js +46 -0
- package/lib/browser/workbench-hosts.d.ts +7 -0
- package/lib/browser/workbench-hosts.js +20 -0
- package/lib/browser/workbench-protocol.d.ts +8 -1
- package/lib/browser/workbench-services.d.ts +2 -1
- package/lib/browser/workbench-services.js +3 -0
- package/lib/browser/workbench-util.d.ts +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TaAccountInfo } from '@celljs/ta-protocol';
|
|
2
|
+
import { type AccountSide } from './device-account.js';
|
|
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
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { relayDefaultUrl } from '@celljs/ta-relay';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CloudSignInUtil } from '../cloud/cloud-sign-in.js';
|
|
4
|
+
import { useWorkbench } from '../hooks.js';
|
|
5
|
+
import { WorkbenchUtil } from '../workbench-util.js';
|
|
6
|
+
import { DeviceAccount } from './device-account.js';
|
|
7
|
+
/** The account of the computer of the page, through its ta serve (TaAccountServer). */
|
|
8
|
+
function serveSide(account) {
|
|
9
|
+
return {
|
|
10
|
+
read: () => account.getAccount(),
|
|
11
|
+
signIn: (provider, service) => account.signIn(provider, service),
|
|
12
|
+
cancelSignIn: () => account.cancelSignIn(),
|
|
13
|
+
approve: id => account.approve(id),
|
|
14
|
+
remove: id => account.remove(id),
|
|
15
|
+
signOut: () => account.signOut(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The relay the app's account is on: that of the computers it is paired with, as theirs is; else the relay of the
|
|
20
|
+
* deployment this build is for, else the default one.
|
|
21
|
+
*/
|
|
22
|
+
async function appService(hosts, current) {
|
|
23
|
+
var _a;
|
|
24
|
+
var _b, _c, _d;
|
|
25
|
+
const paired = (one) => (one && 'pairing' in one.credential ? one.credential.pairing.relay : undefined);
|
|
26
|
+
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 CloudSignInUtil.distribution())) === null || _a === void 0 ? void 0 : _a.relay) !== null && _d !== void 0 ? _d : relayDefaultUrl());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The account a page shows (docs/design/ta-account.md): in the app, the phone's own; elsewhere, that of the computer
|
|
30
|
+
* whose page it is, once connected to it.
|
|
31
|
+
*/
|
|
32
|
+
export function useAccountSide() {
|
|
33
|
+
const [{ status, hosts, host }, bench] = useWorkbench();
|
|
34
|
+
const app = WorkbenchUtil.isApp();
|
|
35
|
+
const where = React.useRef({ hosts, host });
|
|
36
|
+
where.current = { hosts, host };
|
|
37
|
+
const online = status === 'online';
|
|
38
|
+
return React.useMemo(() => {
|
|
39
|
+
if (app) {
|
|
40
|
+
return DeviceAccount.of(bench, () => appService(where.current.hosts, where.current.host), async () => {
|
|
41
|
+
var _a;
|
|
42
|
+
const chosen = CloudSignInUtil.chosen();
|
|
43
|
+
const built = (_a = (await CloudSignInUtil.distribution())) === null || _a === void 0 ? void 0 : _a.gateway;
|
|
44
|
+
return [chosen, built].filter((one) => !!one);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return online ? serveSide(bench.account) : undefined;
|
|
48
|
+
}, [app, online, bench]);
|
|
49
|
+
}
|
|
50
|
+
/** The account as it is now, read again every few seconds while shown; `act` runs a change and shows what it made. */
|
|
51
|
+
export function useAccountInfo(side, every = 3000) {
|
|
52
|
+
const [info, setInfo] = React.useState();
|
|
53
|
+
const [failed, setFailed] = React.useState();
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (!side) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let live = true;
|
|
59
|
+
const read = () => side.read().then(next => live && setInfo(next), (error) => live && setFailed(error));
|
|
60
|
+
void read();
|
|
61
|
+
const timer = setInterval(() => document.visibilityState !== 'hidden' && void read(), every);
|
|
62
|
+
return () => {
|
|
63
|
+
live = false;
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
};
|
|
66
|
+
}, [side, every]);
|
|
67
|
+
const act = React.useCallback(async (run) => {
|
|
68
|
+
if (side) {
|
|
69
|
+
setInfo(await run(side));
|
|
70
|
+
}
|
|
71
|
+
}, [side]);
|
|
72
|
+
return { info, failed, act };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=account-side.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
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.js';
|
|
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
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { AccountAgent, AccountCallError, AccountService } from '@celljs/ta-relay';
|
|
2
|
+
import { storage } from '../workbench-util.js';
|
|
3
|
+
const KEY = 'ta.account';
|
|
4
|
+
/** Signed out of the account by the user: not signed in again by itself with the token of a Ta in the cloud. */
|
|
5
|
+
const OFF_KEY = 'ta.account.off';
|
|
6
|
+
const SYNC_MS = 15000;
|
|
7
|
+
const WAITING_SYNC_MS = 3000;
|
|
8
|
+
/**
|
|
9
|
+
* The app as a device of the user's account (docs/design/ta-account.md): its own keys in localStorage; the computers
|
|
10
|
+
* 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
|
|
11
|
+
* computer's (AccountAgent), with the hooks of a device that pairs with computers rather than letting devices in.
|
|
12
|
+
*/
|
|
13
|
+
export class DeviceAccount {
|
|
14
|
+
constructor(hosts, service, gateways) {
|
|
15
|
+
this.hosts = hosts;
|
|
16
|
+
this.service = service;
|
|
17
|
+
this.gateways = gateways;
|
|
18
|
+
const kept = DeviceAccount.read();
|
|
19
|
+
if (kept) {
|
|
20
|
+
this.agent = this.agentOf(kept);
|
|
21
|
+
}
|
|
22
|
+
this.schedule(0);
|
|
23
|
+
document.addEventListener('visibilitychange', () => document.visibilityState === 'visible' && this.schedule(0));
|
|
24
|
+
}
|
|
25
|
+
/** The one of the page. */
|
|
26
|
+
static of(hosts, service, gateways) {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = DeviceAccount.instance) !== null && _a !== void 0 ? _a : (DeviceAccount.instance = new DeviceAccount(hosts, service, gateways));
|
|
29
|
+
return DeviceAccount.instance;
|
|
30
|
+
}
|
|
31
|
+
/** What the device calls itself in the account. */
|
|
32
|
+
static deviceName(agent = navigator.userAgent) {
|
|
33
|
+
return /iPad/.test(agent) ? 'iPad' : /iPhone/.test(agent) ? 'iPhone' : /Android/.test(agent) ? 'Android' : 'Phone';
|
|
34
|
+
}
|
|
35
|
+
static read() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
var _c;
|
|
38
|
+
try {
|
|
39
|
+
const kept = JSON.parse((_c = (_a = storage()) === null || _a === void 0 ? void 0 : _a.getItem(KEY)) !== null && _c !== void 0 ? _c : 'null');
|
|
40
|
+
return (kept === null || kept === void 0 ? void 0 : kept.token) && ((_b = kept.self) === null || _b === void 0 ? void 0 : _b.signKey) ? kept : undefined;
|
|
41
|
+
}
|
|
42
|
+
catch (_d) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
agentOf(kept) {
|
|
47
|
+
return new AccountAgent(kept, {
|
|
48
|
+
save: next => { var _a; return (_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(next)); },
|
|
49
|
+
name: () => DeviceAccount.deviceName(),
|
|
50
|
+
pairing: (from, link) => this.hosts.addAccountHost(link, from.id),
|
|
51
|
+
unpaired: from => this.hosts.forgetAccountHosts(from),
|
|
52
|
+
signedOut: () => {
|
|
53
|
+
var _a;
|
|
54
|
+
this.forget();
|
|
55
|
+
// A token no longer good, or this device removed: not joined again by itself.
|
|
56
|
+
(_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(OFF_KEY, '1');
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** A Ta in the cloud signed in to: its token is the account of its gateway, which this device joins by itself. */
|
|
61
|
+
cloudToken() {
|
|
62
|
+
for (const host of this.hosts.state.hosts) {
|
|
63
|
+
if ('token' in host.credential && host.credential.url) {
|
|
64
|
+
return { service: host.credential.url.replace(/\/+$/, ''), token: host.credential.token };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Joins the account of the gateway of a Ta in the cloud of this device, unless the user left the account. */
|
|
70
|
+
async adopt() {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const cloud = ((_a = storage()) === null || _a === void 0 ? void 0 : _a.getItem(OFF_KEY)) ? undefined : this.cloudToken();
|
|
73
|
+
if (!cloud || !(await AccountService.ways(cloud.service, [cloud.service])).some(one => one.gateway)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const kept = await AccountAgent.create(cloud.service, cloud.token, { id: '', name: '' }, 'phone', DeviceAccount.deviceName());
|
|
77
|
+
(_b = storage()) === null || _b === void 0 ? void 0 : _b.setItem(KEY, JSON.stringify(kept));
|
|
78
|
+
this.agent = this.agentOf(kept);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
forget() {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = storage()) === null || _a === void 0 ? void 0 : _a.removeItem(KEY);
|
|
84
|
+
this.agent = undefined;
|
|
85
|
+
this.view = undefined;
|
|
86
|
+
this.hosts.forgetAccountHosts();
|
|
87
|
+
}
|
|
88
|
+
schedule(after) {
|
|
89
|
+
clearTimeout(this.timer);
|
|
90
|
+
if (!this.agent && !this.signingIn && !this.cloudToken()) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.timer = setTimeout(() => void this.round(), after);
|
|
94
|
+
}
|
|
95
|
+
round() {
|
|
96
|
+
var _a;
|
|
97
|
+
(_a = this.running) !== null && _a !== void 0 ? _a : (this.running = (async () => {
|
|
98
|
+
let next = SYNC_MS;
|
|
99
|
+
try {
|
|
100
|
+
if (this.signingIn) {
|
|
101
|
+
next = await this.pollSignIn();
|
|
102
|
+
}
|
|
103
|
+
else if (this.agent || (await this.adopt())) {
|
|
104
|
+
const agent = this.agent;
|
|
105
|
+
this.view = await agent.sync();
|
|
106
|
+
this.error = undefined;
|
|
107
|
+
if (this.view.waiting || this.view.devices.some(one => one.waiting)) {
|
|
108
|
+
next = WAITING_SYNC_MS;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
this.running = undefined;
|
|
117
|
+
}
|
|
118
|
+
if (document.visibilityState !== 'hidden') {
|
|
119
|
+
this.schedule(next);
|
|
120
|
+
}
|
|
121
|
+
})());
|
|
122
|
+
return this.running;
|
|
123
|
+
}
|
|
124
|
+
async pollSignIn() {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
const signing = this.signingIn;
|
|
127
|
+
if (Date.now() > signing.expiresAt) {
|
|
128
|
+
this.signingIn = undefined;
|
|
129
|
+
return SYNC_MS;
|
|
130
|
+
}
|
|
131
|
+
const answer = await AccountService.check(signing.way, signing.handle);
|
|
132
|
+
if (answer.status === 'pending') {
|
|
133
|
+
return signing.interval * 1000;
|
|
134
|
+
}
|
|
135
|
+
this.signingIn = undefined;
|
|
136
|
+
if (answer.status === 'failed') {
|
|
137
|
+
this.error = answer.error;
|
|
138
|
+
return SYNC_MS;
|
|
139
|
+
}
|
|
140
|
+
const kept = await AccountAgent.create(signing.way.service, answer.token, answer.account, 'phone', DeviceAccount.deviceName());
|
|
141
|
+
(_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(kept));
|
|
142
|
+
(_b = storage()) === null || _b === void 0 ? void 0 : _b.removeItem(OFF_KEY);
|
|
143
|
+
this.agent = this.agentOf(kept);
|
|
144
|
+
this.view = await this.agent.sync();
|
|
145
|
+
return WAITING_SYNC_MS;
|
|
146
|
+
}
|
|
147
|
+
async read() {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
var _c, _d;
|
|
150
|
+
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());
|
|
151
|
+
const error = this.error ? { error: this.error } : {};
|
|
152
|
+
if (!this.agent) {
|
|
153
|
+
const signing = this.signingIn;
|
|
154
|
+
return {
|
|
155
|
+
service,
|
|
156
|
+
providers: await AccountService.ways(service, await this.gateways().catch(() => [])).catch(() => []),
|
|
157
|
+
devices: [],
|
|
158
|
+
...(signing ? { signingIn: { provider: signing.way.id, code: signing.code, url: signing.url, expiresAt: signing.expiresAt } } : {}),
|
|
159
|
+
...error,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (!this.view) {
|
|
163
|
+
await this.round();
|
|
164
|
+
}
|
|
165
|
+
const view = this.view;
|
|
166
|
+
if (!view) {
|
|
167
|
+
return { service, providers: [], account: this.agent.state.account, devices: [], ...error };
|
|
168
|
+
}
|
|
169
|
+
const devices = view.devices.map(({ trusted: _trusted, ...device }) => device);
|
|
170
|
+
return { service, providers: [], account: view.account, waiting: view.waiting, code: view.code, devices, ...error };
|
|
171
|
+
}
|
|
172
|
+
async signIn(provider, service) {
|
|
173
|
+
if (!this.agent) {
|
|
174
|
+
const ways = await AccountService.ways(await this.service(), await this.gateways().catch(() => []));
|
|
175
|
+
const way = ways.find(one => one.id === provider && (service === undefined || one.service === service));
|
|
176
|
+
if (!way) {
|
|
177
|
+
throw new AccountCallError(404, `No way to sign in with ${provider} here.`);
|
|
178
|
+
}
|
|
179
|
+
const start = await AccountService.begin(way, DeviceAccount.deviceName());
|
|
180
|
+
this.signingIn = { way, ...start, expiresAt: Date.now() + start.expiresIn * 1000 };
|
|
181
|
+
this.error = undefined;
|
|
182
|
+
this.schedule(start.interval * 1000);
|
|
183
|
+
}
|
|
184
|
+
return this.read();
|
|
185
|
+
}
|
|
186
|
+
async cancelSignIn() {
|
|
187
|
+
this.signingIn = undefined;
|
|
188
|
+
return this.read();
|
|
189
|
+
}
|
|
190
|
+
async act(run) {
|
|
191
|
+
if (!this.agent) {
|
|
192
|
+
throw new AccountCallError(401, 'Sign in to an account first.');
|
|
193
|
+
}
|
|
194
|
+
this.view = await run(this.agent);
|
|
195
|
+
this.schedule(WAITING_SYNC_MS);
|
|
196
|
+
return this.read();
|
|
197
|
+
}
|
|
198
|
+
approve(id) {
|
|
199
|
+
return this.act(agent => agent.approve(id));
|
|
200
|
+
}
|
|
201
|
+
remove(id) {
|
|
202
|
+
return this.act(agent => agent.remove(id));
|
|
203
|
+
}
|
|
204
|
+
async signOut() {
|
|
205
|
+
var _a;
|
|
206
|
+
if (this.agent) {
|
|
207
|
+
await this.agent.signOut();
|
|
208
|
+
this.forget();
|
|
209
|
+
(_a = storage()) === null || _a === void 0 ? void 0 : _a.setItem(OFF_KEY, '1');
|
|
210
|
+
}
|
|
211
|
+
this.error = undefined;
|
|
212
|
+
return this.read();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=device-account.js.map
|
|
@@ -6,6 +6,7 @@ import { ConnectionBanner } from '../components/connection-bar.js';
|
|
|
6
6
|
import { DOUBLE_PAGE, SideListUtil } from '../components/side-lists.js';
|
|
7
7
|
import { useSeenChats } from '../components/use-seen-chats.js';
|
|
8
8
|
import { WebLabelUtil } from '../extension/web-extension-protocol.js';
|
|
9
|
+
import { WebHomeUtil } from '../extension/web-home.js';
|
|
9
10
|
import { WebTaskUtil } from '../extension/web-tasks.js';
|
|
10
11
|
import { useNotices, useWebExtensions } from '../hooks.js';
|
|
11
12
|
import { useT } from '../i18n/use-t.js';
|
|
@@ -47,7 +48,7 @@ function useChatHome(onPicked) {
|
|
|
47
48
|
latest.current = onPicked;
|
|
48
49
|
const name = view ? WebLabelUtil.text(view.title) : t('ta.builtin.assistant');
|
|
49
50
|
const shown = extensions.page === DOUBLE_PAGE;
|
|
50
|
-
const shownItem =
|
|
51
|
+
const shownItem = WebHomeUtil.shown(extensions);
|
|
51
52
|
return React.useMemo(() => {
|
|
52
53
|
if (listed) {
|
|
53
54
|
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.js';
|
|
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;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { TaLanguageUtil } from '@celljs/ta-protocol';
|
|
2
|
-
import { ArrowLeftRight, Check, ChevronRight, Download, FolderOpen, Info, Keyboard, KeyRound, Languages, LogOut, Monitor, Palette, Puzzle, RotateCw, Settings2, Smartphone, Sparkles, } from 'lucide-react';
|
|
2
|
+
import { ArrowLeftRight, Check, ChevronRight, CircleUserRound, Download, FolderOpen, Info, Keyboard, KeyRound, Languages, LogOut, Monitor, MonitorSmartphone, Palette, Puzzle, RotateCw, Settings2, Smartphone, Sparkles, } from 'lucide-react';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useDevice } from '../device/device.js';
|
|
5
5
|
import { usePwa, useSettings, useWorkbench } from '../hooks.js';
|
|
6
6
|
import { HostUtil } from '../hosts.js';
|
|
7
7
|
import { useT } from '../i18n/use-t.js';
|
|
8
8
|
import { WorkbenchUtil } from '../workbench-util.js';
|
|
9
|
+
import { DevicesDialog } from './account-view.js';
|
|
9
10
|
import { AuthDialog } from './auth-view.js';
|
|
10
11
|
import { DinoLookPicker } from './dino-look-picker.js';
|
|
11
12
|
import { useDismiss } from './dismiss.js';
|
|
12
13
|
import { HostsDialog } from './host-view.js';
|
|
13
14
|
import { Icon } from './icon.js';
|
|
15
|
+
import { PicturePicker } from './picture-dialog.js';
|
|
14
16
|
import { RelayDialog } from './relay-view.js';
|
|
15
17
|
import { ServeRestartUtil, useRestartTa } from './serve-restart.js';
|
|
16
18
|
import { Keys } from './settings-controls.js';
|
|
@@ -47,12 +49,14 @@ export function useAccountEntries(onSettings, onDialog) {
|
|
|
47
49
|
});
|
|
48
50
|
return [
|
|
49
51
|
[
|
|
52
|
+
entry('picture', t('ta.picture.title'), CircleUserRound, () => PicturePicker.open()),
|
|
50
53
|
entry('look', t('ta.look.title'), Sparkles, () => DinoLookPicker.open()),
|
|
51
54
|
entry('settings', t('ta.settings'), Settings2, () => onSettings(), { keys: touch ? undefined : 'Mod+,' }),
|
|
52
55
|
entry('packages', t('ta.manage.packages'), Puzzle, () => onSettings('packages')),
|
|
53
56
|
...(touch ? [] : [entry('shortcuts', t('ta.manage.shortcuts'), Keyboard, () => onSettings('shortcuts'))]),
|
|
54
57
|
],
|
|
55
58
|
[
|
|
59
|
+
entry('devices', t('ta.myDevices.title'), MonitorSmartphone, () => onDialog('devices')),
|
|
56
60
|
entry('hosts', t('ta.hosts.title'), Monitor, () => onDialog('hosts'), { detail: inUse && (HostUtil.label(inUse) || t('ta.hosts.thisServer')) }),
|
|
57
61
|
entry('accounts', t('ta.manage.accounts'), KeyRound, () => onDialog('accounts')),
|
|
58
62
|
entry('directory', t('ta.manage.workingDirectory'), FolderOpen, () => onDialog('directory')),
|
|
@@ -96,7 +100,8 @@ export function AccountDialogs({ dialog, onClose }) {
|
|
|
96
100
|
dialog === 'accounts' && React.createElement(AuthDialog, { onClose: onClose }),
|
|
97
101
|
dialog === 'directory' && React.createElement(WorkingDirectoryPicker, { onClose: onClose }),
|
|
98
102
|
dialog === 'relay' && React.createElement(RelayDialog, { onClose: onClose }),
|
|
99
|
-
dialog === 'hosts' && React.createElement(HostsDialog, { onClose: onClose })
|
|
103
|
+
dialog === 'hosts' && React.createElement(HostsDialog, { onClose: onClose }),
|
|
104
|
+
dialog === 'devices' && React.createElement(DevicesDialog, { onClose: onClose })));
|
|
100
105
|
}
|
|
101
106
|
/** The round figure of the account: a close-up of the double, the dinosaur the user picked for it (a T. rex until then). */
|
|
102
107
|
export function AccountFigure({ size, className }) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { AccountSide } from '../account/device-account.js';
|
|
3
|
+
/** What the account panel shows: signing in, waiting, or the devices. */
|
|
4
|
+
export declare function AccountPanel({ side }: {
|
|
5
|
+
side: AccountSide;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
/** The account and its devices, over the page: from Me, the menu of the account, the settings. */
|
|
8
|
+
export declare function DevicesDialog({ onClose }: {
|
|
9
|
+
onClose(): void;
|
|
10
|
+
}): React.ReactPortal;
|
|
11
|
+
/**
|
|
12
|
+
* A device asks to join the account: whichever device of it the user has at hand says so, with the code to compare,
|
|
13
|
+
* until it is let in, refused, or put off for now.
|
|
14
|
+
*/
|
|
15
|
+
export declare function AccountAsk(): React.ReactPortal | null;
|
|
16
|
+
/** On the sign-in of the app: sign in to the account, and the computers of it come by themselves. */
|
|
17
|
+
export declare function AccountSignInEntry(): React.JSX.Element | null;
|