dsh-ssh-file 0.0.0-stage → 1.2.2
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/LICENSE +21 -0
- package/README.md +73 -2
- package/cordis.patch.yml +4 -0
- package/icon.svg +7 -0
- package/lib/client.js +1364 -0
- package/lib/descriptors.js +63 -0
- package/lib/index.js +1235 -0
- package/lib/remote.js +9 -0
- package/lib/schemas.js +130 -0
- package/lib/typert.js +81 -0
- package/locale/en.json +4 -0
- package/locale/zh.json +4 -0
- package/package.json +77 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,1364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-ssh-file — client half (plain JS, served unbundled).
|
|
3
|
+
*
|
|
4
|
+
* Surfaces:
|
|
5
|
+
* - sidebar.workspaces.directoryFlow (侧栏「+」添加工作区)
|
|
6
|
+
* - conversation.hero.workspace.directoryFlow (对话框上方工作区选择器)
|
|
7
|
+
* - workspace.picker.directoryFlow (同上,工厂变体)
|
|
8
|
+
* - conversation.composer.dock (聊天输入框下方的状态芯片)
|
|
9
|
+
*
|
|
10
|
+
* API: namespace `remoteWorkspace` (own typert face, mounted below).
|
|
11
|
+
* Local folder picking still goes through ctx.remote.directoryPicker.
|
|
12
|
+
*
|
|
13
|
+
* Browser zod: this bundle is NOT pre-bundled, and the client module system
|
|
14
|
+
* has no 'zod' static-table entry (verified: no registered module named zod;
|
|
15
|
+
* the gateway client only checks codec.mode === 'strict', never parses).
|
|
16
|
+
* We therefore ship a minimal zod-v4-compatible shim used only to construct
|
|
17
|
+
* descriptor schemas. If a real 'zod' becomes require-able it is preferred.
|
|
18
|
+
*/
|
|
19
|
+
window.__ModuleLoader__.load({
|
|
20
|
+
id: 'dsh-ssh-file',
|
|
21
|
+
factory(require) {
|
|
22
|
+
const React = require('react');
|
|
23
|
+
const h = React.createElement;
|
|
24
|
+
const { useState, useEffect, useCallback, useRef } = React;
|
|
25
|
+
let portal = null;
|
|
26
|
+
try { portal = require('react-dom').createPortal; } catch { portal = null; }
|
|
27
|
+
|
|
28
|
+
// ── zod: prefer real, fall back to a minimal v4-compatible shim ────────
|
|
29
|
+
|
|
30
|
+
let z = null;
|
|
31
|
+
let zodSource = 'shim';
|
|
32
|
+
try { z = require('zod'); zodSource = 'require(zod)'; } catch { /* shim below */ }
|
|
33
|
+
if (!z || typeof z.object !== 'function') {
|
|
34
|
+
zodSource = 'shim';
|
|
35
|
+
const Base = class {
|
|
36
|
+
optional() { return new ShimOptional(this); }
|
|
37
|
+
nullable() { return new ShimUnion([this, new ShimLiteral(null)]); }
|
|
38
|
+
safeParse(value) { return shimCheck(this, value); }
|
|
39
|
+
parse(value) {
|
|
40
|
+
const r = this.safeParse(value);
|
|
41
|
+
if (!r.success) throw new Error('schema validation failed');
|
|
42
|
+
return { ...r, data: r.data };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const ShimString = class extends Base {
|
|
46
|
+
constructor() { super(); this.kind = 'string'; }
|
|
47
|
+
uuid() { return this; }
|
|
48
|
+
};
|
|
49
|
+
const ShimNumber = class extends Base { constructor() { super(); this.kind = 'number'; } };
|
|
50
|
+
const ShimBoolean = class extends Base { constructor() { super(); this.kind = 'boolean'; } };
|
|
51
|
+
const ShimLiteral = class extends Base {
|
|
52
|
+
constructor(value) { super(); this.kind = 'literal'; this.value = value; }
|
|
53
|
+
};
|
|
54
|
+
const ShimObject = class extends Base {
|
|
55
|
+
constructor(shape) { super(); this.kind = 'object'; this.shape = shape; }
|
|
56
|
+
};
|
|
57
|
+
const ShimArray = class extends Base {
|
|
58
|
+
constructor(item) { super(); this.kind = 'array'; this.item = item; }
|
|
59
|
+
};
|
|
60
|
+
const ShimUnion = class extends Base {
|
|
61
|
+
constructor(options) { super(); this.kind = 'union'; this.options = options; }
|
|
62
|
+
};
|
|
63
|
+
const ShimOptional = class extends Base {
|
|
64
|
+
constructor(inner) { super(); this.kind = 'optional'; this.inner = inner; }
|
|
65
|
+
};
|
|
66
|
+
function shimCheck(schema, value) {
|
|
67
|
+
switch (schema.kind) {
|
|
68
|
+
case 'string':
|
|
69
|
+
return typeof value === 'string'
|
|
70
|
+
? { success: true, data: value }
|
|
71
|
+
: { success: false, error: { issues: [{ message: 'expected string' }] } };
|
|
72
|
+
case 'number':
|
|
73
|
+
return typeof value === 'number'
|
|
74
|
+
? { success: true, data: value }
|
|
75
|
+
: { success: false, error: { issues: [{ message: 'expected number' }] } };
|
|
76
|
+
case 'boolean':
|
|
77
|
+
return typeof value === 'boolean'
|
|
78
|
+
? { success: true, data: value }
|
|
79
|
+
: { success: false, error: { issues: [{ message: 'expected boolean' }] } };
|
|
80
|
+
case 'literal':
|
|
81
|
+
return value === schema.value
|
|
82
|
+
? { success: true, data: value }
|
|
83
|
+
: { success: false, error: { issues: [{ message: 'literal mismatch' }] } };
|
|
84
|
+
case 'optional': {
|
|
85
|
+
if (value === undefined) return { success: true, data: undefined };
|
|
86
|
+
return shimCheck(schema.inner, value);
|
|
87
|
+
}
|
|
88
|
+
case 'array': {
|
|
89
|
+
if (!Array.isArray(value)) return { success: false, error: { issues: [{ message: 'expected array' }] } };
|
|
90
|
+
const data = [];
|
|
91
|
+
for (const item of value) {
|
|
92
|
+
const r = shimCheck(schema.item, item);
|
|
93
|
+
if (!r.success) return { success: false, error: { issues: [{ message: 'array item mismatch' }] } };
|
|
94
|
+
data.push(r.data);
|
|
95
|
+
}
|
|
96
|
+
return { success: true, data };
|
|
97
|
+
}
|
|
98
|
+
case 'union': {
|
|
99
|
+
for (const option of schema.options) {
|
|
100
|
+
const r = shimCheck(option, value);
|
|
101
|
+
if (r.success) return r;
|
|
102
|
+
}
|
|
103
|
+
return { success: false, error: { issues: [{ message: 'union mismatch' }] } };
|
|
104
|
+
}
|
|
105
|
+
case 'object': {
|
|
106
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
107
|
+
return { success: false, error: { issues: [{ message: 'expected object' }] } };
|
|
108
|
+
}
|
|
109
|
+
const data = {};
|
|
110
|
+
for (const [key, inner] of Object.entries(schema.shape)) {
|
|
111
|
+
const r = shimCheck(inner, value[key]);
|
|
112
|
+
if (!r.success) return { success: false, error: { issues: [{ message: `field ${key} mismatch` }] } };
|
|
113
|
+
if (r.data !== undefined) data[key] = r.data;
|
|
114
|
+
}
|
|
115
|
+
return { success: true, data };
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
return { success: true, data: value };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
z = {
|
|
122
|
+
object: (shape) => new ShimObject(shape),
|
|
123
|
+
string: () => new ShimString(),
|
|
124
|
+
number: () => new ShimNumber(),
|
|
125
|
+
boolean: () => new ShimBoolean(),
|
|
126
|
+
literal: (value) => new ShimLiteral(value),
|
|
127
|
+
union: (options) => new ShimUnion(options),
|
|
128
|
+
array: (item) => new ShimArray(item),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ── schemas (mirror lib/schemas.js) ─────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
const resultSchema = (obj) => z.union([
|
|
135
|
+
z.object({ ok: z.literal(true), value: obj }),
|
|
136
|
+
z.object({ ok: z.literal(false), error: z.object({ code: z.string(), message: z.string() }) }),
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
const sftpEntrySchema = z.object({
|
|
140
|
+
name: z.string(), isDirectory: z.boolean(), size: z.number(), mtime: z.number(), mode: z.number(),
|
|
141
|
+
});
|
|
142
|
+
const profileInfoSchema = z.object({
|
|
143
|
+
profileId: z.string(), name: z.string(), host: z.string(), port: z.number(),
|
|
144
|
+
username: z.string(), authKind: z.union([z.literal('password'), z.literal('key')]),
|
|
145
|
+
connected: z.boolean(), defaultProjectPath: z.string().optional(),
|
|
146
|
+
credentialConfigured: z.boolean().optional(),
|
|
147
|
+
});
|
|
148
|
+
const bindingSchema = z.object({
|
|
149
|
+
workspacePath: z.string(), profileId: z.string(), profileName: z.string(),
|
|
150
|
+
host: z.string(), port: z.number(), username: z.string(), remotePath: z.string(),
|
|
151
|
+
autoConnect: z.boolean(), connected: z.boolean(), missingResource: z.boolean().optional(),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const S = {
|
|
155
|
+
profileList: [z.object({}), resultSchema(z.object({ profiles: z.array(profileInfoSchema) }))],
|
|
156
|
+
profileSave: [z.object({
|
|
157
|
+
profileId: z.string().optional(), name: z.string(), host: z.string(), port: z.number().optional(),
|
|
158
|
+
username: z.string(), authKind: z.union([z.literal('password'), z.literal('key')]),
|
|
159
|
+
password: z.string().optional(), privateKey: z.string().optional(), passphrase: z.string().optional(),
|
|
160
|
+
defaultProjectPath: z.string().optional(),
|
|
161
|
+
}), resultSchema(z.object({ profile: profileInfoSchema }))],
|
|
162
|
+
profileDelete: [z.object({ profileId: z.string() }), resultSchema(z.object({ deleted: z.boolean() }))],
|
|
163
|
+
profileConnect: [z.object({ profileId: z.string(), reuseExisting: z.boolean().optional() }),
|
|
164
|
+
resultSchema(z.object({ connectionId: z.string(), host: z.string(), port: z.number(), username: z.string(), name: z.string().optional() }))],
|
|
165
|
+
profileDisconnect: [z.object({ profileId: z.string() }), resultSchema(z.object({ disconnected: z.number() }))],
|
|
166
|
+
sftpList: [z.object({ connectionId: z.string(), path: z.string() }), resultSchema(z.object({ path: z.string(), entries: z.array(sftpEntrySchema) }))],
|
|
167
|
+
sftpMkdir: [z.object({ connectionId: z.string(), path: z.string() }), resultSchema(z.object({ path: z.string() }))],
|
|
168
|
+
bindingList: [z.object({}), resultSchema(z.object({ bindings: z.array(bindingSchema), workspaces: z.array(z.object({ path: z.string(), title: z.string() })) }))],
|
|
169
|
+
bindingSave: [z.object({ workspacePath: z.string(), profileId: z.string(), remotePath: z.string(), autoConnect: z.boolean().optional() }),
|
|
170
|
+
resultSchema(z.object({ binding: bindingSchema }))],
|
|
171
|
+
bindingDelete: [z.object({ workspacePath: z.string() }), resultSchema(z.object({ removed: z.boolean() }))],
|
|
172
|
+
ensureLocalMirrorFolder: [z.object({ name: z.string() }), resultSchema(z.object({ path: z.string() }))],
|
|
173
|
+
fileRead: [z.object({ connectionId: z.string(), path: z.string() }),
|
|
174
|
+
resultSchema(z.object({ path: z.string(), data: z.string(), bytes: z.number(), truncated: z.boolean() }))],
|
|
175
|
+
fileWrite: [z.object({ connectionId: z.string(), path: z.string(), data: z.string() }),
|
|
176
|
+
resultSchema(z.object({ path: z.string(), bytes: z.number() }))],
|
|
177
|
+
sessionBinding: [z.object({ sessionId: z.string() }), resultSchema(z.object({
|
|
178
|
+
bindings: z.array(bindingSchema),
|
|
179
|
+
matchWorkspacePath: z.string().nullable(),
|
|
180
|
+
cwd: z.string().nullable(),
|
|
181
|
+
}))],
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// ── descriptors (mirror lib/descriptors.js) ─────────────────────────────
|
|
185
|
+
|
|
186
|
+
const PACKAGE = 'dsh-ssh-file';
|
|
187
|
+
const NS = 'remoteWorkspace';
|
|
188
|
+
function def(method, requestSchema, requestType, resultSchema2, resultType) {
|
|
189
|
+
return {
|
|
190
|
+
id: `${PACKAGE}#${NS}/${method}`,
|
|
191
|
+
service: NS,
|
|
192
|
+
namespace: NS,
|
|
193
|
+
method,
|
|
194
|
+
invocation: { kind: 'direct' },
|
|
195
|
+
parameters: [{
|
|
196
|
+
name: 'request',
|
|
197
|
+
wire: 'request',
|
|
198
|
+
source: 'json',
|
|
199
|
+
codec: { mode: 'strict', typeSymbol: `${PACKAGE}/types#${requestType}`, schema: requestSchema, create: () => requestSchema },
|
|
200
|
+
}],
|
|
201
|
+
result: {
|
|
202
|
+
mode: 'strict',
|
|
203
|
+
typeSymbol: `${PACKAGE}/types#${resultType}`,
|
|
204
|
+
schema: resultSchema2,
|
|
205
|
+
create: () => resultSchema2,
|
|
206
|
+
},
|
|
207
|
+
sourceLocation: { file: 'src/client.js', line: 1, column: 1 },
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const TYPERT_REMOTE = {
|
|
211
|
+
package: PACKAGE,
|
|
212
|
+
descriptors: [
|
|
213
|
+
def('profileList', S.profileList[0], 'ProfileListRequest', S.profileList[1], 'ProfileListResult'),
|
|
214
|
+
def('profileSave', S.profileSave[0], 'ProfileSaveRequest', S.profileSave[1], 'ProfileSaveResult'),
|
|
215
|
+
def('profileDelete', S.profileDelete[0], 'ProfileDeleteRequest', S.profileDelete[1], 'ProfileDeleteResult'),
|
|
216
|
+
def('profileConnect', S.profileConnect[0], 'ProfileConnectRequest', S.profileConnect[1], 'ProfileConnectResult'),
|
|
217
|
+
def('profileDisconnect', S.profileDisconnect[0], 'ProfileDisconnectRequest', S.profileDisconnect[1], 'ProfileDisconnectResult'),
|
|
218
|
+
def('sftpList', S.sftpList[0], 'SftpListRequest', S.sftpList[1], 'SftpListResult'),
|
|
219
|
+
def('sftpMkdir', S.sftpMkdir[0], 'SftpMkdirRequest', S.sftpMkdir[1], 'SftpMkdirResult'),
|
|
220
|
+
def('bindingList', S.bindingList[0], 'BindingListRequest', S.bindingList[1], 'BindingListResult'),
|
|
221
|
+
def('bindingSave', S.bindingSave[0], 'BindingSaveRequest', S.bindingSave[1], 'BindingSaveResult'),
|
|
222
|
+
def('bindingDelete', S.bindingDelete[0], 'BindingDeleteRequest', S.bindingDelete[1], 'BindingDeleteResult'),
|
|
223
|
+
def('ensureLocalMirrorFolder', S.ensureLocalMirrorFolder[0], 'EnsureLocalMirrorFolderRequest', S.ensureLocalMirrorFolder[1], 'EnsureLocalMirrorFolderResult'),
|
|
224
|
+
def('fileRead', S.fileRead[0], 'FileReadRequest', S.fileRead[1], 'FileReadResult'),
|
|
225
|
+
def('fileWrite', S.fileWrite[0], 'FileWriteRequest', S.fileWrite[1], 'FileWriteResult'),
|
|
226
|
+
def('sessionBinding', S.sessionBinding[0], 'SessionBindingRequest', S.sessionBinding[1], 'SessionBindingResult'),
|
|
227
|
+
],
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// ── RPC over the remoteWorkspace namespace ──────────────────────────────
|
|
231
|
+
|
|
232
|
+
function makeApi(ctx) {
|
|
233
|
+
const ns = () => ctx.remote?.namespaces?.get('remoteWorkspace')?.service;
|
|
234
|
+
const RPC_TIMEOUT_MS = 12000;
|
|
235
|
+
function withTimeout(promise, method) {
|
|
236
|
+
let timer;
|
|
237
|
+
const timeout = new Promise((_, reject) => {
|
|
238
|
+
timer = setTimeout(() => reject(new Error(
|
|
239
|
+
`remoteWorkspace.${method} 超时:Host 端没有在 ${RPC_TIMEOUT_MS / 1000}s 内回应。` +
|
|
240
|
+
'请检查 DSH 主机日志或重启应用。'
|
|
241
|
+
)), RPC_TIMEOUT_MS);
|
|
242
|
+
});
|
|
243
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
244
|
+
}
|
|
245
|
+
async function call(method, args) {
|
|
246
|
+
const fn = ns()?.[method];
|
|
247
|
+
if (typeof fn !== 'function') {
|
|
248
|
+
throw new Error('dsh-ssh-file 插件未加载(remoteWorkspace 命名空间不可用),请刷新页面或重启应用');
|
|
249
|
+
}
|
|
250
|
+
let rpc = await withTimeout(Promise.resolve(fn(args)), method);
|
|
251
|
+
// The wire proxy may deliver {ok, value:<envelope>} — strip the extra wrapper.
|
|
252
|
+
if (rpc && typeof rpc === 'object' && rpc.ok === true
|
|
253
|
+
&& rpc.value && typeof rpc.value === 'object'
|
|
254
|
+
&& ('ok' in rpc.value) && ('value' in rpc.value || 'error' in rpc.value)) {
|
|
255
|
+
rpc = rpc.value;
|
|
256
|
+
}
|
|
257
|
+
if (!rpc || rpc.ok !== true) throw new Error(rpc?.error?.message ?? '远程调用失败');
|
|
258
|
+
return rpc.value;
|
|
259
|
+
}
|
|
260
|
+
const dp = () => ctx.remote?.directoryPicker;
|
|
261
|
+
return {
|
|
262
|
+
profileList: () => call('profileList', {}),
|
|
263
|
+
profileSave: (input) => call('profileSave', input),
|
|
264
|
+
profileDelete: (input) => call('profileDelete', input),
|
|
265
|
+
profileConnect: (input) => call('profileConnect', input),
|
|
266
|
+
profileDisconnect: (input) => call('profileDisconnect', input),
|
|
267
|
+
sftpList: (connectionId, path) => call('sftpList', { connectionId, path }),
|
|
268
|
+
bindingList: () => call('bindingList', {}),
|
|
269
|
+
bindingSave: (input) => call('bindingSave', input),
|
|
270
|
+
ensureLocalMirrorFolder: (name) => call('ensureLocalMirrorFolder', { name }),
|
|
271
|
+
fileRead: (connectionId, path) => call('fileRead', { connectionId, path }),
|
|
272
|
+
fileWrite: (connectionId, path, data) => call('fileWrite', { connectionId, path, data }),
|
|
273
|
+
sessionBinding: (sessionId) => call('sessionBinding', { sessionId }),
|
|
274
|
+
sftpMkdir: (connectionId, path) => call('sftpMkdir', { connectionId, path }),
|
|
275
|
+
renameWorkspace: async (workspaceId, title) => {
|
|
276
|
+
const ws = ctx.remote?.workspace;
|
|
277
|
+
if (!ws || typeof ws.rename !== 'function') return false;
|
|
278
|
+
try { await ws.rename({ workspaceId, title }); return true; } catch { return false; }
|
|
279
|
+
},
|
|
280
|
+
pickLocal: async () => {
|
|
281
|
+
const picker = dp();
|
|
282
|
+
if (!picker || typeof picker.pick !== 'function') throw new Error('本地目录选择器不可用');
|
|
283
|
+
const result = await picker.pick();
|
|
284
|
+
if (!result || result.ok !== true) throw new Error(result?.error?.message ?? '本地目录选择失败');
|
|
285
|
+
return result.value;
|
|
286
|
+
},
|
|
287
|
+
createDirectory: async (parent, name) => {
|
|
288
|
+
const picker = dp();
|
|
289
|
+
if (!picker || typeof picker.createDirectory !== 'function') throw new Error('无法创建本地目录');
|
|
290
|
+
const result = await picker.createDirectory(parent, name);
|
|
291
|
+
if (!result || result.ok !== true) throw new Error(result?.error?.message ?? '创建本地目录失败');
|
|
292
|
+
return result.value;
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ── small helpers ───────────────────────────────────────────────────────
|
|
298
|
+
|
|
299
|
+
function joinPath(base, name) {
|
|
300
|
+
if (base === '/') return `/${name}`;
|
|
301
|
+
return `${base}/${name}`;
|
|
302
|
+
}
|
|
303
|
+
function homeGuess(username) {
|
|
304
|
+
return username === 'root' ? '/root' : `/home/${username || ''}`;
|
|
305
|
+
}
|
|
306
|
+
function baseName(path) {
|
|
307
|
+
const parts = String(path || '').split('/').filter(Boolean);
|
|
308
|
+
return parts[parts.length - 1] || 'remote';
|
|
309
|
+
}
|
|
310
|
+
function safeFolderName(text) {
|
|
311
|
+
const cleaned = String(text || 'remote').replace(/[^\w.\-\u4e00-\u9fa5]+/g, '-').replace(/^-+|-+$/g, '');
|
|
312
|
+
return cleaned || 'remote';
|
|
313
|
+
}
|
|
314
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
315
|
+
function joinLocal(parent, name) {
|
|
316
|
+
const sep = parent.includes('\\') && !parent.includes('/') ? '\\' : '/';
|
|
317
|
+
return parent.endsWith(sep) ? parent + name : parent + sep + name;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ── styles (host theme tokens with fallbacks) ───────────────────────────
|
|
321
|
+
|
|
322
|
+
const css = {
|
|
323
|
+
chip: {
|
|
324
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, height: 28,
|
|
325
|
+
padding: '0 10px', borderRadius: 999, border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))',
|
|
326
|
+
background: 'var(--dsw-alias-bg-module-platform, transparent)', color: 'var(--dsw-alias-label-secondary, #9aa3b0)',
|
|
327
|
+
fontSize: 12, cursor: 'pointer', whiteSpace: 'nowrap', maxWidth: 260, overflow: 'hidden',
|
|
328
|
+
},
|
|
329
|
+
chipLabel: { overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
330
|
+
scrim: {
|
|
331
|
+
position: 'fixed', inset: 0, zIndex: 1000, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
332
|
+
background: 'rgba(0,0,0,.45)', backdropFilter: 'blur(2px)',
|
|
333
|
+
},
|
|
334
|
+
modal: {
|
|
335
|
+
width: 560, maxWidth: 'calc(100vw - 40px)', height: 520, maxHeight: 'calc(100vh - 60px)',
|
|
336
|
+
display: 'flex', flexDirection: 'column', borderRadius: 14, overflow: 'hidden',
|
|
337
|
+
background: 'var(--dsw-alias-bg-layer-1, #16191e)', color: 'var(--dsw-alias-label-primary, #d7dbe2)',
|
|
338
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))',
|
|
339
|
+
boxShadow: '0 12px 40px rgba(0,0,0,.4)', fontFamily: 'inherit',
|
|
340
|
+
},
|
|
341
|
+
modalSmall: { width: 380, height: 'auto', maxHeight: 'calc(100vh - 60px)' },
|
|
342
|
+
modalWide: { width: 640 },
|
|
343
|
+
head: { display: 'flex', alignItems: 'center', gap: 10, padding: '12px 14px', borderBottom: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.15))' },
|
|
344
|
+
headTitle: { fontSize: 14, fontWeight: 600, flex: 1 },
|
|
345
|
+
closeBtn: {
|
|
346
|
+
all: 'unset', cursor: 'pointer', display: 'grid', placeItems: 'center', width: 26, height: 26, borderRadius: 7,
|
|
347
|
+
color: 'var(--dsw-alias-label-secondary, #9aa3b0)',
|
|
348
|
+
},
|
|
349
|
+
body: { flex: 1, minHeight: 0, overflowY: 'auto', padding: 14, display: 'flex', flexDirection: 'column', gap: 8 },
|
|
350
|
+
choiceRow: {
|
|
351
|
+
all: 'unset', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 12, padding: '16px 14px', borderRadius: 12,
|
|
352
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.18))',
|
|
353
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.04))', textAlign: 'left',
|
|
354
|
+
},
|
|
355
|
+
choiceIcon: { fontSize: 22, flex: 'none' },
|
|
356
|
+
choiceTitle: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #d7dbe2)' },
|
|
357
|
+
choiceDesc: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #9aa3b0)', marginTop: 2, lineHeight: 1.5 },
|
|
358
|
+
serverRow: {
|
|
359
|
+
all: 'unset', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px', borderRadius: 10,
|
|
360
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.18))',
|
|
361
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.04))',
|
|
362
|
+
},
|
|
363
|
+
serverName: { fontSize: 13, fontWeight: 600 },
|
|
364
|
+
serverMeta: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #9aa3b0)' },
|
|
365
|
+
badge: {
|
|
366
|
+
fontSize: 10, padding: '1px 8px', borderRadius: 999,
|
|
367
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.25))',
|
|
368
|
+
color: 'var(--dsw-alias-label-secondary, #9aa3b0)', marginLeft: 'auto', flex: 'none',
|
|
369
|
+
},
|
|
370
|
+
badgeOk: { color: '#3fb950', borderColor: 'rgba(63,185,80,.45)' },
|
|
371
|
+
crumbBar: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', fontSize: 12 },
|
|
372
|
+
crumb: {
|
|
373
|
+
all: 'unset', cursor: 'pointer', padding: '2px 6px', borderRadius: 6,
|
|
374
|
+
color: 'var(--dsw-alias-label-secondary, #9aa3b0)', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
375
|
+
},
|
|
376
|
+
crumbHere: { color: 'var(--dsw-alias-label-primary, #d7dbe2)', fontWeight: 600 },
|
|
377
|
+
dirRow: {
|
|
378
|
+
all: 'unset', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 8, width: '100%',
|
|
379
|
+
padding: '7px 10px', borderRadius: 8, fontSize: 13, textAlign: 'left',
|
|
380
|
+
color: 'var(--dsw-alias-label-primary, #d7dbe2)',
|
|
381
|
+
},
|
|
382
|
+
dirName: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
383
|
+
foot: {
|
|
384
|
+
display: 'flex', alignItems: 'center', gap: 8, padding: '10px 14px', flexWrap: 'wrap',
|
|
385
|
+
borderTop: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.15))',
|
|
386
|
+
},
|
|
387
|
+
primaryBtn: {
|
|
388
|
+
all: 'unset', cursor: 'pointer', height: 30, padding: '0 16px', borderRadius: 8, fontSize: 12, fontWeight: 600,
|
|
389
|
+
background: 'var(--dsw-alias-button-primary-fill, #2d6cdf)', color: 'var(--dsw-alias-label-primary-foreground, #fff)',
|
|
390
|
+
},
|
|
391
|
+
ghostBtn: {
|
|
392
|
+
all: 'unset', cursor: 'pointer', height: 30, padding: '0 12px', borderRadius: 8, fontSize: 12,
|
|
393
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.25))',
|
|
394
|
+
color: 'var(--dsw-alias-label-primary, #d7dbe2)',
|
|
395
|
+
},
|
|
396
|
+
dangerBtn: {
|
|
397
|
+
all: 'unset', cursor: 'pointer', height: 30, padding: '0 12px', borderRadius: 8, fontSize: 12,
|
|
398
|
+
border: '1px solid rgba(248,81,73,.5)', color: '#f85149',
|
|
399
|
+
},
|
|
400
|
+
error: { padding: '6px 10px', fontSize: 12, color: '#f85149', background: 'rgba(248,81,73,.08)', borderRadius: 8, overflowWrap: 'anywhere' },
|
|
401
|
+
notice: { padding: '6px 10px', fontSize: 12, color: '#3fb950', background: 'rgba(63,185,80,.10)', borderRadius: 8 },
|
|
402
|
+
info: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #9aa3b0)', lineHeight: 1.6 },
|
|
403
|
+
empty: { fontSize: 12, color: 'var(--dsw-alias-label-secondary, #9aa3b0)', textAlign: 'center', padding: '24px 0' },
|
|
404
|
+
pathInput: {
|
|
405
|
+
flex: 1, minWidth: 0, height: 30, borderRadius: 8, fontSize: 12, padding: '0 10px',
|
|
406
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
407
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))', color: 'inherit',
|
|
408
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))',
|
|
409
|
+
},
|
|
410
|
+
input: {
|
|
411
|
+
width: '100%', height: 30, borderRadius: 8, fontSize: 12, padding: '0 10px', boxSizing: 'border-box',
|
|
412
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))', color: 'inherit',
|
|
413
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))',
|
|
414
|
+
},
|
|
415
|
+
formRow: { display: 'flex', gap: 8, alignItems: 'center' },
|
|
416
|
+
formLabel: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #9aa3b0)', width: 110, flex: 'none' },
|
|
417
|
+
textarea: {
|
|
418
|
+
width: '100%', minHeight: 64, borderRadius: 8, fontSize: 12, padding: '8px 10px', boxSizing: 'border-box',
|
|
419
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', resize: 'vertical',
|
|
420
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))', color: 'inherit',
|
|
421
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))',
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const OVERLAY_TAG = 'data-rw-overlay';
|
|
426
|
+
function sweepStaleOverlays() {
|
|
427
|
+
// Remove overlay host nodes left behind by previous module generations
|
|
428
|
+
// (e.g. after reloads/bundle toggles) — dead modals that block the page.
|
|
429
|
+
document.querySelectorAll(`[${OVERLAY_TAG}]`).forEach((node) => node.remove());
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function Overlay({ children, onClose }) {
|
|
433
|
+
const hostRef = useRef(null);
|
|
434
|
+
useEffect(() => {
|
|
435
|
+
const host = document.createElement('div');
|
|
436
|
+
host.setAttribute(OVERLAY_TAG, '1');
|
|
437
|
+
document.body.appendChild(host);
|
|
438
|
+
hostRef.current = host;
|
|
439
|
+
return () => { host.remove(); };
|
|
440
|
+
}, []);
|
|
441
|
+
const [host, setHost] = useState(null);
|
|
442
|
+
useEffect(() => { setHost(hostRef.current); }, []);
|
|
443
|
+
if (!host) return null;
|
|
444
|
+
const content = h('div', { style: css.scrim, onMouseDown: (e) => { if (e.target === e.currentTarget) onClose(); } }, children);
|
|
445
|
+
return portal ? portal(content, host) : content;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// ── server manager (list / add / edit / delete) ─────────────────────────
|
|
449
|
+
|
|
450
|
+
function emptyProfileForm() {
|
|
451
|
+
return { name: '', host: '', port: '22', username: 'root', authKind: 'password',
|
|
452
|
+
password: '', privateKey: '', passphrase: '', defaultProjectPath: '' };
|
|
453
|
+
}
|
|
454
|
+
function profileToForm(profile) {
|
|
455
|
+
return {
|
|
456
|
+
profileId: profile.profileId, name: profile.name ?? '', host: profile.host ?? '',
|
|
457
|
+
port: String(profile.port ?? 22), username: profile.username ?? '',
|
|
458
|
+
authKind: profile.authKind ?? 'password',
|
|
459
|
+
password: '', privateKey: '', passphrase: '',
|
|
460
|
+
defaultProjectPath: profile.defaultProjectPath ?? '',
|
|
461
|
+
credentialConfigured: profile.credentialConfigured === true,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function ServerForm({ api, form, setForm, onDone, onCancel }) {
|
|
466
|
+
const [error, setError] = useState(null);
|
|
467
|
+
const [busy, setBusy] = useState(false);
|
|
468
|
+
const set = (key) => (e) => setForm({ ...form, [key]: e.target.value });
|
|
469
|
+
const save = async () => {
|
|
470
|
+
setBusy(true); setError(null);
|
|
471
|
+
console.log('[remote-workspace] profileSave 开始', { host: form.host, username: form.username, authKind: form.authKind });
|
|
472
|
+
try {
|
|
473
|
+
if (!form.host.trim()) throw new Error('主机不能为空');
|
|
474
|
+
if (!form.username.trim()) throw new Error('用户名不能为空');
|
|
475
|
+
if (form.authKind === 'password' && !form.password && !form.profileId) {
|
|
476
|
+
throw new Error('请输入密码');
|
|
477
|
+
}
|
|
478
|
+
if (form.authKind === 'key' && !form.privateKey && !form.profileId) {
|
|
479
|
+
throw new Error('请粘贴私钥');
|
|
480
|
+
}
|
|
481
|
+
const input = {
|
|
482
|
+
...(form.profileId ? { profileId: form.profileId } : {}),
|
|
483
|
+
name: form.name.trim() || form.host.trim(),
|
|
484
|
+
host: form.host.trim(),
|
|
485
|
+
port: Number(form.port) || 22,
|
|
486
|
+
username: form.username.trim(),
|
|
487
|
+
authKind: form.authKind,
|
|
488
|
+
...(form.defaultProjectPath.trim() ? { defaultProjectPath: form.defaultProjectPath.trim() } : {}),
|
|
489
|
+
};
|
|
490
|
+
if (form.authKind === 'password' && form.password) input.password = form.password;
|
|
491
|
+
if (form.authKind === 'key') {
|
|
492
|
+
if (form.privateKey) input.privateKey = form.privateKey;
|
|
493
|
+
if (form.passphrase) input.passphrase = form.passphrase;
|
|
494
|
+
}
|
|
495
|
+
await api.profileSave(input);
|
|
496
|
+
console.log('[remote-workspace] profileSave 成功');
|
|
497
|
+
onDone();
|
|
498
|
+
} catch (cause) {
|
|
499
|
+
console.error('[remote-workspace] profileSave 失败', cause);
|
|
500
|
+
setError(cause?.message ?? String(cause));
|
|
501
|
+
} finally {
|
|
502
|
+
setBusy(false);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
return [
|
|
506
|
+
error ? h('div', { key: 'err', style: css.error }, error) : null,
|
|
507
|
+
h('div', { key: 'r1', style: css.formRow },
|
|
508
|
+
h('span', { style: css.formLabel }, '名称'), h('input', { style: css.input, value: form.name, onChange: set('name'), placeholder: '我的服务器' })),
|
|
509
|
+
h('div', { key: 'r2', style: css.formRow },
|
|
510
|
+
h('span', { style: css.formLabel }, '主机'), h('input', { style: css.input, value: form.host, onChange: set('host'), placeholder: 'example.com' })),
|
|
511
|
+
h('div', { key: 'r3', style: css.formRow },
|
|
512
|
+
h('span', { style: css.formLabel }, '端口'), h('input', { style: css.input, value: form.port, onChange: set('port') })),
|
|
513
|
+
h('div', { key: 'r4', style: css.formRow },
|
|
514
|
+
h('span', { style: css.formLabel }, '用户名'), h('input', { style: css.input, value: form.username, onChange: set('username') })),
|
|
515
|
+
h('div', { key: 'r5', style: css.formRow },
|
|
516
|
+
h('span', { style: css.formLabel }, '认证方式'),
|
|
517
|
+
h('select', { style: css.input, value: form.authKind, onChange: set('authKind') },
|
|
518
|
+
h('option', { value: 'password' }, '密码'),
|
|
519
|
+
h('option', { value: 'key' }, '私钥'))),
|
|
520
|
+
form.authKind === 'password'
|
|
521
|
+
? h('div', { key: 'r6', style: css.formRow },
|
|
522
|
+
h('span', { style: css.formLabel }, '密码(留空保持不变)'),
|
|
523
|
+
h('span', { style: { ...css.info, flex: 'none' } }, form.credentialConfigured === true ? '已保存 ✓' : (form.profileId ? '未设置' : '')),
|
|
524
|
+
h('input', { style: css.input, type: 'password', value: form.password, onChange: set('password') }))
|
|
525
|
+
: [
|
|
526
|
+
h('div', { key: 'r7', style: css.formRow },
|
|
527
|
+
h('span', { style: css.formLabel }, '私钥(留空保持不变)'),
|
|
528
|
+
h('span', { style: { ...css.info, flex: 'none' } }, form.credentialConfigured === true ? '已保存 ✓' : (form.profileId ? '未设置' : '')),
|
|
529
|
+
h('textarea', { style: css.textarea, value: form.privateKey, onChange: set('privateKey'), placeholder: '-----BEGIN OPENSSH PRIVATE KEY-----' })),
|
|
530
|
+
h('div', { key: 'r8', style: css.formRow },
|
|
531
|
+
h('span', { style: css.formLabel }, '私钥口令(可选)'), h('input', { style: css.input, type: 'password', value: form.passphrase, onChange: set('passphrase') })),
|
|
532
|
+
],
|
|
533
|
+
h('div', { key: 'r9', style: css.formRow },
|
|
534
|
+
h('span', { style: css.formLabel }, '默认远程目录'), h('input', { style: css.pathInput, value: form.defaultProjectPath, onChange: set('defaultProjectPath'), placeholder: '/srv/app(可选)' })),
|
|
535
|
+
h('div', { key: 'foot', style: css.foot, onClick: (e) => e.stopPropagation() },
|
|
536
|
+
h('button', { style: css.primaryBtn, disabled: busy, onClick: save }, busy ? '保存中…' : '保存'),
|
|
537
|
+
h('button', { style: css.ghostBtn, onClick: onCancel }, '取消')),
|
|
538
|
+
];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const DEBUG_ID = Math.random().toString(36).slice(2, 7);
|
|
542
|
+
|
|
543
|
+
function ServerManager({ api, onClose, onChanged }) {
|
|
544
|
+
const [profiles, setProfiles] = useState(null);
|
|
545
|
+
const [notice, setNotice] = useState(null);
|
|
546
|
+
const [error, setError] = useState(null);
|
|
547
|
+
const [editing, setEditing] = useState(null); // form object or null
|
|
548
|
+
const load = useCallback(async () => {
|
|
549
|
+
try {
|
|
550
|
+
const value = await api.profileList();
|
|
551
|
+
console.log(`[remote-workspace ${DEBUG_ID}] profileList →`, JSON.stringify(value));
|
|
552
|
+
setProfiles(Array.isArray(value?.profiles) ? value.profiles : []);
|
|
553
|
+
setError(null);
|
|
554
|
+
} catch (cause) {
|
|
555
|
+
console.error(`[remote-workspace ${DEBUG_ID}] profileList 失败`, cause);
|
|
556
|
+
setError(cause?.message ?? String(cause));
|
|
557
|
+
setProfiles([]);
|
|
558
|
+
}
|
|
559
|
+
}, [api]);
|
|
560
|
+
useEffect(() => {
|
|
561
|
+
console.log(`[remote-workspace ${DEBUG_ID}] ServerManager 挂载`);
|
|
562
|
+
void load();
|
|
563
|
+
}, [load]);
|
|
564
|
+
const remove = async (profile) => {
|
|
565
|
+
if (!window.confirm(`删除服务器「${profile.name || profile.host}」?已保存的凭据也会一并删除。`)) return;
|
|
566
|
+
try {
|
|
567
|
+
await api.profileDelete({ profileId: profile.profileId });
|
|
568
|
+
if (profile.connected) await api.profileDisconnect({ profileId: profile.profileId }).catch(() => {});
|
|
569
|
+
await load();
|
|
570
|
+
onChanged?.();
|
|
571
|
+
} catch (cause) {
|
|
572
|
+
setError(cause?.message ?? String(cause));
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
return h(Overlay, { onClose },
|
|
576
|
+
h('div', { style: { ...css.modal, ...css.modalWide }, onMouseDown: (e) => e.stopPropagation() },
|
|
577
|
+
h('div', { style: css.head },
|
|
578
|
+
h('span', { style: css.headTitle }, '服务器管理'),
|
|
579
|
+
h('button', { style: css.ghostBtn, disabled: editing !== null, onClick: () => { setNotice(null); void load(); } }, '⟳ 刷新'),
|
|
580
|
+
h('button', { style: css.ghostBtn, disabled: editing !== null, onClick: () => setEditing(emptyProfileForm()) }, '+ 新增'),
|
|
581
|
+
h('button', { style: css.closeBtn, onClick: onClose, title: '关闭' }, '✕'),
|
|
582
|
+
),
|
|
583
|
+
h('div', { style: css.body },
|
|
584
|
+
error ? h('div', { style: css.error }, error) : null,
|
|
585
|
+
notice ? h('div', { style: css.notice }, notice) : null,
|
|
586
|
+
editing !== null
|
|
587
|
+
? h(ServerForm, { api, form: editing, setForm: setEditing,
|
|
588
|
+
onDone: async () => {
|
|
589
|
+
const savedName = editing?.name || editing?.host || '服务器';
|
|
590
|
+
setEditing(null);
|
|
591
|
+
setNotice(`✅ 已保存:${savedName}`);
|
|
592
|
+
await load();
|
|
593
|
+
onChanged?.();
|
|
594
|
+
},
|
|
595
|
+
onCancel: () => setEditing(null) })
|
|
596
|
+
: [
|
|
597
|
+
profiles === null ? h('div', { style: css.empty }, '加载中…') : null,
|
|
598
|
+
profiles !== null && profiles.length === 0 ? h('div', { style: css.empty }, '还没有保存的服务器,点击「+ 新增」添加。') : null,
|
|
599
|
+
...(profiles ?? []).map((profile) => h('div', { key: profile.profileId, style: { ...css.serverRow, cursor: 'default' } },
|
|
600
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
|
|
601
|
+
h('span', { style: css.serverName }, profile.name || profile.host),
|
|
602
|
+
h('span', { style: css.serverMeta }, `${profile.username}@${profile.host}:${profile.port} · ${profile.authKind === 'password' ? '密码' : '私钥'}` +
|
|
603
|
+
(profile.defaultProjectPath ? ` · 默认目录 ${profile.defaultProjectPath}` : '')),
|
|
604
|
+
),
|
|
605
|
+
profile.connected ? h('span', { style: { ...css.badge, ...css.badgeOk } }, '已连接')
|
|
606
|
+
: profile.credentialConfigured === false ? h('span', { style: { ...css.badge, color: '#f85149', borderColor: 'rgba(248,81,73,.45)' }, title: '未保存密码/私钥,点击编辑补填' }, '缺凭据')
|
|
607
|
+
: null,
|
|
608
|
+
h('button', { style: css.ghostBtn, onClick: () => setEditing(profileToForm(profile)) }, '编辑'),
|
|
609
|
+
h('button', { style: css.dangerBtn, onClick: () => remove(profile) }, '删除'),
|
|
610
|
+
)),
|
|
611
|
+
],
|
|
612
|
+
),
|
|
613
|
+
),
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// ── remote directory browser (bind flow) ────────────────────────────────
|
|
618
|
+
|
|
619
|
+
function RemoteBrowser({ api, profile, connection, onBack, onDone, onError, onManage }) {
|
|
620
|
+
const [path, setPath] = useState(() => {
|
|
621
|
+
const p = (profile.defaultProjectPath || '').trim();
|
|
622
|
+
return p.startsWith('/') ? p : '/';
|
|
623
|
+
});
|
|
624
|
+
const [entries, setEntries] = useState(null);
|
|
625
|
+
const [error, setError] = useState(null);
|
|
626
|
+
const [busy, setBusy] = useState(false);
|
|
627
|
+
const [jump, setJump] = useState('');
|
|
628
|
+
const [status, setStatus] = useState(null);
|
|
629
|
+
const loadRef = useRef(0);
|
|
630
|
+
|
|
631
|
+
const load = useCallback(async (dir) => {
|
|
632
|
+
const token = ++loadRef.current;
|
|
633
|
+
setBusy(true); setError(null);
|
|
634
|
+
try {
|
|
635
|
+
const value = await api.sftpList(connection.connectionId, dir);
|
|
636
|
+
if (token !== loadRef.current) return;
|
|
637
|
+
const list = (Array.isArray(value?.entries) ? value.entries : [])
|
|
638
|
+
.filter((e) => e.isDirectory)
|
|
639
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
640
|
+
setEntries(list);
|
|
641
|
+
setPath(dir);
|
|
642
|
+
} catch (cause) {
|
|
643
|
+
if (token !== loadRef.current) return;
|
|
644
|
+
setError(cause?.message ?? String(cause));
|
|
645
|
+
setEntries([]);
|
|
646
|
+
} finally {
|
|
647
|
+
if (token === loadRef.current) setBusy(false);
|
|
648
|
+
}
|
|
649
|
+
}, [api, connection.connectionId]);
|
|
650
|
+
|
|
651
|
+
useEffect(() => { load(path); /* eslint-disable-line */ }, []);
|
|
652
|
+
|
|
653
|
+
const crumbs = path === '/' ? [] : path.split('/').filter(Boolean);
|
|
654
|
+
|
|
655
|
+
const useThisDirectory = async () => {
|
|
656
|
+
setBusy(true); setStatus('正在创建本地镜像工作区…'); setError(null);
|
|
657
|
+
try {
|
|
658
|
+
// Host-side creation: no dependency on the directory picker's browse capability.
|
|
659
|
+
const mirrorResult = await api.ensureLocalMirrorFolder(`${profile.name || profile.host}-${baseName(path)}`);
|
|
660
|
+
const mirror = mirrorResult?.path ?? mirrorResult;
|
|
661
|
+
if (typeof mirror !== 'string' || mirror.length === 0) throw new Error('镜像文件夹创建结果异常');
|
|
662
|
+
setStatus('正在注册工作区并打开会话…');
|
|
663
|
+
onDone(mirror, path);
|
|
664
|
+
} catch (cause) {
|
|
665
|
+
setStatus(null);
|
|
666
|
+
setError(cause?.message ?? String(cause));
|
|
667
|
+
onError?.(cause);
|
|
668
|
+
} finally {
|
|
669
|
+
setBusy(false);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
return [
|
|
674
|
+
h('div', { key: 'crumbs', style: css.crumbBar },
|
|
675
|
+
h('button', { style: css.ghostBtn, onClick: onBack, title: '返回服务器列表' }, '← 服务器'),
|
|
676
|
+
h('span', { style: { flex: 1 } }),
|
|
677
|
+
...[h('button', { key: 'r', style: crumbs.length ? css.crumb : { ...css.crumb, ...css.crumbHere }, onClick: () => load('/') }, '/')],
|
|
678
|
+
...crumbs.map((part, i) => h(React.Fragment, { key: `${i}-${part}` }, [
|
|
679
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, #6c7480)' } }, '›'),
|
|
680
|
+
h('button', {
|
|
681
|
+
style: i === crumbs.length - 1 ? css.crumbHere : css.crumb,
|
|
682
|
+
onClick: () => load('/' + crumbs.slice(0, i + 1).join('/')),
|
|
683
|
+
}, part),
|
|
684
|
+
])),
|
|
685
|
+
),
|
|
686
|
+
h('div', { key: 'jump', style: css.crumbBar },
|
|
687
|
+
h('button', { style: css.ghostBtn, onClick: () => load(homeGuess(connection.username)) }, '主目录'),
|
|
688
|
+
h('button', { style: css.ghostBtn, onClick: () => load('/') }, '根目录'),
|
|
689
|
+
h('input', {
|
|
690
|
+
style: css.pathInput, value: jump, placeholder: '输入绝对路径跳转,如 /srv/app',
|
|
691
|
+
onChange: (e) => setJump(e.target.value),
|
|
692
|
+
onKeyDown: (e) => { if (e.key === 'Enter' && jump.trim().startsWith('/')) load(jump.trim().replace(/\/+$/, '') || '/'); },
|
|
693
|
+
}),
|
|
694
|
+
h('button', { style: css.ghostBtn, disabled: busy, onClick: () => load(jump.trim().replace(/\/+$/, '') || '/') }, '跳转'),
|
|
695
|
+
),
|
|
696
|
+
error ? h('div', { style: css.error }, error) : null,
|
|
697
|
+
status ? h('div', { style: css.info }, status) : null,
|
|
698
|
+
busy && entries === null && !status ? h('div', { style: css.empty }, '加载中…') : null,
|
|
699
|
+
!busy && entries !== null && entries.length === 0 ? h('div', { style: css.empty }, '(没有子目录)') : null,
|
|
700
|
+
h('div', { key: 'list', style: { display: 'flex', flexDirection: 'column', gap: 2, minHeight: 0 } },
|
|
701
|
+
(entries ?? []).map((entry) => h('button', {
|
|
702
|
+
key: entry.name, style: css.dirRow, onClick: () => load(joinPath(path, entry.name)),
|
|
703
|
+
}, h('span', { style: { flex: 'none', width: 16, textAlign: 'center' } }, '🌐'), h('span', { style: css.dirName }, entry.name))),
|
|
704
|
+
),
|
|
705
|
+
h('div', { key: 'foot', style: css.foot },
|
|
706
|
+
h('span', { style: { ...css.info, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, path),
|
|
707
|
+
h('button', { style: css.primaryBtn, disabled: busy, onClick: useThisDirectory },
|
|
708
|
+
busy ? '处理中…' : '使用此目录'),
|
|
709
|
+
),
|
|
710
|
+
];
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// shared hand-off state between the picker UI and the post-pick binder
|
|
714
|
+
const ownerPickedRef = { current: null };
|
|
715
|
+
|
|
716
|
+
// ── remote server list ──────────────────────────────────────────────────
|
|
717
|
+
|
|
718
|
+
function ServerList({ api, profiles, onPick, onManage, error }) {
|
|
719
|
+
const [connecting, setConnecting] = useState(null);
|
|
720
|
+
const [localError, setLocalError] = useState(null);
|
|
721
|
+
const pick = async (profile) => {
|
|
722
|
+
setConnecting(profile.profileId); setLocalError(null);
|
|
723
|
+
try {
|
|
724
|
+
const value = await api.profileConnect({ profileId: profile.profileId, reuseExisting: true });
|
|
725
|
+
onPick(profile, value);
|
|
726
|
+
} catch (cause) {
|
|
727
|
+
setLocalError(cause?.message ?? String(cause));
|
|
728
|
+
} finally {
|
|
729
|
+
setConnecting(null);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
return [
|
|
733
|
+
error ? h('div', { key: 'err', style: css.error }, error) : null,
|
|
734
|
+
localError ? h('div', { key: 'lerr', style: css.error }, localError) : null,
|
|
735
|
+
h('div', { key: 'manage', style: { textAlign: 'right' } },
|
|
736
|
+
h('button', { style: css.ghostBtn, onClick: onManage }, '管理服务器…')),
|
|
737
|
+
(profiles ?? []).length === 0
|
|
738
|
+
? h('div', { key: 'empty', style: css.empty }, '还没有保存的服务器。点击「管理服务器…」添加,再回来选择远程目录。')
|
|
739
|
+
: profiles.map((profile) => {
|
|
740
|
+
const online = profile.connected === true;
|
|
741
|
+
return h('button', {
|
|
742
|
+
key: profile.profileId, style: css.serverRow, disabled: connecting === profile.profileId,
|
|
743
|
+
onClick: () => pick(profile),
|
|
744
|
+
},
|
|
745
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
|
|
746
|
+
h('span', { style: css.serverName }, profile.name || profile.host),
|
|
747
|
+
h('span', { style: css.serverMeta }, `${profile.username ?? ''}@${profile.host}:${profile.port ?? 22}` +
|
|
748
|
+
(profile.defaultProjectPath ? ` 默认目录 ${profile.defaultProjectPath}` : '')),
|
|
749
|
+
),
|
|
750
|
+
connecting === profile.profileId ? h('span', { style: css.badge }, '连接中…')
|
|
751
|
+
: online ? h('span', { style: { ...css.badge, ...css.badgeOk } }, '已连接')
|
|
752
|
+
: h('span', { style: css.badge }, '点击连接'),
|
|
753
|
+
);
|
|
754
|
+
}),
|
|
755
|
+
];
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ── the directoryFlow entry: 本地 / 远程 choice ──────────────────────────
|
|
759
|
+
|
|
760
|
+
function DirectoryFlowEntry({ owner, api }) {
|
|
761
|
+
const [mode, setMode] = useState(null); // null | 'remote' | 'manage'
|
|
762
|
+
const [profiles, setProfiles] = useState([]);
|
|
763
|
+
const [error, setError] = useState(null);
|
|
764
|
+
const [session, setSession] = useState(null); // { profile, connection }
|
|
765
|
+
const [localBusy, setLocalBusy] = useState(false);
|
|
766
|
+
|
|
767
|
+
const refreshProfiles = useCallback(async () => {
|
|
768
|
+
try {
|
|
769
|
+
const pl = await api.profileList();
|
|
770
|
+
console.log('[remote-workspace flow] profileList →', JSON.stringify(pl));
|
|
771
|
+
setProfiles(Array.isArray(pl?.profiles) ? pl.profiles : []);
|
|
772
|
+
setError(null);
|
|
773
|
+
} catch (cause) {
|
|
774
|
+
console.error('[remote-workspace flow] profileList 失败', cause);
|
|
775
|
+
setError(cause?.message ?? String(cause));
|
|
776
|
+
}
|
|
777
|
+
}, [api]);
|
|
778
|
+
|
|
779
|
+
useEffect(() => {
|
|
780
|
+
if (!owner.open || mode !== 'remote') return;
|
|
781
|
+
void refreshProfiles();
|
|
782
|
+
}, [owner.open, mode, refreshProfiles]);
|
|
783
|
+
|
|
784
|
+
// remote bind continuation: runs after owner.onPicked created the workspace
|
|
785
|
+
useEffect(() => {
|
|
786
|
+
const handoff = ownerPickedRef.current;
|
|
787
|
+
if (!handoff) return;
|
|
788
|
+
ownerPickedRef.current = null;
|
|
789
|
+
let alive = true;
|
|
790
|
+
(async () => {
|
|
791
|
+
for (let i = 0; i < 25; i++) {
|
|
792
|
+
await sleep(400);
|
|
793
|
+
try {
|
|
794
|
+
const ws = await api.bindingList();
|
|
795
|
+
const known = (Array.isArray(ws?.workspaces) ? ws.workspaces : []).some((w) => w.path === handoff.mirror);
|
|
796
|
+
if (known) {
|
|
797
|
+
await api.bindingSave({
|
|
798
|
+
workspacePath: handoff.mirror,
|
|
799
|
+
profileId: handoff.profileId,
|
|
800
|
+
remotePath: handoff.remotePath,
|
|
801
|
+
autoConnect: true,
|
|
802
|
+
});
|
|
803
|
+
// Mark the sidebar workspace with a 🌐 prefix so remote-bound
|
|
804
|
+
// workspaces stand out from local ones (best effort).
|
|
805
|
+
try {
|
|
806
|
+
const wsList = await api.bindingList();
|
|
807
|
+
const candidate = (Array.isArray(wsList?.workspaces) ? wsList.workspaces : [])
|
|
808
|
+
.find((w) => w.path === handoff.mirror);
|
|
809
|
+
if (candidate?.workspaceId) {
|
|
810
|
+
const folderName = handoff.mirror.split(/[\\/]/).pop() || '远程工作区';
|
|
811
|
+
await api.renameWorkspace(candidate.workspaceId, `🌐 ${folderName}`);
|
|
812
|
+
}
|
|
813
|
+
} catch { /* indicator is best effort */ }
|
|
814
|
+
return; // bound
|
|
815
|
+
}
|
|
816
|
+
} catch { /* retry until deadline */ }
|
|
817
|
+
if (!alive) return;
|
|
818
|
+
}
|
|
819
|
+
})();
|
|
820
|
+
return () => { alive = false; };
|
|
821
|
+
}, []);
|
|
822
|
+
|
|
823
|
+
const pickLocal = async () => {
|
|
824
|
+
setLocalBusy(true); setError(null);
|
|
825
|
+
try {
|
|
826
|
+
const path = await api.pickLocal();
|
|
827
|
+
if (path) owner.onPicked(path); else owner.onCancel();
|
|
828
|
+
} catch (cause) {
|
|
829
|
+
setError(cause?.message ?? String(cause));
|
|
830
|
+
} finally {
|
|
831
|
+
setLocalBusy(false);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
if (!owner.open) return null;
|
|
836
|
+
|
|
837
|
+
const body = mode === 'manage'
|
|
838
|
+
? null
|
|
839
|
+
: mode === 'remote'
|
|
840
|
+
? (session
|
|
841
|
+
? h(RemoteBrowser, {
|
|
842
|
+
api, profile: session.profile, connection: session.connection,
|
|
843
|
+
onBack: () => setSession(null),
|
|
844
|
+
onDone: (mirror, remotePath) => { ownerPickedRef.current = { mirror, profileId: session.profile.profileId, remotePath }; owner.onPicked(mirror); },
|
|
845
|
+
onError: () => {},
|
|
846
|
+
})
|
|
847
|
+
: h(ServerList, {
|
|
848
|
+
api, profiles, error,
|
|
849
|
+
onManage: () => setMode('manage'),
|
|
850
|
+
onPick: (profile, connection) => setSession({ profile, connection }),
|
|
851
|
+
}))
|
|
852
|
+
: [
|
|
853
|
+
h('button', { key: 'local', style: css.choiceRow, disabled: localBusy, onClick: pickLocal },
|
|
854
|
+
h('span', { style: css.choiceIcon }, '💻'),
|
|
855
|
+
h('span', null,
|
|
856
|
+
h('div', { style: css.choiceTitle }, localBusy ? '正在打开本地目录选择…' : '本地文件夹'),
|
|
857
|
+
h('div', { style: css.choiceDesc }, '打开系统目录选择器,选择本地磁盘上的文件夹作为工作区。')),
|
|
858
|
+
),
|
|
859
|
+
h('button', { key: 'remote', style: css.choiceRow, onClick: () => setMode('remote') },
|
|
860
|
+
h('span', { style: css.choiceIcon }, '🌐'),
|
|
861
|
+
h('span', null,
|
|
862
|
+
h('div', { style: css.choiceTitle }, '远程 SSH 目录'),
|
|
863
|
+
h('div', { style: css.choiceDesc }, '选择已保存的服务器,可视化浏览远程目录并绑定。文件操作将在远程服务器上执行。')),
|
|
864
|
+
),
|
|
865
|
+
error ? h('div', { key: 'err', style: css.error }, error) : null,
|
|
866
|
+
h('div', { key: 'cancel', style: { textAlign: 'center' } },
|
|
867
|
+
h('button', { style: css.ghostBtn, onClick: owner.onCancel }, '取消')),
|
|
868
|
+
];
|
|
869
|
+
|
|
870
|
+
return [
|
|
871
|
+
mode !== 'manage' ? h(Overlay, { key: 'flow', onClose: owner.onCancel },
|
|
872
|
+
h('div', { style: { ...css.modal, ...css.modalSmall }, onMouseDown: (e) => e.stopPropagation() },
|
|
873
|
+
mode === 'remote' && session
|
|
874
|
+
? null
|
|
875
|
+
: h('div', { style: css.head },
|
|
876
|
+
h('span', { style: css.headTitle }, mode === 'remote' ? '选择远程服务器' : '添加工作区'),
|
|
877
|
+
h('button', { style: css.closeBtn, onClick: owner.onCancel, title: '关闭' }, '✕'),
|
|
878
|
+
),
|
|
879
|
+
h('div', { style: css.body }, body),
|
|
880
|
+
),
|
|
881
|
+
) : null,
|
|
882
|
+
mode === 'manage' ? h(ServerManager, {
|
|
883
|
+
key: 'manage',
|
|
884
|
+
api,
|
|
885
|
+
onClose: () => { setMode('remote'); },
|
|
886
|
+
onChanged: () => { void refreshProfiles(); },
|
|
887
|
+
}) : null,
|
|
888
|
+
];
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// ── composer dock chip: current workspace state ─────────────────────────
|
|
892
|
+
|
|
893
|
+
function DockChip({ api, sessionId }) {
|
|
894
|
+
const [open, setOpen] = useState(false);
|
|
895
|
+
const [state, setState] = useState(null); // { remotePath, profileName } | 'local' | null
|
|
896
|
+
|
|
897
|
+
useEffect(() => {
|
|
898
|
+
let alive = true;
|
|
899
|
+
const load = async () => {
|
|
900
|
+
try {
|
|
901
|
+
if (!sessionId) { if (alive) setState('local'); return; }
|
|
902
|
+
const r = await api.sessionBinding(sessionId);
|
|
903
|
+
if (!alive) return;
|
|
904
|
+
const matchPath = r?.matchWorkspacePath ?? null;
|
|
905
|
+
const match = matchPath ? (r.bindings || []).find((b) => b.workspacePath === matchPath) : null;
|
|
906
|
+
setState(match ? { remotePath: match.remotePath, profileName: match.profileName ?? '' } : 'local');
|
|
907
|
+
} catch {
|
|
908
|
+
if (alive) setState(null);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
void load();
|
|
912
|
+
const timer = setInterval(load, 8000);
|
|
913
|
+
return () => { alive = false; clearInterval(timer); };
|
|
914
|
+
}, [api, sessionId]);
|
|
915
|
+
|
|
916
|
+
const label = state && state !== 'local'
|
|
917
|
+
? `🗂 ${state.profileName ? state.profileName + ':' : '远程'}${state.remotePath}`
|
|
918
|
+
: state === 'local' ? '🗂 本地工作区'
|
|
919
|
+
: '🗂 工作目录';
|
|
920
|
+
|
|
921
|
+
return h(React.Fragment, null,
|
|
922
|
+
h('button', { style: css.chip, title: '当前工作目录(本地 / 远程绑定)', onClick: () => setOpen(true) },
|
|
923
|
+
h('span', { style: css.chipLabel }, label),
|
|
924
|
+
),
|
|
925
|
+
open ? h(PickerModal, { api, onClose: () => setOpen(false) }) : null,
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// ── overview modal (chip) ────────────────────────────────────────────────
|
|
930
|
+
|
|
931
|
+
function PickerModal({ api, onClose }) {
|
|
932
|
+
const [workspaces, setWorkspaces] = useState([]);
|
|
933
|
+
const [bindings, setBindings] = useState([]);
|
|
934
|
+
const [error, setError] = useState(null);
|
|
935
|
+
const [manage, setManage] = useState(false);
|
|
936
|
+
|
|
937
|
+
useEffect(() => {
|
|
938
|
+
if (manage) return;
|
|
939
|
+
let alive = true;
|
|
940
|
+
(async () => {
|
|
941
|
+
try {
|
|
942
|
+
const ws = await api.bindingList();
|
|
943
|
+
if (!alive) return;
|
|
944
|
+
setWorkspaces(Array.isArray(ws?.workspaces) ? ws.workspaces : []);
|
|
945
|
+
setBindings(Array.isArray(ws?.bindings) ? ws.bindings : []);
|
|
946
|
+
setError(null);
|
|
947
|
+
} catch (cause) {
|
|
948
|
+
if (alive) setError(cause?.message ?? String(cause));
|
|
949
|
+
}
|
|
950
|
+
})();
|
|
951
|
+
return () => { alive = false; };
|
|
952
|
+
}, [manage]);
|
|
953
|
+
|
|
954
|
+
if (manage) {
|
|
955
|
+
return h(ServerManager, { api, onClose: () => setManage(false), onChanged: () => {} });
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
const byPath = new Map(bindings.map((b) => [b.workspacePath, b]));
|
|
959
|
+
|
|
960
|
+
return h(Overlay, { onClose },
|
|
961
|
+
h('div', { style: css.modal, onMouseDown: (e) => e.stopPropagation() },
|
|
962
|
+
h('div', { style: css.head },
|
|
963
|
+
h('span', { style: css.headTitle }, '工作区与远程绑定'),
|
|
964
|
+
h('button', { style: css.ghostBtn, onClick: () => setManage(true) }, '服务器管理…'),
|
|
965
|
+
h('button', { style: css.closeBtn, onClick: onClose, title: '关闭' }, '✕'),
|
|
966
|
+
),
|
|
967
|
+
h('div', { style: css.body },
|
|
968
|
+
error ? h('div', { style: css.error }, error) : null,
|
|
969
|
+
workspaces.length === 0 ? h('div', { style: css.empty }, '未发现 DSH 工作区。') : null,
|
|
970
|
+
...workspaces.map((w) => {
|
|
971
|
+
const b = byPath.get(w.path);
|
|
972
|
+
return h('div', { key: w.path, style: { ...css.serverRow, cursor: 'default' } },
|
|
973
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
|
|
974
|
+
h('span', { style: css.serverName }, w.title || '工作区'),
|
|
975
|
+
h('span', { style: css.serverMeta }, w.path),
|
|
976
|
+
),
|
|
977
|
+
b
|
|
978
|
+
? h('span', { style: { ...css.badge, ...css.badgeOk }, title: `${b.profileName || b.profileId} → ${b.remotePath}` }, `${b.profileName || '远程'} → ${b.remotePath}`)
|
|
979
|
+
: h('span', { style: css.badge }, '本地目录'),
|
|
980
|
+
);
|
|
981
|
+
}),
|
|
982
|
+
h('div', { style: css.info }, '要新增远程绑定,请通过侧栏「+」或对话框上方的工作区选择器添加工作区时选择「远程 SSH 目录」。'),
|
|
983
|
+
),
|
|
984
|
+
),
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// ── right-sidebar remote files panel (feature ①) ─────────────────────────
|
|
989
|
+
|
|
990
|
+
function RemoteFilesPanel({ api, sessionId }) {
|
|
991
|
+
const [bindings, setBindings] = useState([]);
|
|
992
|
+
const [activeIdx, setActiveIdx] = useState(0);
|
|
993
|
+
const [connectionId, setConnectionId] = useState(null);
|
|
994
|
+
const [path, setPath] = useState('/');
|
|
995
|
+
const [entries, setEntries] = useState(null);
|
|
996
|
+
const [error, setError] = useState(null);
|
|
997
|
+
const [busy, setBusy] = useState(false);
|
|
998
|
+
const [jump, setJump] = useState('');
|
|
999
|
+
const [editor, setEditor] = useState(null); // { path, data, bytes, truncated, busy, error }
|
|
1000
|
+
const loadRef = useRef(0);
|
|
1001
|
+
|
|
1002
|
+
const activeBinding = bindings[activeIdx] ?? null;
|
|
1003
|
+
const sessionMatched = useRef(false);
|
|
1004
|
+
|
|
1005
|
+
// refresh bindings periodically; default-select the binding that matches
|
|
1006
|
+
// THIS session's working directory (per-session remote workspace awareness)
|
|
1007
|
+
useEffect(() => {
|
|
1008
|
+
let alive = true;
|
|
1009
|
+
const load = async () => {
|
|
1010
|
+
try {
|
|
1011
|
+
const value = sessionId
|
|
1012
|
+
? await api.sessionBinding(sessionId)
|
|
1013
|
+
: await api.bindingList();
|
|
1014
|
+
if (!alive) return;
|
|
1015
|
+
const list = Array.isArray(value?.bindings) ? value.bindings : [];
|
|
1016
|
+
setBindings(list);
|
|
1017
|
+
if (!sessionMatched.current && sessionId) {
|
|
1018
|
+
const matchPath = value?.matchWorkspacePath ?? null;
|
|
1019
|
+
if (matchPath) {
|
|
1020
|
+
const idx = list.findIndex((b) => b.workspacePath === matchPath);
|
|
1021
|
+
if (idx >= 0) { setActiveIdx(idx); sessionMatched.current = true; }
|
|
1022
|
+
} else if (list.length > 0) {
|
|
1023
|
+
// no match for this session: keep manual selector but mark checked
|
|
1024
|
+
sessionMatched.current = true;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
setActiveIdx((idx) => (idx < list.length ? idx : 0));
|
|
1028
|
+
} catch { /* namespace not ready yet */ }
|
|
1029
|
+
};
|
|
1030
|
+
void load();
|
|
1031
|
+
const timer = setInterval(load, 8000);
|
|
1032
|
+
return () => { alive = false; clearInterval(timer); };
|
|
1033
|
+
}, [api, sessionId]);
|
|
1034
|
+
|
|
1035
|
+
const list = useCallback(async (connection, dir) => {
|
|
1036
|
+
const token = ++loadRef.current;
|
|
1037
|
+
setBusy(true); setError(null);
|
|
1038
|
+
try {
|
|
1039
|
+
const value = await api.sftpList(connection, dir);
|
|
1040
|
+
if (token !== loadRef.current) return;
|
|
1041
|
+
const sorted = (Array.isArray(value?.entries) ? value.entries : [])
|
|
1042
|
+
.sort((a, b) => (a.isDirectory === b.isDirectory ? a.name.localeCompare(b.name) : a.isDirectory ? -1 : 1));
|
|
1043
|
+
setEntries(sorted);
|
|
1044
|
+
setPath(dir);
|
|
1045
|
+
} catch (cause) {
|
|
1046
|
+
if (token !== loadRef.current) return;
|
|
1047
|
+
setError(cause?.message ?? String(cause));
|
|
1048
|
+
setEntries([]);
|
|
1049
|
+
} finally {
|
|
1050
|
+
if (token === loadRef.current) setBusy(false);
|
|
1051
|
+
}
|
|
1052
|
+
}, [api]);
|
|
1053
|
+
|
|
1054
|
+
// (re)connect when the selected binding changes
|
|
1055
|
+
useEffect(() => {
|
|
1056
|
+
if (!activeBinding) { setConnectionId(null); setEntries(null); return; }
|
|
1057
|
+
let alive = true;
|
|
1058
|
+
(async () => {
|
|
1059
|
+
setBusy(true); setError(null); setEntries(null);
|
|
1060
|
+
try {
|
|
1061
|
+
const value = await api.profileConnect({ profileId: activeBinding.profileId, reuseExisting: true });
|
|
1062
|
+
if (!alive) return;
|
|
1063
|
+
setConnectionId(value.connectionId);
|
|
1064
|
+
const start = (activeBinding.remotePath || '/').startsWith('/') ? activeBinding.remotePath : '/';
|
|
1065
|
+
await list(value.connectionId, start);
|
|
1066
|
+
} catch (cause) {
|
|
1067
|
+
if (!alive) return;
|
|
1068
|
+
setError(cause?.message ?? String(cause));
|
|
1069
|
+
setConnectionId(null);
|
|
1070
|
+
} finally {
|
|
1071
|
+
if (alive) setBusy(false);
|
|
1072
|
+
}
|
|
1073
|
+
})();
|
|
1074
|
+
return () => { alive = false; };
|
|
1075
|
+
}, [activeBinding?.profileId]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
1076
|
+
|
|
1077
|
+
if (!bindings.length) {
|
|
1078
|
+
return h('div', { style: { padding: 14, color: 'var(--dsw-alias-label-secondary, #9aa3b0)', fontSize: 12, lineHeight: 1.7 } },
|
|
1079
|
+
'当前没有任何远程工作区绑定。',
|
|
1080
|
+
h('div', { style: { marginTop: 6 } }, '通过侧栏「+」添加工作区时选择「远程 SSH 目录」即可创建绑定,绑定后这里会显示远程主机的文件树。'),
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
const openFile = async (entry) => {
|
|
1085
|
+
if (!connectionId) return;
|
|
1086
|
+
const filePath = joinPath(path, entry.name);
|
|
1087
|
+
setEditor({ path: filePath, data: '', busy: true, error: null, truncated: false, dirty: false });
|
|
1088
|
+
try {
|
|
1089
|
+
const value = await api.fileRead(connectionId, filePath);
|
|
1090
|
+
setEditor({ path: filePath, data: value.data ?? '', bytes: value.bytes ?? 0, truncated: value.truncated === true, busy: false, error: null, dirty: false });
|
|
1091
|
+
} catch (cause) {
|
|
1092
|
+
setEditor({ path: filePath, data: '', busy: false, error: cause?.message ?? String(cause), truncated: false, dirty: false });
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
const saveFile = async () => {
|
|
1097
|
+
if (!editor || !connectionId) return;
|
|
1098
|
+
setEditor({ ...editor, busy: true, error: null });
|
|
1099
|
+
try {
|
|
1100
|
+
await api.fileWrite(connectionId, editor.path, editor.data);
|
|
1101
|
+
setEditor({ ...editor, busy: false, dirty: false });
|
|
1102
|
+
} catch (cause) {
|
|
1103
|
+
setEditor({ ...editor, busy: false, error: cause?.message ?? String(cause) });
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
const mkdir = async () => {
|
|
1108
|
+
const name = window.prompt('新文件夹名称(在当前目录下创建):');
|
|
1109
|
+
if (!name || !connectionId) return;
|
|
1110
|
+
try {
|
|
1111
|
+
await api.sftpMkdir(connectionId, joinPath(path, name));
|
|
1112
|
+
await list(connectionId, path);
|
|
1113
|
+
} catch (cause) {
|
|
1114
|
+
setError(cause?.message ?? String(cause));
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
const crumbs = path === '/' ? [] : path.split('/').filter(Boolean);
|
|
1119
|
+
|
|
1120
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, fontSize: 12, color: 'var(--dsw-alias-label-primary, #d7dbe2)' } },
|
|
1121
|
+
h('select', {
|
|
1122
|
+
value: String(activeIdx), onChange: (e) => setActiveIdx(Number(e.target.value)),
|
|
1123
|
+
style: { margin: '8px 10px 0', height: 28, borderRadius: 8, fontSize: 12, background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))', color: 'inherit', border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))' },
|
|
1124
|
+
},
|
|
1125
|
+
bindings.map((b, i) => h('option', { key: b.workspacePath, value: String(i) },
|
|
1126
|
+
`${b.profileName || b.host} → ${b.remotePath}${b.connected ? '(已连接)' : ''}`)),
|
|
1127
|
+
),
|
|
1128
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 4, flexWrap: 'wrap', padding: '8px 10px 0' } },
|
|
1129
|
+
h('button', { style: css.ghostBtn, disabled: !connectionId, onClick: () => list(connectionId, parentOf(path)) }, '↑ 上级'),
|
|
1130
|
+
h('button', { style: css.ghostBtn, disabled: !connectionId, onClick: () => list(connectionId, homeGuess(activeBinding?.username)) }, '主目录'),
|
|
1131
|
+
h('button', { style: css.ghostBtn, disabled: !connectionId, onClick: () => list(connectionId, '/') }, '根目录'),
|
|
1132
|
+
h('button', { style: css.ghostBtn, disabled: !connectionId, onClick: mkdir }, '+ 文件夹'),
|
|
1133
|
+
h('button', { style: css.ghostBtn, disabled: !connectionId, onClick: () => list(connectionId, path) }, '刷新'),
|
|
1134
|
+
),
|
|
1135
|
+
h('div', { style: { display: 'flex', gap: 4, padding: '6px 10px 0' } },
|
|
1136
|
+
h('input', {
|
|
1137
|
+
style: { ...css.pathInput, flex: 1 }, value: jump, placeholder: '绝对路径跳转',
|
|
1138
|
+
onChange: (e) => setJump(e.target.value),
|
|
1139
|
+
onKeyDown: (e) => { if (e.key === 'Enter' && jump.trim().startsWith('/')) list(connectionId, jump.trim().replace(/\/+$/, '') || '/'); },
|
|
1140
|
+
}),
|
|
1141
|
+
),
|
|
1142
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 3, flexWrap: 'wrap', padding: '6px 10px 2px', fontFamily: 'ui-monospace, Menlo, monospace', color: 'var(--dsw-alias-label-secondary, #9aa3b0)' } },
|
|
1143
|
+
h('button', { style: css.crumb, onClick: () => list(connectionId, '/') }, '/'),
|
|
1144
|
+
...crumbs.map((part, i) => h(React.Fragment, { key: `${i}-${part}` }, [
|
|
1145
|
+
h('button', { style: i === crumbs.length - 1 ? css.crumbHere : css.crumb, onClick: () => list(connectionId, '/' + crumbs.slice(0, i + 1).join('/')) }, part),
|
|
1146
|
+
i < crumbs.length - 1 ? h('span', null, '›') : null,
|
|
1147
|
+
])),
|
|
1148
|
+
),
|
|
1149
|
+
error ? h('div', { style: { ...css.error, margin: '0 10px' } }, error) : null,
|
|
1150
|
+
busy && entries === null ? h('div', { style: css.empty }, '加载中…') : null,
|
|
1151
|
+
!busy && entries !== null && entries.length === 0 ? h('div', { style: css.empty }, '(空目录)') : null,
|
|
1152
|
+
h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '0 6px 8px' } },
|
|
1153
|
+
(entries ?? []).map((entry) => h('button', {
|
|
1154
|
+
key: entry.name,
|
|
1155
|
+
style: { ...css.dirRow, fontSize: 12 },
|
|
1156
|
+
onDoubleClick: () => { if (!entry.isDirectory) openFile(entry); },
|
|
1157
|
+
onClick: () => { if (entry.isDirectory) list(connectionId, joinPath(path, entry.name)); else openFile(entry); },
|
|
1158
|
+
},
|
|
1159
|
+
h('span', { style: { flex: 'none', width: 16, textAlign: 'center' } }, entry.isDirectory ? '📁' : '📄'),
|
|
1160
|
+
h('span', { style: css.dirName, title: entry.name }, entry.name),
|
|
1161
|
+
!entry.isDirectory ? h('span', { style: { ...css.serverMeta, marginLeft: 'auto', flex: 'none' } }, formatSize(entry.size)) : null,
|
|
1162
|
+
)),
|
|
1163
|
+
),
|
|
1164
|
+
editor ? h(EditorOverlay, { editor, setEditor, saveFile, onClose: () => setEditor(null) }) : null,
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function parentOf(path) {
|
|
1169
|
+
if (path === '/') return '/';
|
|
1170
|
+
const idx = path.lastIndexOf('/');
|
|
1171
|
+
return idx <= 0 ? '/' : path.slice(0, idx);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function formatSize(size) {
|
|
1175
|
+
if (!Number.isFinite(size)) return '';
|
|
1176
|
+
if (size < 1024) return `${size}B`;
|
|
1177
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}KB`;
|
|
1178
|
+
return `${(size / 1024 / 1024).toFixed(1)}MB`;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function EditorOverlay({ editor, setEditor, saveFile, onClose }) {
|
|
1182
|
+
return h(Overlay, { onClose },
|
|
1183
|
+
h('div', { style: { ...css.modal, width: 720 }, onMouseDown: (e) => e.stopPropagation() },
|
|
1184
|
+
h('div', { style: css.head },
|
|
1185
|
+
h('span', { style: { ...css.headTitle, fontFamily: 'ui-monospace, Menlo, monospace', overflow: 'hidden', textOverflow: 'ellipsis' } }, editor.path),
|
|
1186
|
+
editor.truncated ? h('span', { style: css.badge }, '已截断(>1MB,保存会覆盖截断部分)') : null,
|
|
1187
|
+
h('button', { style: css.closeBtn, onClick: onClose, title: '关闭' }, '✕'),
|
|
1188
|
+
),
|
|
1189
|
+
editor.busy ? h('div', { style: css.empty }, '加载中…') : null,
|
|
1190
|
+
editor.error ? h('div', { style: { ...css.error, margin: 10 } }, editor.error) : null,
|
|
1191
|
+
!editor.busy ? h('textarea', {
|
|
1192
|
+
value: editor.data,
|
|
1193
|
+
onChange: (e) => setEditor({ ...editor, data: e.target.value, dirty: true }),
|
|
1194
|
+
spellCheck: false,
|
|
1195
|
+
style: {
|
|
1196
|
+
flex: 1, minHeight: 0, margin: 10, borderRadius: 8, padding: 10, resize: 'none',
|
|
1197
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 12, lineHeight: 1.5,
|
|
1198
|
+
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.06))', color: 'var(--dsw-alias-label-primary, #d7dbe2)',
|
|
1199
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.2))',
|
|
1200
|
+
},
|
|
1201
|
+
}) : null,
|
|
1202
|
+
h('div', { style: css.foot },
|
|
1203
|
+
h('span', { style: { ...css.info, flex: 1 } }, editor.dirty ? '有未保存修改' : ''),
|
|
1204
|
+
h('button', { style: css.primaryBtn, disabled: editor.busy, onClick: saveFile }, editor.busy ? '保存中…' : '保存(覆盖远程文件)'),
|
|
1205
|
+
),
|
|
1206
|
+
),
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// Right-sidebar tab registrations (mirror the official ui-sidebar-terminal pattern).
|
|
1211
|
+
|
|
1212
|
+
function RemoteFilesGuide(props) {
|
|
1213
|
+
const { api, sessionId, kind, title, description, actions, useTabInfo } = props;
|
|
1214
|
+
const [bound, setBound] = useState(null); // null = checking
|
|
1215
|
+
// Hooks must run during render: resolve the tab once, click handlers use the result.
|
|
1216
|
+
const tabInfo = typeof useTabInfo === 'function' ? useTabInfo() : null;
|
|
1217
|
+
const openActions = actions ?? tabInfo?.tab?.actions;
|
|
1218
|
+
useEffect(() => {
|
|
1219
|
+
if (!sessionId) return;
|
|
1220
|
+
let alive = true;
|
|
1221
|
+
(async () => {
|
|
1222
|
+
try {
|
|
1223
|
+
const r = await api.sessionBinding(sessionId);
|
|
1224
|
+
if (alive) setBound(!!r?.matchWorkspacePath);
|
|
1225
|
+
} catch { if (alive) setBound(false); }
|
|
1226
|
+
})();
|
|
1227
|
+
return () => { alive = false; };
|
|
1228
|
+
}, [sessionId, api]);
|
|
1229
|
+
const open = () => {
|
|
1230
|
+
try {
|
|
1231
|
+
const target = openActions ?? tabInfo?.tab?.actions;
|
|
1232
|
+
if (target?.openTab) target.openTab(kind ?? 'remote-files');
|
|
1233
|
+
else console.error('[remote-workspace] guide open: no tab actions available');
|
|
1234
|
+
} catch (cause) { console.error('[remote-workspace] guide open failed', cause); }
|
|
1235
|
+
};
|
|
1236
|
+
// Fail-closed: the 🌐 entry shows ONLY in sessions confirmed remote-bound.
|
|
1237
|
+
if (bound !== true) return null;
|
|
1238
|
+
return h('button', {
|
|
1239
|
+
onClick: open,
|
|
1240
|
+
'data-sidebar-right-guide-entry': 'remote-files',
|
|
1241
|
+
title: typeof description === 'string' ? description : '浏览并编辑绑定远程目录中的文件',
|
|
1242
|
+
style: {
|
|
1243
|
+
all: 'unset', boxSizing: 'border-box', cursor: 'pointer',
|
|
1244
|
+
display: 'flex', alignItems: 'center', gap: 10, width: '100%',
|
|
1245
|
+
padding: '12px 16px', borderRadius: 10, textAlign: 'left',
|
|
1246
|
+
border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.20))',
|
|
1247
|
+
background: 'var(--dsw-alias-bg-layer-1, rgba(127,127,127,.05))',
|
|
1248
|
+
},
|
|
1249
|
+
},
|
|
1250
|
+
h('span', {
|
|
1251
|
+
style: {
|
|
1252
|
+
flex: 'none', width: 26, height: 26, display: 'inline-flex',
|
|
1253
|
+
alignItems: 'center', justifyContent: 'center',
|
|
1254
|
+
fontSize: 17, lineHeight: 1, borderRadius: 8,
|
|
1255
|
+
background: 'rgba(59,130,246,.12)',
|
|
1256
|
+
},
|
|
1257
|
+
}, '🌐'),
|
|
1258
|
+
h('span', { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
|
|
1259
|
+
h('span', { style: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #d7dbe2)' } },
|
|
1260
|
+
typeof title === 'string' ? title : '打开远程文件'),
|
|
1261
|
+
h('span', { style: { fontSize: 11, color: 'var(--dsw-alias-label-secondary, #9aa3b0)' } },
|
|
1262
|
+
typeof description === 'string' ? description : '浏览并编辑绑定远程目录中的文件'),
|
|
1263
|
+
),
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
function RemoteFilesTitle() {
|
|
1268
|
+
return h('span', null, '🌐 远程文件');
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
/** Best-effort locale namespace so the tab shell can translate if it wants to. */
|
|
1272
|
+
function tryRegisterLocale(ctx) {
|
|
1273
|
+
try {
|
|
1274
|
+
ctx.locale?.register?.('ssh-file-panel', {
|
|
1275
|
+
zh: { panelTitle: '远程文件' },
|
|
1276
|
+
en: { panelTitle: 'Remote Files' },
|
|
1277
|
+
});
|
|
1278
|
+
} catch { /* locale service unavailable */ }
|
|
1279
|
+
return () => {};
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// ── module face ──────────────────────────────────────────────────────────
|
|
1283
|
+
|
|
1284
|
+
return {
|
|
1285
|
+
inject: ['slots', 'remote', 'remote.directoryPicker', 'remote.workspace'],
|
|
1286
|
+
async apply(ctx) {
|
|
1287
|
+
// Register the client typert face so ctx.remote.namespaces has 'remoteWorkspace'.
|
|
1288
|
+
const disposeRemote = await ctx.remote.$mount(TYPERT_REMOTE);
|
|
1289
|
+
|
|
1290
|
+
// Kill any dead overlay DOM from a previous module generation first.
|
|
1291
|
+
sweepStaleOverlays();
|
|
1292
|
+
|
|
1293
|
+
const api = makeApi(ctx);
|
|
1294
|
+
|
|
1295
|
+
const registerFlowSlot = (slotName) => ctx.slots.inject(slotName, () => ctx.slots.register(
|
|
1296
|
+
// priority -1 shadows the built-in native picker (lowest renders) so
|
|
1297
|
+
// both registrants can coexist instead of colliding at priority 0.
|
|
1298
|
+
{ name: slotName, id: 'ssh-file', priority: -1 },
|
|
1299
|
+
function RemoteWorkspaceDirectoryFlow(props) {
|
|
1300
|
+
return h(DirectoryFlowEntry, { owner: props, api });
|
|
1301
|
+
},
|
|
1302
|
+
));
|
|
1303
|
+
|
|
1304
|
+
const disposers = [
|
|
1305
|
+
registerFlowSlot('sidebar.workspaces.directoryFlow'),
|
|
1306
|
+
registerFlowSlot('conversation.hero.workspace.directoryFlow'),
|
|
1307
|
+
registerFlowSlot('workspace.picker.directoryFlow'),
|
|
1308
|
+
ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register(
|
|
1309
|
+
{ name: 'conversation.composer.dock', id: 'ssh-file', order: 5, inject: (sessionId) => ({ sessionId }) },
|
|
1310
|
+
function RemoteWorkspaceChip(props) { return h(DockChip, { api, sessionId: props?.sessionId }); },
|
|
1311
|
+
)),
|
|
1312
|
+
// Declare the tab TYPE so the right-sidebar guide lists our entry —
|
|
1313
|
+
// without this the guide entry / pane / title slots never render.
|
|
1314
|
+
// NOTE: guide icon must be a COMPONENT (rendered as <Icon/>), not an element.
|
|
1315
|
+
ctx.inject(['sidebarRightTabs'], (tabsCtx) => {
|
|
1316
|
+
tabsCtx.effect(() => {
|
|
1317
|
+
function RemoteFilesIcon() {
|
|
1318
|
+
return h('span', { style: { fontSize: 16 } }, '🌐');
|
|
1319
|
+
}
|
|
1320
|
+
try {
|
|
1321
|
+
tabsCtx.sidebarRightTabs.register({
|
|
1322
|
+
id: 'dsh-ssh-file',
|
|
1323
|
+
kind: 'remote-files',
|
|
1324
|
+
multiple: true,
|
|
1325
|
+
priority: 'extension',
|
|
1326
|
+
title: () => '🌐 远程文件',
|
|
1327
|
+
guide: [{
|
|
1328
|
+
id: 'open',
|
|
1329
|
+
order: 20,
|
|
1330
|
+
title: () => '打开远程文件',
|
|
1331
|
+
description: () => '浏览并编辑绑定远程目录中的文件',
|
|
1332
|
+
icon: RemoteFilesIcon,
|
|
1333
|
+
}],
|
|
1334
|
+
});
|
|
1335
|
+
} catch (e) { console.error('[remote-workspace] sidebarRightTabs.register failed', e); }
|
|
1336
|
+
}, 'dsh-ssh-file: tab type');
|
|
1337
|
+
}),
|
|
1338
|
+
// right-sidebar "远程文件" panel tab (guide entry + pane body + title)
|
|
1339
|
+
tryRegisterLocale(ctx),
|
|
1340
|
+
ctx.slots.inject('sidebar.right.tab.guide.entry', () => ctx.slots.register(
|
|
1341
|
+
// key MUST equal the sidebarRightTabs registration id — the guide
|
|
1342
|
+
// dispatches occupants by entry.providerId, falling back to a
|
|
1343
|
+
// generic EntryBox (no per-session hiding) when no occupant matches.
|
|
1344
|
+
{ name: 'sidebar.right.tab.guide.entry', key: 'dsh-ssh-file', locale: 'ssh-file-panel', inject: (sessionId) => ({ sessionId }) },
|
|
1345
|
+
function SshFileGuideEntry(props) { return h(RemoteFilesGuide, { api, sessionId: props?.sessionId, ...props }); },
|
|
1346
|
+
)),
|
|
1347
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register(
|
|
1348
|
+
{ name: 'sidebar.right.pane.tab', key: 'dsh-ssh-file', locale: 'ssh-file-panel', inject: (sessionId) => ({ sessionId }) },
|
|
1349
|
+
function SshFilePaneTab(props) { return h(RemoteFilesPanel, { api, sessionId: props?.sessionId }); },
|
|
1350
|
+
)),
|
|
1351
|
+
ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register(
|
|
1352
|
+
{ name: 'sidebar.right.pane.tab.title', key: 'dsh-ssh-file', locale: 'ssh-file-panel' },
|
|
1353
|
+
function SshFilePaneTabTitle() { return h(RemoteFilesTitle); },
|
|
1354
|
+
)),
|
|
1355
|
+
];
|
|
1356
|
+
|
|
1357
|
+
return async () => {
|
|
1358
|
+
for (const dispose of disposers) { try { dispose?.(); } catch { /* ignore */ } }
|
|
1359
|
+
try { await disposeRemote?.(); } catch { /* ignore */ }
|
|
1360
|
+
};
|
|
1361
|
+
},
|
|
1362
|
+
};
|
|
1363
|
+
},
|
|
1364
|
+
});
|