Skip to content

Commit

Permalink
Merge pull request #389 from SiriusXT/open_in_file_manager_of_data
Browse files Browse the repository at this point in the history
Open in file manager of Trilium's data directory
  • Loading branch information
eliandoran authored Sep 10, 2024
2 parents d7ab990 + 3ad2d1a commit 7a11f9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/public/app/services/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ function getHost() {
return `${url.protocol}//${url.hostname}:${url.port}`;
}

async function openDirectory(directory) {
try {
if (utils.isElectron()) {
const electron = utils.dynamicRequire('electron');
const res = await electron.shell.openPath(directory);
if (res) {
console.error('Failed to open directory:', res);
}
} else {
console.error('Not running in an Electron environment.');
}
} catch (err) {
// Handle file system errors (e.g. path does not exist or is inaccessible)
console.error('Error:', err.message);
}
}

export default {
download,
downloadFileNote,
Expand All @@ -176,4 +193,5 @@ export default {
openAttachmentExternally,
openNoteCustom,
openAttachmentCustom,
openDirectory
}
15 changes: 14 additions & 1 deletion src/public/app/widgets/dialogs/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import server from "../../services/server.js";
import utils from "../../services/utils.js";
import { t } from "../../services/i18n.js";
import BasicWidget from "../basic_widget.js";
import openService from "../../services/open.js";


const TPL = `
<div class="about-dialog modal fade mx-auto" tabindex="-1" role="dialog">
Expand Down Expand Up @@ -72,7 +74,18 @@ export default class AboutDialog extends BasicWidget {
this.$buildDate.text(appInfo.buildDate);
this.$buildRevision.text(appInfo.buildRevision);
this.$buildRevision.attr('href', `https://github.com/TriliumNext/Notes/commit/${appInfo.buildRevision}`);
this.$dataDirectory.text(appInfo.dataDirectory);
if (utils.isElectron()) {
this.$dataDirectory.html($('<a></a>', {
href: '#',
text: appInfo.dataDirectory,
}));
this.$dataDirectory.find("a").on('click', (event) => {
event.preventDefault();
openService.openDirectory(appInfo.dataDirectory);
})
} else {
this.$dataDirectory.text(appInfo.dataDirectory);
}
}

async openAboutDialogEvent() {
Expand Down

0 comments on commit 7a11f9a

Please sign in to comment.