Skip to content

Commit e269ba1

Browse files
authored
fix: support for Acode terminal SAF URIs (#1621)
1 parent 3458718 commit e269ba1

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

src/lib/openFolder.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ import openFile from "./openFile";
1919
import recents from "./recents";
2020
import appSettings from "./settings";
2121

22+
const isTermuxSafUri = (value = "") =>
23+
value.startsWith("content://com.termux.documents/tree/");
24+
const isAcodeTerminalPublicSafUri = (value = "") =>
25+
value.startsWith("content://com.foxdebug.acode.documents/tree/");
26+
const isTerminalSafUri = (value = "") =>
27+
isTermuxSafUri(value) || isAcodeTerminalPublicSafUri(value);
28+
2229
/**
2330
* @typedef {import('../components/collapsableList').Collapsible} Collapsible
2431
*/
@@ -401,7 +408,7 @@ function execOperation(type, action, url, $target, name) {
401408
editorManager.onupdate("delete-file");
402409
editorManager.emit("update", "delete-file");
403410
} else {
404-
if (url.startsWith("content://com.termux.documents/tree/")) {
411+
if (isTerminalSafUri(url)) {
405412
const fs = fsOperation(url);
406413
const entries = await fs.lsDir();
407414
if (entries.length === 0) {
@@ -436,10 +443,7 @@ function execOperation(type, action, url, $target, name) {
436443
}
437444

438445
async function renameFile() {
439-
if (
440-
url.startsWith("content://com.termux.documents/tree/") &&
441-
!helpers.isFile(type)
442-
) {
446+
if (isTermuxSafUri(url) && !helpers.isFile(type)) {
443447
alert(strings.warning, strings["rename not supported"]);
444448
return;
445449
}
@@ -455,11 +459,8 @@ function execOperation(type, action, url, $target, name) {
455459
const fs = fsOperation(url);
456460
let newUrl;
457461

458-
if (
459-
url.startsWith("content://com.termux.documents/tree/") &&
460-
helpers.isFile(type)
461-
) {
462-
// Special handling for Termux content files
462+
if (isTermuxSafUri(url) && helpers.isFile(type)) {
463+
// Special handling for Termux SAF content files
463464
const newFilePath = Url.join(Url.dirname(url), newName);
464465
const content = await fs.readFile();
465466
await fsOperation(Url.dirname(url)).createFile(newName, content);
@@ -581,11 +582,8 @@ function execOperation(type, action, url, $target, name) {
581582
}
582583
let newUrl;
583584
if (clipBoard.action === "cut") {
584-
// Special handling for Termux SAF folders - move manually due to SAF limitations
585-
if (
586-
clipBoard.url.startsWith("content://com.termux.documents/tree/") &&
587-
IS_DIR
588-
) {
585+
// Special handling for SAF folders backed by terminal providers - move manually due to SAF limitations
586+
if (isTerminalSafUri(clipBoard.url) && IS_DIR) {
589587
const moveRecursively = async (sourceUrl, targetParentUrl) => {
590588
const sourceFs = fsOperation(sourceUrl);
591589
const sourceName = Url.basename(sourceUrl);

src/utils/helpers.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,22 @@ export default {
387387
// Determine if it's a special case URI
388388
const isSpecialCase = currentUri.includes("::");
389389
let baseFolder;
390-
391-
if (currentUri.includes("com.android.externalstorage.documents")) {
390+
const isExternalStorageUri = currentUri.includes(
391+
"com.android.externalstorage.documents",
392+
);
393+
const isTermuxUri = currentUri.includes("com.termux.documents");
394+
const isAcodeTerminalPublicSafUri = currentUri.includes(
395+
"com.foxdebug.acode.documents",
396+
);
397+
const [, treeSegment = ""] = currentUri.split("/tree/");
398+
const terminalBasePath = isAcodeTerminalPublicSafUri
399+
? decodeURIComponent(treeSegment.split("::")[0] || "")
400+
: "";
401+
402+
if (isExternalStorageUri) {
392403
baseFolder = decodeURIComponent(currentUri.split("%3A")[1].split("/")[0]);
393404
} else if (
394-
!(
395-
currentUri.includes("com.android.externalstorage.documents") ||
396-
currentUri.includes("com.termux.documents")
397-
)
405+
!(isExternalStorageUri || isTermuxUri || isAcodeTerminalPublicSafUri)
398406
) {
399407
// Handle nested paths for regular file:// URIs
400408
const pathParts = pathString.split("/").filter(Boolean);
@@ -443,18 +451,27 @@ export default {
443451
let fullUri = currentUri;
444452

445453
// Adjust URI for special cases
446-
if (currentUri.includes("com.android.externalstorage.documents")) {
454+
if (isExternalStorageUri) {
447455
if (!isSpecialCase && i === 0) {
448456
fullUri += `::primary:${baseFolder}/${name}`;
449457
} else {
450458
fullUri += `/${name}`;
451459
}
452-
} else if (currentUri.includes("com.termux.documents")) {
460+
} else if (isTermuxUri) {
453461
if (!isSpecialCase && i === 0) {
454462
fullUri += `::/data/data/com.termux/files/home/${name}`;
455463
} else {
456464
fullUri += `/${name}`;
457465
}
466+
} else if (isAcodeTerminalPublicSafUri) {
467+
if (!isSpecialCase && i === 0) {
468+
const sanitizedBase = terminalBasePath.endsWith("/")
469+
? `${terminalBasePath}${name}`
470+
: `${terminalBasePath}/${name}`;
471+
fullUri += `::${sanitizedBase}`;
472+
} else {
473+
fullUri += `/${name}`;
474+
}
458475
}
459476

460477
if (isLastElement && isFile) {

0 commit comments

Comments
 (0)