fix: ended page scopes start no timers; SSH transfers keep their connection from the idle sweep; linked files download whole; only the sent item unpacks on an SSH host, replace and skip as on a machine
This commit is contained in:
1 parent
e05ff05015
commit
64ce8f2b72
7 files changed
+175
-52
No files matched your search
@@ -780,6 +780,7 @@ p.mv-a { margin:0; font-size:13px; }
|
||||
.fpane.narrow .fm-bar { gap:5px; }
|
||||
.fpane.narrow .fm-bar .btn.ico { padding-left:8px; padding-right:8px; gap:4px; font-size:12.5px; }
|
||||
.fpane.narrow .fp-sel { gap:4px; }
|
||||
.fpane.narrow .fp-selinfo { margin-right:6px; }
|
||||
.fpane.narrow .fp-sel .btn.sq { width:32px; height:32px; }
|
||||
/* The pane: its bar and list scroll inside it. */
|
||||
.fpane-body { flex:1; min-height:0; overflow:auto; padding:10px 12px 12px; }
|
||||
|
||||
@@ -15,24 +15,7 @@
|
||||
|
||||
function register(name, mod) { modules[name] = mod; }
|
||||
|
||||
// scope gives a module timers, requests and listeners that end with it.
|
||||
function scope() {
|
||||
const timers = new Set(), offs = [], ac = new AbortController();
|
||||
return {
|
||||
timeout(fn, ms) { const id = setTimeout(() => { timers.delete(id); fn(); }, ms); timers.add(id); return id; },
|
||||
interval(fn, ms) { const id = setInterval(fn, ms); timers.add(id); return id; },
|
||||
clear(id) { clearTimeout(id); clearInterval(id); timers.delete(id); },
|
||||
fetch(url, opt) {
|
||||
const o = Object.assign({credentials: 'same-origin'}, opt || {});
|
||||
// A request with its own signal ends on either.
|
||||
o.signal = o.signal && AbortSignal.any ? AbortSignal.any([o.signal, ac.signal]) : (o.signal || ac.signal);
|
||||
return fetch(url, o);
|
||||
},
|
||||
on(target, ev, fn, opt) { target.addEventListener(ev, fn, opt); offs.push(() => target.removeEventListener(ev, fn, opt)); },
|
||||
signal: ac.signal,
|
||||
end() { timers.forEach(id => { clearTimeout(id); clearInterval(id); }); timers.clear(); offs.forEach(f => f()); ac.abort(); }
|
||||
};
|
||||
}
|
||||
const scope = WSUtil.scope;
|
||||
|
||||
function unmount(area) {
|
||||
const m = mounted.get(area);
|
||||
|
||||
@@ -22,6 +22,28 @@
|
||||
if (n < 1073741824) return (n / 1048576).toFixed(1) + ' M';
|
||||
return (n / 1073741824).toFixed(1) + ' G';
|
||||
}
|
||||
const api = {shellQuote, shellQuoteAll, dropAction, fmtSize};
|
||||
// scope gives a module timers, requests and listeners that end with it;
|
||||
// once ended it starts nothing new (a request's late answer cannot set a
|
||||
// timer going again).
|
||||
function scope() {
|
||||
let ended = false;
|
||||
const timers = new Set(), offs = [], ac = new AbortController();
|
||||
return {
|
||||
timeout(fn, ms) { if (ended) return 0; const id = setTimeout(() => { timers.delete(id); fn(); }, ms); timers.add(id); return id; },
|
||||
interval(fn, ms) { if (ended) return 0; const id = setInterval(fn, ms); timers.add(id); return id; },
|
||||
clear(id) { clearTimeout(id); clearInterval(id); timers.delete(id); },
|
||||
fetch(url, opt) {
|
||||
const o = Object.assign({credentials: 'same-origin'}, opt || {});
|
||||
// A request with its own signal ends on either.
|
||||
o.signal = o.signal && AbortSignal.any ? AbortSignal.any([o.signal, ac.signal]) : (o.signal || ac.signal);
|
||||
return fetch(url, o);
|
||||
},
|
||||
on(target, ev, fn, opt) { target.addEventListener(ev, fn, opt); offs.push(() => target.removeEventListener(ev, fn, opt)); },
|
||||
signal: ac.signal,
|
||||
end() { ended = true; timers.forEach(id => { clearTimeout(id); clearInterval(id); }); timers.clear(); offs.forEach(f => f()); ac.abort(); }
|
||||
};
|
||||
}
|
||||
|
||||
const api = {shellQuote, shellQuoteAll, dropAction, fmtSize, scope};
|
||||
if (typeof module !== 'undefined') module.exports = api; else root.WSUtil = api;
|
||||
})(this);
|
||||
@@ -39,3 +39,13 @@ test('dropAction: other SSH user on the same host is another place', () => {
|
||||
const b = {kind: 'ssh', id: 'm1|bob@h:22', label: 'bob@h'};
|
||||
assert.strictEqual(U.dropAction({source: a, paths: ['/x'], dir: '/'}, {kind: 'term', source: b}).kind, 'deny');
|
||||
});
|
||||
|
||||
test('scope: nothing new runs after it ended', async () => {
|
||||
const s = U.scope();
|
||||
let n = 0;
|
||||
s.end();
|
||||
s.timeout(() => n++, 1);
|
||||
s.interval(() => n++, 1);
|
||||
await new Promise(r => setTimeout(r, 20));
|
||||
assert.strictEqual(n, 0);
|
||||
});
|
||||
Reference in new issue
Block a user