@coda-console/friends 0.6.0 → 0.7.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 +65 -7
- package/lib/friends.mjs +7 -4
- package/lib/gateway.mjs +72 -9
- package/lib/outbox.mjs +10 -5
- package/lib/rpc-caller.mjs +474 -0
- package/lib/rpc-format.mjs +288 -0
- package/lib/rpc-holder.mjs +723 -0
- package/lib/rpc-store.mjs +556 -0
- package/main.mjs +62 -4
- package/package.json +15 -2
- package/view/app.mjs +375 -36
- package/view/style.css +43 -0
package/package.json
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
"displayName": "好友",
|
|
5
5
|
"description": "管理 Accord 身份与熟人好友通道,并提供业务无关的好友网关",
|
|
6
6
|
"icon": { "symbol": "person.2.fill", "color": "blue" },
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.7.0",
|
|
8
8
|
"categories": [
|
|
9
9
|
"Skills 与工具"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
12
|
"engines": {
|
|
13
|
-
"coda":
|
|
13
|
+
"coda": 17
|
|
14
14
|
},
|
|
15
15
|
"main": "main.mjs",
|
|
16
16
|
"activationEvents": [
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"manage"
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
|
+
"optionalUses": {
|
|
27
|
+
"remote-exec/machine@1": [
|
|
28
|
+
"use"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
26
31
|
"contributes": {
|
|
27
32
|
"views": [
|
|
28
33
|
{
|
|
@@ -203,6 +208,14 @@
|
|
|
203
208
|
],
|
|
204
209
|
"protocolImplementations": [
|
|
205
210
|
"friends/social@1"
|
|
211
|
+
],
|
|
212
|
+
"optionalProtocolImplementations": [
|
|
213
|
+
"remote-exec/machine@1"
|
|
214
|
+
],
|
|
215
|
+
"reservedAccordKinds": [
|
|
216
|
+
"friends/rpc-grant",
|
|
217
|
+
"friends/rpc-call",
|
|
218
|
+
"friends/rpc-answer"
|
|
206
219
|
]
|
|
207
220
|
},
|
|
208
221
|
"license": "MIT",
|
package/view/app.mjs
CHANGED
|
@@ -1,27 +1,59 @@
|
|
|
1
1
|
// 好友页:各台电脑的 Accord 身份(Hero)、按电脑分节的好友列表与详情、添加好友。
|
|
2
2
|
// 页面不自己选机器:视图里有几台就都读,身份按公钥归组、好友按电脑分节(lib/view-members.mjs);写操作发往它所在的那一台。
|
|
3
|
-
// Accord 的读写(coda/accord@1
|
|
3
|
+
// Accord 的读写(coda/accord@1)都在这里按交互发起;「共享」(授给好友的、好友授给本机的远程执行、最近的操作)只经模块读写各台本机。
|
|
4
|
+
// 昵称、头像都由 Accord 公钥推出(nickname.mjs、avatar.mjs),没有可编辑的名片;
|
|
4
5
|
// 节点名等外来数据一律用 textContent / DOM API 渲染,从不拼 HTML 字符串。
|
|
5
6
|
import { accordStatusSummary, resolveAvatar } from '../lib/avatar.mjs';
|
|
6
7
|
import { checked, parseInvite } from '../lib/friends.mjs';
|
|
7
8
|
import { identityTitle } from '../lib/nickname.mjs';
|
|
8
9
|
import { friendSections, identities, listMembers } from '../lib/view-members.mjs';
|
|
9
|
-
import { fill, h, identiconSvg } from './dom.mjs';
|
|
10
|
+
import { fill, h, identiconSvg, svg } from './dom.mjs';
|
|
10
11
|
|
|
11
12
|
const ACCORD = 'coda/accord@1', LOCAL = { kind: ACCORD, id: 'local' };
|
|
12
13
|
const coda = window.coda;
|
|
13
14
|
const root = document.getElementById('root');
|
|
14
15
|
const STATUS_TEXT = { bound: '已互认', pending: '待互认', conflict: '密钥冲突' };
|
|
16
|
+
const MACHINE_KIND = 'remote-exec/machine@1';
|
|
17
|
+
const RECOVER_MS = 3000;
|
|
18
|
+
// 结果不明的撤销:连续读到这么多遍有效列表、授权仍可用,就不再自动重发。
|
|
19
|
+
const REVOKE_RETRIES = 3;
|
|
20
|
+
// 结果不明的授予:连续读到这么多遍有效列表、里面都没有这条授权,就回滚这一行,允许重试(持有方对同一目标的授予幂等)。
|
|
21
|
+
const GRANT_CONFIRMS = 3;
|
|
15
22
|
|
|
16
23
|
// 视图里的每台电脑(成员在页面生命周期内不变)各存一份数据;读不到的(unreachable)也在,只是不发请求。
|
|
17
24
|
const members = listMembers(coda).map(m => ({ ...m, entry: null, author: null, friends: [], loaded: false, accordProblem: null }));
|
|
18
25
|
const live = members.filter(m => !m.unreachable);
|
|
19
26
|
const multi = members.length > 1;
|
|
20
|
-
const state = { busy: new Set(), notice: new Map(), heroNotice: new Map(), detail: null, removing: null };
|
|
27
|
+
const state = { busy: new Set(), notice: new Map(), heroNotice: new Map(), detail: null, removing: null, menu: null };
|
|
21
28
|
const via = m => ({ machine: m.id });
|
|
22
29
|
const rowKey = (m, node) => `${m.id}\u0000${node}`;
|
|
23
30
|
function say(target, text, kind = 'hint') { target.className = kind; target.textContent = text; }
|
|
24
31
|
|
|
32
|
+
// ---- 共享:经各台的模块读写那台本机的持有方、调用方 ----
|
|
33
|
+
const pendingReplies = new Map();
|
|
34
|
+
let counter = 0;
|
|
35
|
+
// `late`:等不到回应时也不丢这条回复,晚到了就交给它(授予这类不能重发的写操作用)。
|
|
36
|
+
function ask(m, type, input = {}, late) {
|
|
37
|
+
const rid = `n${++counter}`;
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const settle = fn => v => { clearTimeout(timer); pendingReplies.delete(rid); fn(v); };
|
|
40
|
+
const timer = setTimeout(() => {
|
|
41
|
+
if (late) pendingReplies.get(rid).late = late; else pendingReplies.delete(rid);
|
|
42
|
+
reject(new Error('模块没有回应'));
|
|
43
|
+
}, 10_000);
|
|
44
|
+
pendingReplies.set(rid, { machine: m.id, resolve: settle(resolve), reject: settle(reject) });
|
|
45
|
+
Promise.resolve().then(() => coda.postMessage({ type, rid, ...input }, via(m))).catch(error => pendingReplies.get(rid)?.reject(Object.assign(new Error(`发送失败:${error?.message ?? error}`), { refused: true })));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
addEventListener('message', event => {
|
|
49
|
+
const { type, rid, ok, value, error, effects } = event.data ?? {};
|
|
50
|
+
const wait = type === 'reply' ? pendingReplies.get(rid) : null;
|
|
51
|
+
if (!wait || (event.machine?.id && event.machine.id !== wait.machine)) return;
|
|
52
|
+
// refused:确认什么也没写——模块明确回了错误且 effects 为 none,或消息根本没发出去(postMessage 抛错);别的错误、超时都是结果不明。
|
|
53
|
+
const failure = Object.assign(new Error(error), { refused: effects === 'none' });
|
|
54
|
+
if (wait.late) { pendingReplies.delete(rid); wait.late(ok ? { value } : { failure }); } else if (ok) wait.resolve(value); else wait.reject(failure);
|
|
55
|
+
});
|
|
56
|
+
|
|
25
57
|
// ---- 读各台的 Accord ----
|
|
26
58
|
function onChange(m, { type, entry }) {
|
|
27
59
|
if (type === 'DELETED' || !entry) return;
|
|
@@ -48,12 +80,12 @@ const rowAvatar = row => resolveAvatar({ author: row.author, name: row.title });
|
|
|
48
80
|
|
|
49
81
|
// ---- 弹层:宽屏居中模态,窄屏底部抽屉;同一时间只开一个 ----
|
|
50
82
|
let openDialog = null;
|
|
51
|
-
function makeDialog({ title, close: closeLabel, onClose }) {
|
|
83
|
+
function makeDialog({ title, close: closeLabel, onClose, cancel = () => closeDialog() }) {
|
|
52
84
|
const heading = h('h3', {}, title), body = h('div', { class: 'dlg-body' });
|
|
53
85
|
const panel = h('div', { class: 'dialog', role: 'dialog', 'aria-modal': 'true' }, h('div', { class: 'grabber', 'aria-hidden': 'true' }),
|
|
54
|
-
h('div', { class: 'dlg-head' }, heading, h('button', { class: 'btn quiet small', type: 'button', onclick: () =>
|
|
86
|
+
h('div', { class: 'dlg-head' }, heading, h('button', { class: 'btn quiet small', type: 'button', onclick: () => cancel() }, closeLabel)),
|
|
55
87
|
body);
|
|
56
|
-
const scrim = h('div', { class: 'scrim', onclick: e => { if (e.target === scrim)
|
|
88
|
+
const scrim = h('div', { class: 'scrim', onclick: e => { if (e.target === scrim) cancel(); } }, panel);
|
|
57
89
|
scrim.hidden = true;
|
|
58
90
|
return { scrim, heading, body, onClose };
|
|
59
91
|
}
|
|
@@ -71,7 +103,14 @@ function closeDialog() {
|
|
|
71
103
|
dialog.onClose?.();
|
|
72
104
|
coda.scroll?.(true)?.catch(() => {});
|
|
73
105
|
}
|
|
74
|
-
|
|
106
|
+
// Escape 一次收一层:授予选择框,再是行尾菜单,再是弹层。
|
|
107
|
+
addEventListener('keydown', e => {
|
|
108
|
+
if (e.key !== 'Escape') return;
|
|
109
|
+
if (picker.ctx) closePicker();
|
|
110
|
+
else if (state.menu) { state.menu = null; draw(); }
|
|
111
|
+
else if (openDialog) closeDialog();
|
|
112
|
+
});
|
|
113
|
+
addEventListener('click', () => { if (state.menu) { state.menu = null; draw(); } });
|
|
75
114
|
|
|
76
115
|
// ---- 本机身份:每个身份一张 Hero ----
|
|
77
116
|
// 只有一台电脑时,Hero 上带这台的状态条和「添加好友」;几台时这两样都在各自的节里。
|
|
@@ -128,12 +167,21 @@ const invite = {
|
|
|
128
167
|
authKey: h('input', { type: 'password', autocomplete: 'off', spellcheck: 'false', placeholder: '入网码,提交后立即清空', oninput: dropHidden }),
|
|
129
168
|
linkId: h('input', { type: 'text', autocomplete: 'off', placeholder: '留空自动生成' }),
|
|
130
169
|
scope: h('input', { type: 'text', autocomplete: 'off', placeholder: '留空用本机空间' }),
|
|
131
|
-
peerNode: h('input', { type: 'text', autocomplete: 'off', placeholder: '可选' }),
|
|
170
|
+
peerNode: h('input', { type: 'text', autocomplete: 'off', placeholder: '可选', oninput: dropHidden }),
|
|
132
171
|
message: h('p', { class: 'hint' }),
|
|
133
172
|
button: h('button', { class: 'btn', type: 'button', onclick: submitInvite }, '接受邀请'),
|
|
134
173
|
hidden: {},
|
|
135
174
|
};
|
|
136
|
-
|
|
175
|
+
// 各字段只在识别出一份邀请之后展开给用户核对:口令只随粘贴的邀请来,空表单手填交不出去。
|
|
176
|
+
const ASK_PASTE = '请粘贴对方给你的完整邀请';
|
|
177
|
+
invite.fields = h('div', { class: 'fields' },
|
|
178
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'control(入网地址)'), invite.control),
|
|
179
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'authKey(入网码)'), invite.authKey),
|
|
180
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'linkId'), invite.linkId),
|
|
181
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'scope'), invite.scope),
|
|
182
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'peerNode'), invite.peerNode));
|
|
183
|
+
invite.fields.hidden = true;
|
|
184
|
+
invite.dialog = makeDialog({ title: '添加好友', close: '关闭', onClose: resetGenerated });
|
|
137
185
|
// 接受邀请和随后的互认都发给打开它的那一节的电脑。
|
|
138
186
|
function openInvite(m) {
|
|
139
187
|
if (invite.target !== m) say(invite.message, '');
|
|
@@ -141,44 +189,102 @@ function openInvite(m) {
|
|
|
141
189
|
invite.dialog.heading.textContent = multi ? `添加好友 · ${m.name}` : '添加好友';
|
|
142
190
|
showDialog(invite.dialog);
|
|
143
191
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
192
|
+
// 上半「邀请对方」:说明、主按钮、结果区各有固定的位置,状态变化只换内容;下半「接受对方的邀请」不受它影响。
|
|
193
|
+
// 生成的邀请是凭据:只放在 generated.text 里显示这一次,不进 setState、存储或日志,关掉弹层就清掉。
|
|
194
|
+
const generated = { state: 'idle', text: '', error: '', copied: false, copyError: '', token: 0, timer: 0 };
|
|
195
|
+
const generate = {
|
|
196
|
+
button: h('button', { class: 'btn', type: 'button', onclick: generateInvite }, '生成邀请'),
|
|
197
|
+
result: h('div', { class: 'result', role: 'status', 'aria-live': 'polite' }),
|
|
198
|
+
};
|
|
199
|
+
const canInvite = () => typeof coda.inviteFriend === 'function';
|
|
200
|
+
function drawGenerated() {
|
|
201
|
+
const s = canInvite() ? generated.state : 'na';
|
|
202
|
+
generate.button.disabled = s === 'busy' || s === 'na';
|
|
203
|
+
generate.button.textContent = s === 'done' ? '再生成一个' : s === 'fail' ? '重试' : '生成邀请';
|
|
204
|
+
if (s === 'done') {
|
|
205
|
+
const copy = h('button', { class: 'btn quiet small', type: 'button', onclick: copyInvite }, generated.copied ? '已复制' : '复制');
|
|
206
|
+
return fill(generate.result, h('pre', { class: 'res-box code', 'aria-label': '好友邀请' }, generated.text),
|
|
207
|
+
h('div', { class: 'copyrow' }, copy, generated.copyError ? h('span', { class: 'error' }, generated.copyError) : h('span', { class: 'secondary' }, '24 小时内有效,只能用一次')));
|
|
208
|
+
}
|
|
209
|
+
const text = { busy: '正在生成…', fail: generated.error, na: '请在 Coda 客户端里打开好友页来生成邀请' }[s];
|
|
210
|
+
fill(generate.result, h('div', { class: s === 'fail' ? 'res-box err' : 'res-box' }, text));
|
|
211
|
+
}
|
|
212
|
+
async function generateInvite() {
|
|
213
|
+
if (generated.state === 'busy' || !canInvite()) return;
|
|
214
|
+
const mine = ++generated.token, target = invite.target;
|
|
215
|
+
Object.assign(generated, { state: 'busy', text: '', error: '', copied: false, copyError: '' });
|
|
216
|
+
drawGenerated();
|
|
217
|
+
let outcome;
|
|
218
|
+
try { outcome = { state: 'done', text: (await coda.inviteFriend({ machine: target.id })).text }; }
|
|
219
|
+
// 在确认框里取消:回到空闲,不显示错误。
|
|
220
|
+
catch (e) { outcome = e?.code === 'canceled' ? { state: 'idle' } : { state: 'fail', error: e?.message ?? String(e) }; }
|
|
221
|
+
if (mine !== generated.token) return;
|
|
222
|
+
Object.assign(generated, outcome);
|
|
223
|
+
drawGenerated();
|
|
224
|
+
}
|
|
225
|
+
async function copyInvite() {
|
|
226
|
+
clearTimeout(generated.timer);
|
|
227
|
+
try { await coda.copy(generated.text); Object.assign(generated, { copied: true, copyError: '' }); }
|
|
228
|
+
catch (e) { Object.assign(generated, { copied: false, copyError: `复制失败:${e.message}` }); }
|
|
229
|
+
drawGenerated();
|
|
230
|
+
generated.timer = setTimeout(() => { generated.copied = false; drawGenerated(); }, 1500);
|
|
231
|
+
}
|
|
232
|
+
function resetGenerated() {
|
|
233
|
+
clearTimeout(generated.timer);
|
|
234
|
+
Object.assign(generated, { state: 'idle', text: '', error: '', copied: false, copyError: '', token: generated.token + 1 });
|
|
235
|
+
drawGenerated();
|
|
236
|
+
}
|
|
237
|
+
drawGenerated();
|
|
238
|
+
invite.dialog.body.append(
|
|
239
|
+
h('section', { class: 'blk' }, h('h4', { class: 'sec' }, '邀请对方'),
|
|
240
|
+
h('p', { class: 'hint' }, '生成一段邀请发给对方,对方在他的好友页粘贴'),
|
|
241
|
+
h('div', { class: 'line' }, generate.button), generate.result),
|
|
242
|
+
h('section', { class: 'blk' }, h('h4', { class: 'sec' }, '接受对方的邀请'), h('div', { class: 'stack' },
|
|
243
|
+
h('p', { class: 'hint' }, ASK_PASTE), invite.paste, invite.fields,
|
|
244
|
+
h('div', { class: 'line' }, invite.button), invite.message)));
|
|
245
|
+
// hostname、peerPort、bindingToken(一次性口令)只随识别出的那份邀请,不进输入框:手改入网地址或入网码就是另一份邀请了,
|
|
246
|
+
// 连粘贴区的原文一起丢掉,免得再从原文里解析出旧邀请;口令只交给邀请指定的那台,改 peerNode 同理;改 linkId、scope 不算。
|
|
247
|
+
function dropHidden() { invite.hidden = {}; invite.paste.value = ''; }
|
|
248
|
+
// 粘贴区没有识别出邀请(清空了或识别不了):上次识别出的字段不再属于它,清掉并收起。
|
|
249
|
+
function closeFields() {
|
|
250
|
+
for (const name of ['control', 'authKey', 'linkId', 'scope', 'peerNode']) invite[name].value = '';
|
|
251
|
+
invite.fields.hidden = true;
|
|
252
|
+
}
|
|
156
253
|
function parsePaste() {
|
|
157
254
|
invite.hidden = {};
|
|
158
255
|
const text = invite.paste.value;
|
|
159
|
-
if (!text.trim()) return say(invite.message, '', 'hint');
|
|
256
|
+
if (!text.trim()) { closeFields(); return say(invite.message, '', 'hint'); }
|
|
160
257
|
try {
|
|
161
258
|
const found = parseInvite(text);
|
|
162
259
|
for (const name of ['control', 'authKey', 'scope', 'peerNode']) if (found[name]) invite[name].value = found[name];
|
|
163
260
|
if (found.linkId && !/^f-[0-9a-f]{8}$/.test(found.linkId)) invite.linkId.value = found.linkId;
|
|
164
|
-
invite.hidden = { hostname: found.hostname ?? '', peerPort: found.peerPort };
|
|
261
|
+
invite.hidden = { hostname: found.hostname ?? '', peerPort: found.peerPort, bindingToken: found.bindingToken };
|
|
262
|
+
invite.fields.hidden = false;
|
|
165
263
|
say(invite.message, '已识别邀请,核对后点「接受邀请」', 'ok');
|
|
166
|
-
} catch (e) {
|
|
264
|
+
} catch (e) {
|
|
265
|
+
// 提交时报的是这份的解析错误。
|
|
266
|
+
closeFields();
|
|
267
|
+
say(invite.message, e.message, 'error');
|
|
268
|
+
}
|
|
167
269
|
}
|
|
168
270
|
function clearInvite() {
|
|
169
|
-
|
|
271
|
+
invite.paste.value = '';
|
|
272
|
+
closeFields();
|
|
170
273
|
invite.hidden = {};
|
|
171
274
|
}
|
|
172
275
|
async function submitInvite() {
|
|
173
276
|
let input;
|
|
174
277
|
try {
|
|
175
278
|
input = checked({ control: invite.control.value, authKey: invite.authKey.value, linkId: invite.linkId.value, scope: invite.scope.value,
|
|
176
|
-
peerNode: invite.peerNode.value, hostname: invite.hidden.hostname, peerPort: invite.hidden.peerPort });
|
|
279
|
+
peerNode: invite.peerNode.value, hostname: invite.hidden.hostname, peerPort: invite.hidden.peerPort, bindingToken: invite.hidden.bindingToken });
|
|
177
280
|
} catch (e) {
|
|
178
|
-
//
|
|
179
|
-
|
|
281
|
+
// 什么也没粘贴、字段也没展开:请对方的完整邀请。当前粘贴识别成功了(口令只在这时记着)、或没有粘贴,就以字段为准,校验不过只报错;
|
|
282
|
+
// 粘贴了却还没识别成功,才按粘贴原文再解析一次,成不了就报它的错。
|
|
283
|
+
if (invite.fields.hidden && !invite.paste.value.trim()) return say(invite.message, ASK_PASTE, 'error');
|
|
284
|
+
if (invite.hidden.bindingToken || !invite.paste.value.trim()) return say(invite.message, e.message, 'error');
|
|
285
|
+
try { input = parseInvite(invite.paste.value); } catch (pasted) { return say(invite.message, pasted.message, 'error'); }
|
|
180
286
|
}
|
|
181
|
-
//
|
|
287
|
+
// 入网码和一次性口令是凭据:取出后立刻清空所有输入框和记着的口令,不写进任何存储或日志。
|
|
182
288
|
clearInvite();
|
|
183
289
|
const target = invite.target, opts = via(target), show = (text, kind) => { if (invite.target === target) say(invite.message, text, kind); };
|
|
184
290
|
invite.button.disabled = true;
|
|
@@ -186,13 +292,15 @@ async function submitInvite() {
|
|
|
186
292
|
const peerNode = input.peerNode;
|
|
187
293
|
let node;
|
|
188
294
|
try {
|
|
189
|
-
|
|
295
|
+
// 先发出调用,立刻放掉页面手里的入参(含口令),再等结果。
|
|
296
|
+
const pending = coda.call(LOCAL, 'accept', input, opts);
|
|
297
|
+
input = null;
|
|
298
|
+
({ node } = await pending);
|
|
190
299
|
} catch (e) {
|
|
191
300
|
input = null;
|
|
192
301
|
invite.button.disabled = false;
|
|
193
|
-
return show(`接受邀请失败:${e.message}
|
|
302
|
+
return show(`接受邀请失败:${e.message}。入网码和口令已清空,请重新粘贴邀请再试`, 'error');
|
|
194
303
|
}
|
|
195
|
-
input = null;
|
|
196
304
|
show('已加入通道,正在与对方互认…', 'progress');
|
|
197
305
|
try {
|
|
198
306
|
await coda.call(LOCAL, 'handshake', { node, ...(peerNode ? { peerNode } : {}) }, opts);
|
|
@@ -228,18 +336,21 @@ async function remove(m, row) {
|
|
|
228
336
|
draw();
|
|
229
337
|
}
|
|
230
338
|
const detail = {
|
|
231
|
-
dialog: makeDialog({ title: '好友', close: '完成', onClose: () => { state.detail = null; state.removing = null; } }),
|
|
339
|
+
dialog: makeDialog({ title: '好友', close: '完成', onClose: () => { state.detail = null; state.removing = null; state.menu = null; closePicker(); } }),
|
|
232
340
|
card: h('div'),
|
|
233
341
|
info: h('dl', { class: 'facts' }),
|
|
342
|
+
share: h('section', { class: 'share' }),
|
|
234
343
|
actions: h('div', { class: 'actions split' }),
|
|
235
344
|
notice: h('div'),
|
|
236
345
|
};
|
|
237
|
-
detail.dialog.body.append(h('div', { class: 'stack' }, detail.card, detail.info, detail.actions, detail.notice));
|
|
346
|
+
detail.dialog.body.append(h('div', { class: 'stack' }, detail.card, detail.info, detail.share, detail.actions, detail.notice));
|
|
238
347
|
const detailRow = () => state.detail && sectionRows(state.detail.member).find(row => row.node === state.detail.node);
|
|
239
348
|
function openDetail(m, row) {
|
|
240
|
-
state.detail = { member: m, node: row.node, key: rowKey(m, row.node) }; state.removing = null;
|
|
349
|
+
state.detail = { member: m, node: row.node, key: rowKey(m, row.node) }; state.removing = null; state.menu = null;
|
|
350
|
+
shareOf(m).opsOpen = false;
|
|
241
351
|
drawDetail();
|
|
242
352
|
showDialog(detail.dialog);
|
|
353
|
+
loadShare(m, row);
|
|
243
354
|
}
|
|
244
355
|
function fact(label, ...value) { return [h('dt', {}, label), h('dd', { class: 'selectable' }, ...value)]; }
|
|
245
356
|
async function copyFriendKey(m, row) {
|
|
@@ -268,11 +379,237 @@ function drawDetail() {
|
|
|
268
379
|
h('button', { class: 'btn quiet small', type: 'button', onclick: () => { state.removing = null; draw(); } }, '再想想')]
|
|
269
380
|
: [h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => handshake(m, row) }, '重新互认'), h('span', { class: 'spacer' }),
|
|
270
381
|
h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => { state.removing = key; draw(); } }, '移除好友…')]));
|
|
382
|
+
drawShare(m, row);
|
|
271
383
|
fill(detail.notice,
|
|
272
384
|
row.status === 'conflict' ? h('p', { class: 'warn-box' }, '对方的密钥与之前互认的不一致,可能换了设备或身份。确认是本人后可「重新互认」,否则建议移除。') : null,
|
|
273
385
|
notice ? h('p', { class: notice.kind }, notice.text) : null);
|
|
274
386
|
}
|
|
275
387
|
|
|
388
|
+
// ---- 共享:授给这位好友的远程执行、好友授给本机的、最近的操作 ----
|
|
389
|
+
// 授权按机器存在各台本机的持有方里,所以这一节读的、写的都是详情所在的那一台(节标题写明是哪台)。
|
|
390
|
+
// 本地先行:授予、撤销先改界面,进行中只显示在那一行的状态位置;模块明确拒绝(refused)就回滚、原因写在那一行;
|
|
391
|
+
// 超时、发不出去这类结果不明的,保持本机的选择,后台每隔几秒重读授权恢复。
|
|
392
|
+
const SHARE_STATUS = {
|
|
393
|
+
available: ['可用', 'bound'], target_off: ['目标已关闭', 'pending'], target_missing: ['目标不在了', 'pending'], no_identity: ['读不出本机身份', 'pending'],
|
|
394
|
+
granting: ['授予中', 'busy'], revoking: ['撤销中', 'busy'], machine_changed: ['已停用', 'pending'], grantee_changed: ['已停用', 'pending'],
|
|
395
|
+
};
|
|
396
|
+
const PROXY_STATUS = {
|
|
397
|
+
available: ['可用', 'bound'], off: ['TA 那边没开远程执行', 'pending'], channel: ['和 TA 的通道断了', 'pending'],
|
|
398
|
+
author: ['本机身份变了,请 TA 重新授予', 'pending'], sign: ['本机没有可用的签名证书', 'pending'],
|
|
399
|
+
};
|
|
400
|
+
// 授出的范围不让选,由对方的身份决定:个人身份授给他名下的机器,机器身份只授给那一台;基座还没给 certified 时不写。
|
|
401
|
+
const scopeNote = certified => (certified === true ? '授给这个人名下的机器' : certified === false ? '只授给对方那一台机器' : null);
|
|
402
|
+
const shareOf = m => (m.share ??= { grants: null, problem: null, corrupt: null, clock: 0, writes: 0, touched: 0, reread: false, pending: [], revoking: new Map(), theirs: new Map(), ops: new Map(), targets: null, targetsProblem: null, opsOpen: false, timer: null });
|
|
403
|
+
const certifiedOf = (m, row) => m.friends.find(friend => friend.node === row.node)?.certified;
|
|
404
|
+
const mergeGrant = (sh, made) => { const all = sh.grants ?? []; sh.grants = all.some(g => g.grant === made.grant) ? all.map(g => (g.grant === made.grant ? made : g)) : [...all, made]; };
|
|
405
|
+
// 已撤的不显示;撤销中的(名下的调用还在取消)显示。
|
|
406
|
+
const visibleGrant = g => g.status === 'revoking' || (g.status !== 'revoked' && g.revokedAt === undefined);
|
|
407
|
+
|
|
408
|
+
function loadShare(m, row) {
|
|
409
|
+
readGrants(m);
|
|
410
|
+
if (!row.author) return;
|
|
411
|
+
readTheirs(m, row);
|
|
412
|
+
if (shareOf(m).opsOpen) readOps(m, row);
|
|
413
|
+
}
|
|
414
|
+
// 授权的读与写在同一台机器上按顺序记版本:写开始、结束都记一笔;写之前(或写还没结束时)发出的列表,晚到就丢掉,没有写在途时再读一次,
|
|
415
|
+
// 免得迟到的旧列表盖掉已确认的授予或撤销。
|
|
416
|
+
const beginWrite = sh => { sh.writes++; sh.touched = ++sh.clock; };
|
|
417
|
+
function endWrite(m) {
|
|
418
|
+
const sh = shareOf(m);
|
|
419
|
+
sh.writes--; sh.touched = ++sh.clock;
|
|
420
|
+
if (!sh.writes && sh.reread) readGrants(m);
|
|
421
|
+
}
|
|
422
|
+
// 给回这一遍读到的有效列表;没读到(失败、晚到的旧结果、持有方故障)给回 null。`round`:恢复循环里的这一遍,读完不另排下一轮。
|
|
423
|
+
async function readGrants(m, round = false) {
|
|
424
|
+
const sh = shareOf(m), issued = ++sh.clock, clean = sh.writes === 0;
|
|
425
|
+
sh.reread = false;
|
|
426
|
+
let read, failure;
|
|
427
|
+
try { read = await ask(m, 'grants.list'); } catch (e) { failure = e; }
|
|
428
|
+
// 先看版本,再看成败:写之前发出的列表,晚到的结果与晚到的错误都不算数。
|
|
429
|
+
if (!clean || sh.touched > issued) { sh.reread = true; if (!sh.writes) readGrants(m); return null; }
|
|
430
|
+
if (failure) { sh.problem = `读不到授权:${failure.message}`; draw(); return null; }
|
|
431
|
+
sh.problem = null; sh.corrupt = read.corrupt || null;
|
|
432
|
+
// 持有方的授权数据读不出来时,列表是空的但不是真的空:不拿它改显示,也不用它判断待确认的操作;已打开的授予选择框关掉。
|
|
433
|
+
if (sh.corrupt) {
|
|
434
|
+
if (picker.ctx?.m === m) closePicker();
|
|
435
|
+
} else {
|
|
436
|
+
sh.grants = read.grants;
|
|
437
|
+
// 授予:读到了就是授出了;读不到不算被拒,等这笔操作有确定的结果(回应晚到、或读到)。
|
|
438
|
+
sh.pending = sh.pending.filter(p => (p.state !== 'granting' && !p.expired) || !read.grants.some(g => g.friend === p.friend && g.target.id === p.target.id && g.revokedAt === undefined));
|
|
439
|
+
// 结果不明的授予:列表连续读到上限遍都没有它,就当没授出,这一行回滚、目标重新可选。
|
|
440
|
+
for (const p of sh.pending) {
|
|
441
|
+
if (p.state !== 'granting' || !p.unknown || (p.misses = (p.misses ?? 0) + 1) < GRANT_CONFIRMS) continue;
|
|
442
|
+
Object.assign(p, { state: 'denied', reason: '没有确认授予成功,请重试', unknown: false, expired: true });
|
|
443
|
+
}
|
|
444
|
+
// 结果不明的撤销:读到已撤或在撤销中就是核对完了,留下的是仍可用的,由恢复循环再发一次。
|
|
445
|
+
for (const [grant, one] of sh.revoking) if (one.unknown && !read.grants.some(g => g.grant === grant && visibleGrant(g) && g.status !== 'revoking')) sh.revoking.delete(grant);
|
|
446
|
+
}
|
|
447
|
+
draw();
|
|
448
|
+
if (!round) recover(m);
|
|
449
|
+
return sh.corrupt ? null : read.grants;
|
|
450
|
+
}
|
|
451
|
+
async function readTheirs(m, row) {
|
|
452
|
+
const sh = shareOf(m);
|
|
453
|
+
try { sh.theirs.set(row.author, { rows: await ask(m, 'proxies.list', { friend: row.author }) }); }
|
|
454
|
+
catch (e) { sh.theirs.set(row.author, { problem: `读不到 TA 授给你的:${e.message}` }); }
|
|
455
|
+
draw();
|
|
456
|
+
}
|
|
457
|
+
async function readOps(m, row) {
|
|
458
|
+
const sh = shareOf(m);
|
|
459
|
+
try { sh.ops.set(row.author, { rows: await ask(m, 'ledger.list', { friend: row.author, limit: 20 }) }); }
|
|
460
|
+
catch (e) { sh.ops.set(row.author, { problem: `读不到操作记录:${e.message}` }); }
|
|
461
|
+
draw();
|
|
462
|
+
}
|
|
463
|
+
// 还有要恢复的(结果不明的授予与撤销、读到的撤销中)就隔几秒来一轮,直到状态变化。一轮 = 读一遍列表,读到有效列表、且结果不明的撤销
|
|
464
|
+
// 对应的授权仍可用,才重发;读和重发都结束了才排下一轮(所以同一授权的撤销不会有两个在途重试)。
|
|
465
|
+
function recover(m) {
|
|
466
|
+
const sh = shareOf(m);
|
|
467
|
+
const need = sh.pending.some(p => p.unknown) || [...sh.revoking.values()].some(r => r.unknown) || (sh.grants ?? []).some(g => g.status === 'revoking');
|
|
468
|
+
if (!need || sh.timer) return;
|
|
469
|
+
sh.timer = setTimeout(async () => {
|
|
470
|
+
if (await readGrants(m, true)) {
|
|
471
|
+
for (const [grant, one] of sh.revoking) {
|
|
472
|
+
if (!one.unknown) continue;
|
|
473
|
+
// 授权仍可用的有效列表已连续读到上限遍:不再自动重发,写明没确认,这一行回到可手动再撤。
|
|
474
|
+
if ((one.reads = (one.reads ?? 0) + 1) >= REVOKE_RETRIES) sh.revoking.set(grant, { error: '撤销没有确认,可再撤一次' });
|
|
475
|
+
else await sendRevoke(m, grant);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
sh.timer = null;
|
|
479
|
+
draw();
|
|
480
|
+
recover(m);
|
|
481
|
+
}, RECOVER_MS);
|
|
482
|
+
sh.timer?.unref?.();
|
|
483
|
+
}
|
|
484
|
+
async function sendRevoke(m, grant) {
|
|
485
|
+
const sh = shareOf(m), reads = sh.revoking.get(grant)?.reads;
|
|
486
|
+
beginWrite(sh);
|
|
487
|
+
try { mergeGrant(sh, await ask(m, 'grants.revoke', { grant })); sh.revoking.delete(grant); }
|
|
488
|
+
catch (e) { sh.revoking.set(grant, e.refused ? { error: e.message } : { unknown: true, reads }); }
|
|
489
|
+
endWrite(m);
|
|
490
|
+
}
|
|
491
|
+
async function revokeGrant(m, g) {
|
|
492
|
+
const sh = shareOf(m);
|
|
493
|
+
state.menu = null;
|
|
494
|
+
sh.revoking.set(g.grant, {});
|
|
495
|
+
draw();
|
|
496
|
+
await sendRevoke(m, g.grant);
|
|
497
|
+
recover(m);
|
|
498
|
+
draw();
|
|
499
|
+
}
|
|
500
|
+
// 同一好友、同一目标的本地操作只留一条:重试替掉原来的失败,确认成功就清掉。结果不明的(回应超时)不重发,
|
|
501
|
+
// 它的回应晚到了照样接住;读到了、或回应晚到之前这一行一直是「授予中」,目标一直占着。
|
|
502
|
+
async function grantTo(m, row, target) {
|
|
503
|
+
const sh = shareOf(m);
|
|
504
|
+
if (sh.corrupt) return;
|
|
505
|
+
const one = { friend: row.author, target: { id: target.id, name: target.name }, state: 'granting' };
|
|
506
|
+
sh.pending = [...sh.pending.filter(p => !(p.friend === one.friend && p.target.id === target.id)), one];
|
|
507
|
+
closePicker();
|
|
508
|
+
draw();
|
|
509
|
+
const settle = (outcome, failure) => {
|
|
510
|
+
if (!sh.pending.includes(one)) return;
|
|
511
|
+
if (outcome) { mergeGrant(sh, outcome); sh.pending = sh.pending.filter(p => p !== one); } else if (failure.refused) Object.assign(one, { state: 'denied', reason: failure.message, unknown: false });
|
|
512
|
+
else one.unknown = true;
|
|
513
|
+
};
|
|
514
|
+
beginWrite(sh);
|
|
515
|
+
try { settle(await ask(m, 'grants.grant', { friend: row.author, target: { kind: MACHINE_KIND, id: target.id } }, late => {
|
|
516
|
+
beginWrite(sh); settle(late.value, late.failure); endWrite(m); draw();
|
|
517
|
+
})); } catch (e) { settle(null, e); recover(m); }
|
|
518
|
+
endWrite(m);
|
|
519
|
+
draw();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const dots = () => svg('svg', { viewBox: '0 0 24 24', width: 18, height: 18, fill: 'currentColor', 'aria-hidden': 'true' },
|
|
523
|
+
svg('circle', { cx: 5, cy: 12, r: 2 }), svg('circle', { cx: 12, cy: 12, r: 2 }), svg('circle', { cx: 19, cy: 12, r: 2 }));
|
|
524
|
+
const emptyRow = text => h('li', { class: 'empty g-empty' }, text);
|
|
525
|
+
// 一行:名称与说明、状态、行尾只有一个菜单按钮(没有菜单的行也留着这个槽,列对得齐)。
|
|
526
|
+
function shareRow({ key, name, sub, subKind, badge, busy, menu }) {
|
|
527
|
+
const open = state.menu === key;
|
|
528
|
+
return h('li', { class: 'g-row', 'aria-busy': busy ? 'true' : null },
|
|
529
|
+
h('div', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, name), sub ? h('span', { class: `g-sub truncate${subKind === 'error' ? ' error' : ''}` }, sub) : null),
|
|
530
|
+
h('span', { class: `badge ${badge[1]}` }, badge[0]),
|
|
531
|
+
menu ? h('button', { class: 'kebab', type: 'button', 'aria-label': `更多操作:${name}`, 'aria-haspopup': 'menu', 'aria-expanded': String(open), disabled: busy,
|
|
532
|
+
onclick: e => { e.stopPropagation?.(); state.menu = open ? null : key; draw(); } }, dots()) : h('span', { class: 'kebab-slot', 'aria-hidden': 'true' }),
|
|
533
|
+
open && menu ? h('div', { class: 'menu', role: 'menu' }, h('button', { type: 'button', role: 'menuitem', class: menu.danger ? 'danger' : '',
|
|
534
|
+
onclick: e => { e.stopPropagation?.(); menu.run(); } }, menu.label, menu.note ? h('span', { class: 'menu-note' }, menu.note) : null)) : null);
|
|
535
|
+
}
|
|
536
|
+
function drawShare(m, row) {
|
|
537
|
+
const sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
|
|
538
|
+
const mine = [
|
|
539
|
+
...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => {
|
|
540
|
+
const local = sh.revoking.get(g.grant), busy = g.status === 'revoking' || (local && !local.error);
|
|
541
|
+
return shareRow({ key: `g:${g.grant}`, name: g.target.name ?? g.target.id, sub: local?.error ?? scope, subKind: local?.error ? 'error' : null,
|
|
542
|
+
badge: busy ? SHARE_STATUS.revoking : SHARE_STATUS[g.status] ?? ['已失效', 'pending'], busy,
|
|
543
|
+
menu: { label: '撤销', note: '同时取消对方正在跑的调用', danger: true, run: () => revokeGrant(m, g) } });
|
|
544
|
+
}),
|
|
545
|
+
...sh.pending.filter(p => p.friend === row.author).map(p => shareRow({ key: `p:${p.target.id}`, name: p.target.name, sub: p.state === 'denied' ? p.reason : scope, subKind: p.state === 'denied' ? 'error' : null,
|
|
546
|
+
badge: p.state === 'denied' ? ['未授予', 'conflict'] : SHARE_STATUS.granting, busy: p.state === 'granting',
|
|
547
|
+
menu: { label: '移除', run: () => { sh.pending = sh.pending.filter(one => one !== p); state.menu = null; draw(); } } })),
|
|
548
|
+
];
|
|
549
|
+
const their = sh.theirs.get(row.author);
|
|
550
|
+
const theirRows = (their?.rows ?? []).map(proxy => shareRow({ key: `t:${proxy.key}`, name: proxy.name, badge: PROXY_STATUS[proxy.status] ?? ['不可用', 'pending'] }));
|
|
551
|
+
const ops = sh.ops.get(row.author);
|
|
552
|
+
const canGrant = row.status === 'bound' && Boolean(row.author) && sh.grants !== null && !sh.corrupt;
|
|
553
|
+
fill(detail.share,
|
|
554
|
+
h('h4', {}, `共享 · ${m.name}`),
|
|
555
|
+
h('div', {}, h('div', { class: 'sub-head' }, '我授给 TA', h('span', { class: 'spacer' }),
|
|
556
|
+
h('button', { class: 'btn quiet small', type: 'button', disabled: !canGrant, 'aria-label': '授予远程执行', onclick: () => openPicker(m, row) }, '授予…')),
|
|
557
|
+
h('ul', { class: 'glist' }, sh.problem ? h('li', { class: 'error g-empty' }, sh.problem) : sh.corrupt ? h('li', { class: 'error g-empty' }, `持有方出了故障:授权数据读不出来${typeof sh.corrupt === 'string' ? `(${sh.corrupt})` : ''},暂时不能授予和撤销`) : sh.grants === null ? emptyRow('正在读取…') : mine.length ? mine : emptyRow('还没有授给 TA 的东西'))),
|
|
558
|
+
h('div', {}, h('div', { class: 'sub-head' }, 'TA 授给我'),
|
|
559
|
+
h('ul', { class: 'glist' }, their?.problem ? h('li', { class: 'error g-empty' }, their.problem) : !their ? emptyRow(row.author ? '正在读取…' : 'TA 还没有授给你东西')
|
|
560
|
+
: theirRows.length ? theirRows : emptyRow('TA 还没有授给你东西'))),
|
|
561
|
+
h('details', { class: 'ops', open: sh.opsOpen, ontoggle: e => {
|
|
562
|
+
if (e.target.open === sh.opsOpen) return;
|
|
563
|
+
sh.opsOpen = e.target.open;
|
|
564
|
+
if (sh.opsOpen && row.author) readOps(m, row);
|
|
565
|
+
} }, h('summary', {}, '最近的操作'),
|
|
566
|
+
h('div', { class: 'ops-list' }, ops?.problem ? h('p', { class: 'error' }, ops.problem) : !ops ? h('p', { class: 'empty' }, row.author ? '正在读取…' : '还没有操作记录')
|
|
567
|
+
: ops.rows.length ? [...ops.rows.map(opRow), h('p', { class: 'hint' }, '完整记录:coda self ledger.list')] : h('p', { class: 'empty' }, '还没有操作记录'))));
|
|
568
|
+
}
|
|
569
|
+
// 操作记录的摘要:时间、操作、命令摘要、结局、耗时。
|
|
570
|
+
const duration = ms => (ms < 10_000 ? `${(ms / 1000).toFixed(1)} 秒` : ms < 60_000 ? `${Math.round(ms / 1000)} 秒` : `${Math.round(ms / 60_000)} 分钟`);
|
|
571
|
+
function outcomeOf(row) {
|
|
572
|
+
if (row.outcome === 'rejected') return ['被拒绝', 'conflict'];
|
|
573
|
+
if (row.outcome === 'canceled') return ['已取消', 'pending'];
|
|
574
|
+
if (row.outcome === 'failed') return [`失败(${row.code ?? '未知'})`, 'conflict'];
|
|
575
|
+
if (row.exitCode === undefined || row.exitCode === 0) return ['成功', 'bound'];
|
|
576
|
+
return [row.exitCode === null ? '失败' : `失败(退出码 ${row.exitCode})`, 'conflict'];
|
|
577
|
+
}
|
|
578
|
+
function opRow(row) {
|
|
579
|
+
const [label, kind] = outcomeOf(row), rejected = row.outcome === 'rejected';
|
|
580
|
+
return h('div', { class: 'op' },
|
|
581
|
+
h('div', { class: 'op-top' }, h('span', { class: 'op-time' }, formatTime(row.at)), h('span', { class: 'tag' }, rejected ? '请求' : '执行'), h('span', { class: 'spacer' }),
|
|
582
|
+
h('span', { class: `badge ${kind}` }, label), h('span', { class: 'dur' }, rejected ? '—' : duration(row.ms))),
|
|
583
|
+
h('div', { class: 'op-cmd truncate selectable' }, rejected ? `${row.code}${row.count > 1 ? ` × ${row.count}` : ''}` : row.command.summary));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// 授予选择框:叠在好友详情上,只选要授出的记录,不选范围;每行下面的小字是对方身份决定的范围。
|
|
587
|
+
const picker = { dialog: makeDialog({ title: '授予远程执行', close: '取消', cancel: () => closePicker() }), ctx: null, list: h('ul', { class: 'glist' }) };
|
|
588
|
+
picker.dialog.body.append(picker.list);
|
|
589
|
+
function openPicker(m, row) {
|
|
590
|
+
picker.ctx = { m, row };
|
|
591
|
+
picker.dialog.scrim.hidden = false;
|
|
592
|
+
drawPicker();
|
|
593
|
+
const sh = shareOf(m);
|
|
594
|
+
ask(m, 'grants.targets').then(targets => { sh.targets = targets; sh.targetsProblem = null; }, e => { sh.targetsProblem = `读不到本机的远程执行记录:${e.message}`; }).then(drawPicker);
|
|
595
|
+
}
|
|
596
|
+
function closePicker() {
|
|
597
|
+
picker.ctx = null;
|
|
598
|
+
picker.dialog.scrim.hidden = true;
|
|
599
|
+
}
|
|
600
|
+
function drawPicker() {
|
|
601
|
+
if (!picker.ctx) return;
|
|
602
|
+
const { m, row } = picker.ctx, sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
|
|
603
|
+
const taken = new Set([...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => g.target.id), ...sh.pending.filter(p => p.friend === row.author && p.state !== 'denied').map(p => p.target.id)]);
|
|
604
|
+
fill(picker.list, sh.targetsProblem ? h('li', { class: 'error g-empty' }, sh.targetsProblem) : sh.targets === null ? emptyRow('正在读取…')
|
|
605
|
+
: sh.targets.length ? sh.targets.map(target => {
|
|
606
|
+
const why = sh.corrupt ? '持有方出了故障' : !target.available ? '远程执行没打开' : taken.has(target.id) ? '已授给 TA' : '';
|
|
607
|
+
return h('li', {}, h('button', { class: 'pick', type: 'button', disabled: Boolean(why), onclick: () => { if (!why) grantTo(m, row, target); } },
|
|
608
|
+
h('span', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, target.name), h('span', { class: 'g-sub truncate' }, `${target.os} · ${target.user}`), scope ? h('span', { class: 'g-sub truncate' }, scope) : null),
|
|
609
|
+
why ? h('span', { class: 'why' }, why) : null));
|
|
610
|
+
}) : emptyRow('本机没有可授出的远程执行记录'));
|
|
611
|
+
}
|
|
612
|
+
|
|
276
613
|
function friendTile(m, row) {
|
|
277
614
|
return h('li', {}, h('button', { class: 'f-tile', type: 'button', 'aria-label': `${row.title},${STATUS_TEXT[row.status]}`, onclick: () => openDetail(m, row) },
|
|
278
615
|
avatar(rowAvatar(row), 'sm'),
|
|
@@ -302,9 +639,11 @@ function draw() {
|
|
|
302
639
|
if (!ids.length) ids.push({ author: null, signer: null, members: [] });
|
|
303
640
|
fill(page, ids.map(id => drawHero(id, sections)), sections.map(drawSection));
|
|
304
641
|
if (state.detail) { if (detailRow()) drawDetail(); else closeDialog(); }
|
|
642
|
+
drawPicker();
|
|
305
643
|
}
|
|
306
644
|
|
|
307
|
-
|
|
645
|
+
picker.dialog.scrim.hidden = true;
|
|
646
|
+
root.replaceChildren(page, detail.dialog.scrim, invite.dialog.scrim, picker.dialog.scrim);
|
|
308
647
|
draw();
|
|
309
648
|
|
|
310
649
|
coda.header({ text: '好友' }).catch(() => {});
|
package/view/style.css
CHANGED
|
@@ -145,6 +145,49 @@ details[open] > summary { margin-bottom: 10px; }
|
|
|
145
145
|
.key-full { overflow-wrap: anywhere; word-break: break-all; }
|
|
146
146
|
.warn-box { margin: 0 0 8px; padding: 9px 11px; border-radius: 11px; background: color-mix(in srgb, var(--red) 11%, transparent); color: var(--red); font-size: .92em; }
|
|
147
147
|
|
|
148
|
+
/* 添加好友:「邀请对方」与「接受对方的邀请」各一块,结果区高度固定,状态变化只换里面的内容 */
|
|
149
|
+
.blk { display: flex; flex-direction: column; gap: 10px; }
|
|
150
|
+
.blk + .blk { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
|
|
151
|
+
.blk .sec { margin: 0; }
|
|
152
|
+
.result { height: 208px; display: flex; flex-direction: column; gap: 8px; }
|
|
153
|
+
.res-box { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; color: var(--fg2); font-size: .92em; overflow: auto; }
|
|
154
|
+
.res-box.code { display: block; text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--fg); margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: .86em; line-height: 1.5; -webkit-user-select: text; user-select: text; }
|
|
155
|
+
.res-box.err { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
|
|
156
|
+
.copyrow { flex: none; display: flex; align-items: center; gap: 10px; min-height: 28px; }
|
|
157
|
+
|
|
158
|
+
/* 好友详情里的「共享」 */
|
|
159
|
+
.share { padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; }
|
|
160
|
+
.share > h4 { margin: 0; font-size: 1.12em; font-weight: 700; }
|
|
161
|
+
.sub-head { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-weight: 650; color: var(--fg2); }
|
|
162
|
+
.glist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
163
|
+
.g-row { position: relative; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 8px 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
|
|
164
|
+
.g-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
|
|
165
|
+
.g-name { font-weight: 650; }
|
|
166
|
+
.g-sub { font-size: .85em; color: var(--fg3); }
|
|
167
|
+
.g-sub.error { color: var(--red); }
|
|
168
|
+
.badge.busy { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
|
|
169
|
+
.badge.busy::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: currentColor; animation: pulse 1s ease-in-out infinite; }
|
|
170
|
+
@keyframes pulse { 50% { opacity: .25; } }
|
|
171
|
+
.kebab, .kebab-slot { flex: none; width: 32px; height: 32px; }
|
|
172
|
+
.kebab { display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--fg2); }
|
|
173
|
+
.kebab:not(:disabled):hover { background: var(--fill); }
|
|
174
|
+
.kebab svg { pointer-events: none; }
|
|
175
|
+
.g-empty { min-height: 56px; display: flex; align-items: center; justify-content: center; padding: 0 16px; }
|
|
176
|
+
.menu { position: absolute; top: 44px; right: 8px; z-index: 5; min-width: 150px; padding: 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
|
|
177
|
+
.menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; padding: 8px 12px; border: 0; border-radius: 8px; background: none; text-align: left; font-weight: 600; }
|
|
178
|
+
.menu button.danger { color: var(--red); }
|
|
179
|
+
.menu button:hover { background: var(--fill); }
|
|
180
|
+
.menu button.danger:hover { background: color-mix(in srgb, var(--red) 10%, transparent); }
|
|
181
|
+
.menu-note { font-size: .85em; font-weight: 400; color: var(--fg2); }
|
|
182
|
+
.ops-list { display: flex; flex-direction: column; gap: 6px; }
|
|
183
|
+
.op { padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 3px; }
|
|
184
|
+
.op-top { display: flex; align-items: center; gap: 8px; font-size: .88em; }
|
|
185
|
+
.op-time { color: var(--fg3); }
|
|
186
|
+
.op-cmd { font-family: var(--mono); font-size: .86em; }
|
|
187
|
+
.dur { color: var(--fg2); font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; }
|
|
188
|
+
.pick { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; }
|
|
189
|
+
.pick .why { font-size: .85em; color: var(--orange); }
|
|
190
|
+
|
|
148
191
|
@media (min-width: 680px) {
|
|
149
192
|
.page { padding: 18px 24px 28px; gap: 20px; }
|
|
150
193
|
.hero-body { padding: 14px 20px 18px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); align-items: end; column-gap: 18px; }
|