Merge pull request #389 from SiriusXT/open_in_file_manager_of_data

Open in file manager of Trilium's data directory
This commit is contained in:
Elian Doran 2024-09-10 21:04:56 +03:00 committed by GitHub
commit 7a11f9aaff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -166,6 +166,23 @@ function getHost() {
return `${url.protocol}//${url.hostname}:${url.port}`; 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 { export default {
download, download,
downloadFileNote, downloadFileNote,
@ -176,4 +193,5 @@ export default {
openAttachmentExternally, openAttachmentExternally,
openNoteCustom, openNoteCustom,
openAttachmentCustom, openAttachmentCustom,
openDirectory
} }

View File

@ -2,6 +2,8 @@ import server from "../../services/server.js";
import utils from "../../services/utils.js"; import utils from "../../services/utils.js";
import { t } from "../../services/i18n.js"; import { t } from "../../services/i18n.js";
import BasicWidget from "../basic_widget.js"; import BasicWidget from "../basic_widget.js";
import openService from "../../services/open.js";
const TPL = ` const TPL = `
<div class="about-dialog modal fade mx-auto" tabindex="-1" role="dialog"> <div class="about-dialog modal fade mx-auto" tabindex="-1" role="dialog">
@ -72,7 +74,18 @@ export default class AboutDialog extends BasicWidget {
this.$buildDate.text(appInfo.buildDate); this.$buildDate.text(appInfo.buildDate);
this.$buildRevision.text(appInfo.buildRevision); this.$buildRevision.text(appInfo.buildRevision);
this.$buildRevision.attr('href', `https://github.com/TriliumNext/Notes/commit/${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() { async openAboutDialogEvent() {