Skip to content

Commit 170da7e

Browse files
authored
feat: new option to open file in external app from file browser (#1163)
* feat: new option to open file in external app * fix: formatting
1 parent 40d9832 commit 170da7e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/pages/fileBrowser/fileBrowser.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import projects from "lib/projects";
2020
import recents from "lib/recents";
2121
import remoteStorage from "lib/remoteStorage";
2222
import appSettings from "lib/settings";
23+
import mimeTypes from "mime-types";
2324
import mustache from "mustache";
2425
import filesSettings from "settings/filesSettings";
2526
import URLParse from "url-parse";
@@ -766,6 +767,7 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
766767

767768
if (helpers.isFile(type)) {
768769
options.push(["info", strings.info, "info"]);
770+
options.push(["open_with", strings["open with"], "open_in_browser"]);
769771
}
770772

771773
if (currentDir.url !== "/" && url) {
@@ -819,6 +821,27 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
819821
navigator.clipboard.writeText(url);
820822
alert(strings.success, strings["copied to clipboard"]);
821823
break;
824+
825+
case "open_with":
826+
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+
);
840+
} catch (error) {
841+
console.error(error);
842+
toast(strings.error);
843+
}
844+
break;
822845
}
823846
}
824847

0 commit comments

Comments
 (0)