Snippets panel updates right after adding a snippet; SFTP explorer refreshes reliably: keeps selection and scroll on refresh, refreshes both panes after delete/rename/mkdir, target pane after each transferred file, auto-refresh on tab/window focus and every 10 s while visible, selects new/renamed items, greys out items being deleted, F5/Del/F2 shortcuts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
809227e8f1
commit
2dff4a5c47
3 files changed
+53
-21
No files matched your search
@@ -339,6 +339,7 @@
|
||||
'Move {n} item(s) to the trash: {list}': '{n} Element(e) in den Papierkorb verschieben: {list}',
|
||||
'Permanently delete {n} item(s) from the server: {list}': '{n} Element(e) endgültig vom Server löschen: {list}',
|
||||
'Nothing selected': 'Nichts ausgewählt',
|
||||
'{n} item(s) deleted': '{n} Element(e) gelöscht',
|
||||
'Try again': 'Erneut versuchen',
|
||||
'done': 'fertig',
|
||||
'Error': 'Fehler',
|
||||
|
||||
+50
-21
@@ -681,7 +681,7 @@ function viewSnippets(page) {
|
||||
}
|
||||
c.append(l, templateList());
|
||||
}
|
||||
function editSnippet(s = {}) {
|
||||
function editSnippet(s = {}, onSaved) {
|
||||
const form = openDrawer(s.id ? T('Edit snippet') : T('New snippet'), [
|
||||
field('Name', 'label', s.label, { placeholder: T('System update') }),
|
||||
field(T('Command(s)'), 'command', s.command, { type: 'textarea', placeholder: 'sudo pacman -Syu' }),
|
||||
@@ -690,7 +690,8 @@ function editSnippet(s = {}) {
|
||||
const v = formValues(form);
|
||||
if (!v.command.trim()) throw new Error(T('Command is missing.'));
|
||||
await call('vault:upsert', 'snippets', { ...s, ...v, label: v.label || v.command.split('\n')[0].slice(0, 40) });
|
||||
reload();
|
||||
await reload();
|
||||
onSaved?.();
|
||||
});
|
||||
}
|
||||
// Eingebaute Vorlagen (nicht im Vault). Parameter werden vor dem Ausführen abgefragt; build() liefert eine Zeile.
|
||||
@@ -1768,7 +1769,7 @@ class TerminalSession {
|
||||
const fid = e.target.closest('[data-feature]')?.dataset.feature;
|
||||
if (fid) featureOpeners()[fid](this.host);
|
||||
if (a === 'snip') { $('.snip-panel', this.el).classList.toggle('open'); this.renderSnips(); this.doFit(); }
|
||||
if (a === 'snipnew') editSnippet();
|
||||
if (a === 'snipnew') editSnippet({}, () => this.renderSnips());
|
||||
if (a === 'find') this.toggleFind();
|
||||
const f = e.target.closest('[data-f]')?.dataset.f;
|
||||
const inp = $('.findbar input', this.el);
|
||||
@@ -2161,14 +2162,21 @@ class FilePane {
|
||||
const p = e.target.closest('[data-p]')?.dataset.p;
|
||||
if (p === 'up') this.up();
|
||||
if (p === 'home') this.go(this.home);
|
||||
if (p === 'refresh') this.go(this.cwd);
|
||||
if (p === 'refresh') this.refresh();
|
||||
if (p === 'mkdir') this.mkdir();
|
||||
if (p === 'xfer') this.transferSelected();
|
||||
if (p === 'upload') this.pickUpload();
|
||||
});
|
||||
$('.path', this.el).addEventListener('keydown', (e) => { if (e.key === 'Enter') this.go(e.target.value); });
|
||||
const files = $('.files', this.el);
|
||||
files.addEventListener('contextmenu', (e) => { if (!e.target.closest('tr[data-i]')) { e.preventDefault(); ctxMenu(e.clientX, e.clientY, [{ label: T('New folder'), icon: 'newdir', run: () => this.mkdir() }, { label: T('Refresh'), icon: 'refresh', run: () => this.go(this.cwd) }]); } });
|
||||
// Tastatur: F5 aktualisieren, Entf löschen, F2 umbenennen
|
||||
files.tabIndex = 0;
|
||||
files.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'F5') { e.preventDefault(); this.refresh(); }
|
||||
else if (e.key === 'Delete' && this.sel.size) { e.preventDefault(); this.remove(); }
|
||||
else if (e.key === 'F2' && this.sel.size === 1) { e.preventDefault(); this.rename(this.files.find((x) => this.sel.has(x.name))); }
|
||||
});
|
||||
files.addEventListener('contextmenu', (e) => { if (!e.target.closest('tr[data-i]')) { e.preventDefault(); ctxMenu(e.clientX, e.clientY, [{ label: T('New folder'), icon: 'newdir', run: () => this.mkdir() }, { label: T('Refresh'), icon: 'refresh', run: () => this.refresh() }]); } });
|
||||
// Drag & Drop zwischen den Panes
|
||||
// Web-Version: Dateien aus dem Betriebssystem in den Server-Bereich ziehen = hochladen
|
||||
const osFiles = (e) => WEB && [...(e.dataTransfer?.types || [])].includes('Files');
|
||||
@@ -2186,8 +2194,7 @@ class FilePane {
|
||||
if (!WEB) {
|
||||
// Desktop: Dateiauswahl des Systems, Upload in den aktuellen Server-Ordner
|
||||
const files = await call('sftp:pickUpload');
|
||||
for (const f of files) await this.sftp.transfer('upload', f.path, await this.join(this.cwd, f.name), f.name);
|
||||
if (files.length) this.go(this.cwd);
|
||||
for (const f of files) { await this.sftp.transfer('upload', f.path, await this.join(this.cwd, f.name), f.name); this.refresh(); }
|
||||
return;
|
||||
}
|
||||
const inp = h('<input type="file" multiple style="display:none"/>');
|
||||
@@ -2196,8 +2203,7 @@ class FilePane {
|
||||
inp.click();
|
||||
}
|
||||
async uploadFiles(files) {
|
||||
for (const f of files) await this.sftp.webTransfer('upload', f, `${this.cwd.replace(/\/$/, '')}/${f.name}`, f.name);
|
||||
this.go(this.cwd);
|
||||
for (const f of files) { await this.sftp.webTransfer('upload', f, `${this.cwd.replace(/\/$/, '')}/${f.name}`, f.name); this.refresh(); }
|
||||
}
|
||||
async join(...p) { return this.side === 'local' ? api.call('local:join', ...p) : p.join('/').replace(/\/+/g, '/'); }
|
||||
async parent(p) { return this.side === 'local' ? api.call('local:parent', p) : (p.replace(/\/[^/]+\/?$/, '') || '/'); }
|
||||
@@ -2212,15 +2218,26 @@ class FilePane {
|
||||
return this.go(home);
|
||||
}
|
||||
async up() { this.go(await this.parent(this.cwd)); }
|
||||
async go(dir) {
|
||||
// keep: Auswahl und Scrollposition behalten (Aktualisieren im selben Ordner); select: diese Namen danach markieren
|
||||
async go(dir, { keep = false, select, quiet = false } = {}) {
|
||||
const seq = (this.seq = (this.seq || 0) + 1);
|
||||
try {
|
||||
const files = await this.list(dir);
|
||||
this.cwd = dir; this.files = files; this.sel.clear();
|
||||
$('.path', this.el).value = dir;
|
||||
if (seq !== this.seq) return; // inzwischen neuer angefordert
|
||||
const box = $('.files', this.el), scroll = keep ? box.scrollTop : 0;
|
||||
const sel = select ? new Set(select) : keep ? this.sel : new Set();
|
||||
this.cwd = dir; this.files = files; this.sel = new Set(files.map((f) => f.name).filter((n) => sel.has(n)));
|
||||
if (!keep) this.lastIdx = null;
|
||||
const path = $('.path', this.el); if (document.activeElement !== path || !keep) path.value = dir;
|
||||
const roots = $('.roots', this.el); if (roots) roots.value = dir.slice(0, 2).toUpperCase() + '\\';
|
||||
this.draw();
|
||||
} catch (e) { toast(e.message, 'error'); }
|
||||
box.scrollTop = scroll;
|
||||
if (select) $('tr.sel', box)?.scrollIntoView({ block: 'nearest' });
|
||||
} catch (e) { if (!quiet) toast(e.message, 'error'); }
|
||||
}
|
||||
refresh(opts = {}) { return this.cwd ? this.go(this.cwd, { keep: true, ...opts }) : Promise.resolve(); }
|
||||
// Nach Änderungen beide Seiten aktualisieren (die andere zeigt evtl. denselben Ordner)
|
||||
refreshBoth(opts) { this.other?.refresh({ quiet: true }); return this.refresh(opts); }
|
||||
sorted() {
|
||||
const { k, dir } = this.sort;
|
||||
return [...this.files].filter((f) => f.name !== '.' && f.name !== '..').sort((a, b) => (b.isDir - a.isDir) || (k === 'name' ? a.name.localeCompare(b.name, undefined, { numeric: true }) : (a[k] - b[k])) * dir);
|
||||
@@ -2266,29 +2283,34 @@ class FilePane {
|
||||
async mkdir() {
|
||||
const n = await promptBox(T('New folder'), T('Name')); if (!n) return;
|
||||
const p = await this.join(this.cwd, n);
|
||||
try { this.side === 'local' ? await api.call('local:op', 'mkdir', p) : await api.call('sftp:op', this.sftp.id, 'mkdir', p); this.go(this.cwd); } catch (e) { toast(e.message, 'error'); }
|
||||
try { this.side === 'local' ? await api.call('local:op', 'mkdir', p) : await api.call('sftp:op', this.sftp.id, 'mkdir', p); this.refreshBoth({ select: [n] }); } catch (e) { toast(e.message, 'error'); }
|
||||
}
|
||||
async rename(f) {
|
||||
const n = await promptBox(T('Rename'), T('New name'), f.name); if (!n || n === f.name) return;
|
||||
const a = await this.join(this.cwd, f.name), b = await this.join(this.cwd, n);
|
||||
try { this.side === 'local' ? await api.call('local:op', 'rename', a, b) : await api.call('sftp:op', this.sftp.id, 'rename', a, b); this.go(this.cwd); } catch (e) { toast(e.message, 'error'); }
|
||||
try { this.side === 'local' ? await api.call('local:op', 'rename', a, b) : await api.call('sftp:op', this.sftp.id, 'rename', a, b); this.refreshBoth({ select: [n] }); } catch (e) { toast(e.message, 'error'); this.refresh(); }
|
||||
}
|
||||
async chmod(f) {
|
||||
const m = await promptBox(T('Change permissions'), T('Octal (e.g. 644)'), (f.mode & 0o777).toString(8)); if (!m) return;
|
||||
try { await api.call('sftp:op', this.sftp.id, 'chmod', await this.join(this.cwd, f.name), parseInt(m, 8)); this.go(this.cwd); } catch (e) { toast(e.message, 'error'); }
|
||||
try { await api.call('sftp:op', this.sftp.id, 'chmod', await this.join(this.cwd, f.name), parseInt(m, 8)); this.refresh(); } catch (e) { toast(e.message, 'error'); }
|
||||
}
|
||||
async remove() {
|
||||
const names = [...this.sel]; if (!names.length) return;
|
||||
if (!(await confirmBox(T('Delete?'), T(this.side === 'local' ? 'Move {n} item(s) to the trash: {list}' : 'Permanently delete {n} item(s) from the server: {list}', { n: names.length, list: names.slice(0, 5).join(', ') + (names.length > 5 ? ' …' : '') })))) return;
|
||||
// Sofort ausgrauen, damit man sieht, was gerade gelöscht wird
|
||||
$$('tr.sel', this.el).forEach((tr) => tr.classList.add('busy'));
|
||||
let ok = 0;
|
||||
for (const n of names) {
|
||||
const f = this.files.find((x) => x.name === n);
|
||||
const p = await this.join(this.cwd, n);
|
||||
try {
|
||||
if (this.side === 'local') await api.call('local:op', 'delete', p);
|
||||
else await api.call('sftp:op', this.sftp.id, f.isDir ? 'rmdir' : 'unlink', p);
|
||||
ok++;
|
||||
} catch (e) { toast(`${n}: ${e.message}`, 'error'); }
|
||||
}
|
||||
this.go(this.cwd);
|
||||
await this.refreshBoth();
|
||||
if (ok) toast(T('{n} item(s) deleted', { n: ok }), 'ok');
|
||||
}
|
||||
async transferSelected() {
|
||||
const names = [...this.sel];
|
||||
@@ -2306,8 +2328,8 @@ class FilePane {
|
||||
const src = await this.join(this.cwd, n), dst = await target.join(target.cwd, n);
|
||||
const dir = this.side === 'local' ? 'upload' : 'download';
|
||||
await this.sftp.transfer(dir, dir === 'upload' ? src : dst, dir === 'upload' ? dst : src, n);
|
||||
target.refresh({ select: names });
|
||||
}
|
||||
target.go(target.cwd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2323,6 +2345,12 @@ class SftpSession {
|
||||
wrap.append(h(`<div class="pane"><div class="pane-empty"><div class="spinner" style="width:30px;height:30px;border:3px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:spin .9s linear infinite"></div><div>${esc(T('Connecting to {host} …', { host: host.address }))}</div></div></div>`));
|
||||
this.unsub = api.on('sftp:progress', (tid, done, total) => this.progress(tid, done, total));
|
||||
this.xfers = new Map();
|
||||
// Automatisch aktualisieren: beim Zurückkehren ins Fenster und alle 10 s, solange der Tab sichtbar ist
|
||||
const visible = () => this.el.classList.contains('active') && !document.hidden;
|
||||
this.autoRefresh = () => { if (visible() && !this.xfers.size) { this.local?.refresh({ quiet: true }); this.remote.refresh({ quiet: true }); } };
|
||||
window.addEventListener('focus', this.autoRefresh);
|
||||
this.timer = setInterval(this.autoRefresh, 10000);
|
||||
this.onShow = () => this.autoRefresh();
|
||||
addTab(this);
|
||||
this.open();
|
||||
}
|
||||
@@ -2355,6 +2383,7 @@ class SftpSession {
|
||||
row.classList.add('fail'); $('.pct', row).textContent = T('Error'); row.title = e.message; toast(`${name}: ${e.message}`, 'error');
|
||||
setTimeout(() => row.remove(), 10000);
|
||||
}
|
||||
this.xfers.delete(tid);
|
||||
}
|
||||
// Web-Version: Upload per HTTP (mit Fortschritt), Download als Browser-Download
|
||||
webTransfer(dir, file, remotePath, name) {
|
||||
@@ -2376,9 +2405,9 @@ class SftpSession {
|
||||
x.onload = () => {
|
||||
if (x.status < 300) { row.classList.add('done'); $('.bar i', row).style.width = '100%'; $('.pct', row).textContent = T('done'); setTimeout(() => row.remove(), 5000); }
|
||||
else { row.classList.add('fail'); $('.pct', row).textContent = T('Error'); const m = (() => { try { return JSON.parse(x.responseText).error; } catch { return x.statusText; } })(); toast(`${name}: ${m}`, 'error'); setTimeout(() => row.remove(), 10000); }
|
||||
resolve();
|
||||
this.xfers.delete(tid); resolve();
|
||||
};
|
||||
x.onerror = () => { row.classList.add('fail'); $('.pct', row).textContent = T('Error'); resolve(); };
|
||||
x.onerror = () => { row.classList.add('fail'); $('.pct', row).textContent = T('Error'); this.xfers.delete(tid); resolve(); };
|
||||
x.send(file);
|
||||
});
|
||||
}
|
||||
@@ -2388,7 +2417,7 @@ class SftpSession {
|
||||
$('.bar i', row).style.width = p + '%';
|
||||
$('.pct', row).textContent = `${p}% · ${fmtSize(done)} / ${fmtSize(total)}`;
|
||||
}
|
||||
dispose() { this.unsub(); api.call('sftp:close', this.id).catch(() => {}); }
|
||||
dispose() { this.unsub(); clearInterval(this.timer); window.removeEventListener('focus', this.autoRefresh); api.call('sftp:close', this.id).catch(() => {}); }
|
||||
}
|
||||
function openSftp(host) { return new SftpSession(host); }
|
||||
|
||||
|
||||
@@ -253,6 +253,8 @@ body.in-session #sidebar { display: none; }
|
||||
.pane td.date { color: var(--muted); }
|
||||
.pane tr:hover td { background: rgb(var(--tint) / 0.024); }
|
||||
.pane tr.sel td { background: color-mix(in srgb, var(--accent) 15%, transparent); }
|
||||
.pane tr.busy { opacity: .45; pointer-events: none; }
|
||||
.pane .files:focus { outline: none; }
|
||||
.pane .ico-dir { color: var(--folder); }
|
||||
.pane .ico-file { color: var(--faint); }
|
||||
.pane-empty { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; color: var(--muted); }
|
||||
|
||||
Reference in new issue
Block a user