Use background jobs for file transfers

This commit is contained in:
Mikei386
2026-06-23 06:52:25 +02:00
parent 11b76f4572
commit 3fec83cf73
9 changed files with 201 additions and 47 deletions
+11 -15
View File
@@ -209,7 +209,7 @@ function renderExplorer(body, win) {
dropZone.addEventListener('dragover', (event) => {
if (hasDropPayload(event)) {
event.preventDefault();
setDropEffect(event, event.altKey ? 'copy' : 'move');
setDropEffect(event, 'copy');
data.dragOver = true;
dropZone.classList.add('drag-over');
}
@@ -235,6 +235,9 @@ function renderExplorer(body, win) {
for (const row of body.querySelectorAll('.file-row')) {
const entry = data.entries.find((item) => item.path === row.dataset.path);
row.draggable = false;
row.addEventListener('dragstart', (event) => event.preventDefault());
row.addEventListener('selectstart', (event) => event.preventDefault());
row.addEventListener('pointerdown', (event) => {
lockExplorerScroll(win, body);
startItemPointerDrag(event, win, entry);
@@ -334,18 +337,6 @@ async function handleDrop(event, win, targetPath) {
return;
}
const internalPath = state.draggedEntry?.path || '';
if (internalPath) {
const name = internalPath.split('/').filter(Boolean).at(-1);
const destination = `${targetPath.replace(/\/$/, '')}/${name}`;
if (internalPath === destination) {
throw new Error('Quelle und Ziel sind identisch.');
}
await createJob(event.altKey ? 'copy' : 'move', internalPath, destination);
await reloadExplorerWindows([win.id, state.draggedEntry?.sourceWindowId].filter(Boolean));
return;
}
const files = getDroppedFiles(event);
if (files.length) {
const form = new FormData();
@@ -378,7 +369,8 @@ async function reloadExplorerWindows(ids) {
}
function hasDropPayload(event) {
return Boolean(state.draggedEntry || getDroppedFiles(event).length);
const types = [...(event.dataTransfer?.types || [])];
return types.includes('Files') || getDroppedFiles(event).length > 0;
}
function showError(error) {
@@ -546,7 +538,7 @@ function updatePropertiesWindows() {
}
function startItemPointerDrag(event, win, entry) {
if (event.button !== 0) return;
if (event.button !== 0 || !entry) return;
state.pointerDrag = {
sourceWindowId: win.id,
@@ -563,6 +555,9 @@ function startItemPointerDrag(event, win, entry) {
const up = (upEvent) => finishItemPointerDrag(upEvent, move, up);
document.addEventListener('pointermove', move);
document.addEventListener('pointerup', up, { once: true });
try {
event.currentTarget.setPointerCapture(event.pointerId);
} catch {}
}
function updateItemPointerDrag(event) {
@@ -597,6 +592,7 @@ async function finishItemPointerDrag(event, move, up) {
return;
}
event.preventDefault();
state.suppressClickPath = drag.path;
const target = findPointerDropTarget(event);
if (!target) {