Remove fragile drag data access
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
PLUGIN="u-navigator"
|
PLUGIN="u-navigator"
|
||||||
VERSION="0.2.9"
|
VERSION="0.2.10"
|
||||||
PKG_DIR="packages"
|
PKG_DIR="packages"
|
||||||
WORK_DIR=".plugin-build"
|
WORK_DIR=".plugin-build"
|
||||||
PKG_NAME="${PLUGIN}-${VERSION}.tgz"
|
PKG_NAME="${PLUGIN}-${VERSION}.tgz"
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+25
-15
@@ -207,7 +207,7 @@ function renderExplorer(body, win) {
|
|||||||
dropZone.addEventListener('dragover', (event) => {
|
dropZone.addEventListener('dragover', (event) => {
|
||||||
if (hasDropPayload(event)) {
|
if (hasDropPayload(event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.dataTransfer.dropEffect = event.altKey ? 'copy' : 'move';
|
setDropEffect(event, event.altKey ? 'copy' : 'move');
|
||||||
data.dragOver = true;
|
data.dragOver = true;
|
||||||
dropZone.classList.add('drag-over');
|
dropZone.classList.add('drag-over');
|
||||||
}
|
}
|
||||||
@@ -242,12 +242,7 @@ function renderExplorer(body, win) {
|
|||||||
});
|
});
|
||||||
row.addEventListener('dragstart', (event) => {
|
row.addEventListener('dragstart', (event) => {
|
||||||
state.draggedEntry = { path: entry.path, name: entry.name, sourceWindowId: win.id };
|
state.draggedEntry = { path: entry.path, name: entry.name, sourceWindowId: win.id };
|
||||||
try {
|
setEffectAllowed(event);
|
||||||
event.dataTransfer.setData('text/plain', entry.path);
|
|
||||||
} catch {
|
|
||||||
// Some WebKit builds reject programmatic drag data. App state is the primary channel.
|
|
||||||
}
|
|
||||||
event.dataTransfer.effectAllowed = 'copyMove';
|
|
||||||
row.classList.add('dragging');
|
row.classList.add('dragging');
|
||||||
});
|
});
|
||||||
row.addEventListener('dragend', () => {
|
row.addEventListener('dragend', () => {
|
||||||
@@ -260,7 +255,7 @@ function renderExplorer(body, win) {
|
|||||||
if (entry.type === 'directory') {
|
if (entry.type === 'directory') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.dataTransfer.dropEffect = event.altKey ? 'copy' : 'move';
|
setDropEffect(event, event.altKey ? 'copy' : 'move');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
row.addEventListener('drop', async (event) => {
|
row.addEventListener('drop', async (event) => {
|
||||||
@@ -362,7 +357,7 @@ async function handleDrop(event, win, targetPath) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const internalPath = state.draggedEntry?.path || safeGetDragText(event);
|
const internalPath = state.draggedEntry?.path || '';
|
||||||
if (internalPath) {
|
if (internalPath) {
|
||||||
const name = internalPath.split('/').filter(Boolean).at(-1);
|
const name = internalPath.split('/').filter(Boolean).at(-1);
|
||||||
const destination = `${targetPath.replace(/\/$/, '')}/${name}`;
|
const destination = `${targetPath.replace(/\/$/, '')}/${name}`;
|
||||||
@@ -374,9 +369,10 @@ async function handleDrop(event, win, targetPath) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.dataTransfer.files.length) {
|
const files = getDroppedFiles(event);
|
||||||
|
if (files.length) {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
for (const file of event.dataTransfer.files) {
|
for (const file of files) {
|
||||||
form.append('files', file, file.name);
|
form.append('files', file, file.name);
|
||||||
}
|
}
|
||||||
await fetchChecked(apiUrl(`upload.php?path=${encodeURIComponent(targetPath)}`), {
|
await fetchChecked(apiUrl(`upload.php?path=${encodeURIComponent(targetPath)}`), {
|
||||||
@@ -405,7 +401,7 @@ async function reloadExplorerWindows(ids) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hasDropPayload(event) {
|
function hasDropPayload(event) {
|
||||||
return Boolean(state.draggedEntry || event.dataTransfer?.types?.includes('Files') || event.dataTransfer?.types?.includes('text/plain'));
|
return Boolean(state.draggedEntry || getDroppedFiles(event).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showError(error) {
|
function showError(error) {
|
||||||
@@ -413,11 +409,25 @@ function showError(error) {
|
|||||||
alert(message);
|
alert(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeGetDragText(event) {
|
function getDroppedFiles(event) {
|
||||||
try {
|
try {
|
||||||
return event.dataTransfer.getData('text/plain');
|
return [...(event.dataTransfer?.files || [])];
|
||||||
} catch {
|
} catch {
|
||||||
return '';
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setEffectAllowed(event) {
|
||||||
|
try {
|
||||||
|
event.dataTransfer.effectAllowed = 'copyMove';
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDropEffect(event, effect) {
|
||||||
|
try {
|
||||||
|
event.dataTransfer.dropEffect = effect;
|
||||||
|
} catch {
|
||||||
|
// Browser rejected the requested cursor hint; the app-state drop still works.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE PLUGIN [
|
<!DOCTYPE PLUGIN [
|
||||||
<!ENTITY name "u-navigator">
|
<!ENTITY name "u-navigator">
|
||||||
<!ENTITY author "michael">
|
<!ENTITY author "michael">
|
||||||
<!ENTITY version "0.2.9">
|
<!ENTITY version "0.2.10">
|
||||||
<!ENTITY package "&name;-&version;.tgz">
|
<!ENTITY package "&name;-&version;.tgz">
|
||||||
]>
|
]>
|
||||||
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
|
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<FILE Name="/boot/config/plugins/&name;/&package;">
|
<FILE Name="/boot/config/plugins/&name;/&package;">
|
||||||
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
|
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
|
||||||
<MD5>a8f39d867d56be04d8645f0975440b0a</MD5>
|
<MD5>cf0f9388fccc94487173e16cd9075cec</MD5>
|
||||||
</FILE>
|
</FILE>
|
||||||
|
|
||||||
<FILE Run="/bin/bash">
|
<FILE Run="/bin/bash">
|
||||||
|
|||||||
Reference in New Issue
Block a user