Skip to content

Commit 7cdd264

Browse files
committed
fix: open with of file browser
1 parent 4380aad commit 7cdd264

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/pages/fileBrowser/fileBrowser.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,20 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
748748
});
749749
}
750750

751+
async function getShareableUri(fileUrl) {
752+
if (!fileUrl) return null;
753+
try {
754+
const fs = fsOperation(fileUrl);
755+
if (/^s?ftp:/.test(fileUrl)) {
756+
return fs.localName;
757+
}
758+
const stat = await fs.stat();
759+
return stat?.url || null;
760+
} catch (error) {
761+
return null;
762+
}
763+
}
764+
751765
async function contextMenuHandler() {
752766
if (appSettings.value.vibrateOnTap) {
753767
navigator.vibrate(constants.VIBRATION_TIME);
@@ -824,19 +838,20 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
824838

825839
case "open_with":
826840
try {
827-
let mimeType = mimeTypes.lookup(name || "text/plain");
828-
const fs = fsOperation(url);
829-
if (/^s?ftp:/.test(url)) return fs.localName;
830-
831-
system.fileAction(
832-
(await fs.stat()).url,
833-
name,
834-
"VIEW",
835-
mimeType,
836-
() => {
837-
toast(strings["no app found to handle this file"]);
838-
},
839-
);
841+
const shareableUri = await getShareableUri(url);
842+
if (!shareableUri) {
843+
toast(strings["no app found to handle this file"]);
844+
break;
845+
}
846+
847+
const mimeType =
848+
mimeTypes.lookup(name) ||
849+
mimeTypes.lookup(shareableUri) ||
850+
"text/plain";
851+
852+
system.fileAction(shareableUri, name, "VIEW", mimeType, () => {
853+
toast(strings["no app found to handle this file"]);
854+
});
840855
} catch (error) {
841856
console.error(error);
842857
toast(strings.error);

0 commit comments

Comments
 (0)